Skip to content

Commit 63094f3

Browse files
apps/augmentedreality: add allow guest write permission on comments
1 parent 42ce409 commit 63094f3

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

apps/augmentedreality/api.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
from drf_spectacular.utils import extend_schema
22
from guest_user.mixins import AllowGuestUserMixin
3+
from guest_user.models import is_guest_user
34

5+
from adhocracy4.api.permissions import ViewSetRulesPermission
46
from adhocracy4.comments_async.api import CommentViewSet
57
from adhocracy4.ratings.api import RatingViewSet
68

79

10+
# TODO: Move this permission to A4, if this is becoming permanent
11+
class AllowGuestCommentPermission(ViewSetRulesPermission):
12+
def has_permission(self, request, view):
13+
# Allow guest users for POST (create) requests
14+
if request.method == "POST" and is_guest_user(request.user):
15+
return True
16+
17+
# For all other cases, use the normal permission logic
18+
return super().has_permission(request, view)
19+
20+
821
class CombinedRatingViewSet(AllowGuestUserMixin, RatingViewSet):
922
http_method_names = ["post", "patch"]
1023

@@ -26,6 +39,8 @@ def create(self, request, *args, **kwargs):
2639

2740

2841
class CombinedCommentViewSet(AllowGuestUserMixin, CommentViewSet):
42+
permission_classes = [AllowGuestCommentPermission]
43+
2944
def get_queryset(self):
3045
comments = super().get_queryset()
3146
return comments

0 commit comments

Comments
 (0)