Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick fix - everyone can see all product types to bypass bug #107

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 4 additions & 27 deletions dojo/product_type/queries.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,15 @@
from crum import get_current_user
from django.db.models import Exists, OuterRef, Q
from dojo.models import Product_Type, Product_Type_Member, Product_Type_Group
from dojo.authorization.authorization import get_roles_for_permission, user_has_global_permission, user_has_permission, \
from dojo.authorization.authorization import user_has_global_permission, user_has_permission, \
role_has_permission
from dojo.group.queries import get_authorized_groups
from dojo.authorization.roles_permissions import Permissions


def get_authorized_product_types(permission):
user = get_current_user()

if user is None:
return Product_Type.objects.none()

if user.is_superuser:
return Product_Type.objects.all().order_by('name')

if user_has_global_permission(user, permission):
return Product_Type.objects.all().order_by('name')

roles = get_roles_for_permission(permission)
authorized_roles = Product_Type_Member.objects.filter(product_type=OuterRef('pk'),
user=user,
role__in=roles)
authorized_groups = Product_Type_Group.objects.filter(
product_type=OuterRef('pk'),
group__users=user,
role__in=roles)
product_types = Product_Type.objects.annotate(
member=Exists(authorized_roles),
authorized_group=Exists(authorized_groups)).order_by('name')
product_types = product_types.filter(Q(member=True) | Q(authorized_group=True))

return product_types
# TODO: in order to quickly resolve a bug in the product types filter
# everyone can see all product types
return Product_Type.objects.all().order_by('name')


def get_authorized_members_for_product_type(product_type, permission):
Expand Down
Loading