Skip to content

Commit

Permalink
quick patch to fix snex2 permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
jchate6 committed Jul 31, 2024
1 parent d95f77f commit 4a33c0f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tom_common/templatetags/tom_common_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def recent_comments(context, limit=10):
Comments will only be displayed for targets which the logged-in user has permission to view.
"""
user = context['request'].user
targets_for_user = get_objects_for_user(user, f'{Target._meta.app_label}.view_target')
targets_for_user = get_objects_for_user(user, 'tom_targets.view_target')

# In django-contrib-comments, the Comment model has a field ``object_pk`` which refers to the primary key
# of the object it is related to, i.e., a comment on a ``Target`` has an ``object_pk`` corresponding with the
Expand Down
4 changes: 2 additions & 2 deletions tom_targets/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class TargetViewSet(ModelViewSet, PermissionListMixin):

def get_queryset(self):
permission_required = permissions_map.get(self.request.method)
return get_objects_for_user(self.request.user, f'{Target._meta.app_label}.{permission_required}')
return get_objects_for_user(self.request.user, f'tom_targets.{permission_required}')

def create(self, request, *args, **kwargs):
response = super().create(request, *args, **kwargs)
Expand Down Expand Up @@ -93,7 +93,7 @@ class TargetNameViewSet(DestroyModelMixin, PermissionListMixin, RetrieveModelMix
def get_queryset(self):
permission_required = permissions_map.get(self.request.method)
return TargetName.objects.filter(
target__in=get_objects_for_user(self.request.user, f'{Target._meta.app_label}.{permission_required}')
target__in=get_objects_for_user(self.request.user, f'tom_targets.{permission_required}')
)


Expand Down
4 changes: 2 additions & 2 deletions tom_targets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TargetListView(PermissionListMixin, FilterView):
model = Target
filterset_class = TargetFilter
# Set app_name for Django-Guardian Permissions in case of Custom Target Model
permission_required = f'{Target._meta.app_label}.view_target'
permission_required = 'tom_targets.view_target'
ordering = ['-created']

def get_context_data(self, *args, **kwargs):
Expand Down Expand Up @@ -92,7 +92,7 @@ def get(self, request, *args, **kwargs):
# Tests fail without distinct but it works in practice, it is unclear as to why
# The Django query planner shows different results between in practice and unit tests
# django-guardian related querying is present in the test planner, but not in practice
targets = get_objects_for_user(request.user, f'{Target._meta.app_label}.view_target').filter(
targets = get_objects_for_user(request.user, 'tom_targets.view_target').filter(
Q(name__icontains=target_name) | Q(aliases__name__icontains=target_name)
).distinct()
if targets.count() == 1:
Expand Down

0 comments on commit 4a33c0f

Please sign in to comment.