Skip to content

Commit

Permalink
Merge pull request #5606 from akatsoulas/bug-1846733-add-tags
Browse files Browse the repository at this point in the history
Check if user has permissions to add tags
  • Loading branch information
akatsoulas authored Dec 7, 2023
2 parents 684a54a + 8e660e2 commit 20b34e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion kitsune/questions/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ def has_object_permission(self, request, view, obj):
return super().has_object_permission(request, view, obj)


class HasAddTagPermissions(permissions.BasePermission):
def has_object_permission(self, request, view, obj):
"""Simple permision check to match the one from the question view."""

if not request.user.has_perm("questions.tag_question"):
return False
return super().has_object_permission(request, view, obj)


class QuestionViewSet(viewsets.ModelViewSet):
serializer_class = QuestionSerializer
queryset = Question.objects.all()
Expand Down Expand Up @@ -359,7 +368,11 @@ def take(self, request, pk=None):

return Response(status=status.HTTP_204_NO_CONTENT)

@action(detail=True, methods=["post"], permission_classes=[permissions.IsAuthenticated])
@action(
detail=True,
methods=["post"],
permission_classes=[permissions.IsAuthenticated, HasAddTagPermissions],
)
def add_tags(self, request, pk=None):
question = self.get_object()

Expand Down
1 change: 1 addition & 0 deletions kitsune/questions/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ def test_add_tags(self):

u = UserFactory()
add_permission(u, Tag, "add_tag")
add_permission(u, Question, "tag_question")
self.client.force_authenticate(user=u)

res = self.client.post(
Expand Down

0 comments on commit 20b34e6

Please sign in to comment.