Skip to content

Commit

Permalink
fix(permission): Check is_school_admin not has_group_by_id
Browse files Browse the repository at this point in the history
  • Loading branch information
DoyunShin committed Jan 16, 2024
1 parent be94d66 commit 529c709
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
4 changes: 1 addition & 3 deletions apps/core/models/signals/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def update_communication_article_status(comment):
)
if (
article.parent_board.is_school_communication
and comment.created_by.profile.has_group_by_id(
7
) # 7 = Communication board admin
and comment.created_by.profile.is_school_admin
and article.communication_article.school_response_status
!= SchoolResponseStatus.ANSWER_DONE
):
Expand Down
4 changes: 1 addition & 3 deletions apps/core/permissions/communication_article.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ class CommunicationArticleAdminPermission(permissions.IsAuthenticated):
message = "You are not authorized to access this feature"

def has_permission(self, request, view):
return request.user.is_staff or request.user.profile.has_group_by_id(
7
) # 7 = Communication board admin
return request.user.is_staff or request.user.profile.is_school_admin
6 changes: 2 additions & 4 deletions apps/core/views/viewsets/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,10 @@ def perform_create(self, serializer):
)
parent_article = parent_comment.parent_article

print(parent_article)
# print(parent_article)

created_by = self.request.user
is_school_admin = UserProfile.objects.get(user_id=created_by).has_group_by_id(
7
) # 7 = Communication board admin
is_school_admin = UserProfile.objects.get(user_id=created_by).is_school_admin

if is_school_admin and parent_article.name_type != NameType.ANONYMOUS:
name_type = NameType.REGULAR
Expand Down

0 comments on commit 529c709

Please sign in to comment.