Skip to content

Commit

Permalink
fixed permission for committee leaders for group forms
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNyl committed Aug 18, 2024
1 parent 1a7dff4 commit f086ac2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
6 changes: 6 additions & 0 deletions app/content/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ def is_leader_of(self, group):
group=group, membership_type=MembershipType.LEADER
).exists()

@property
def is_leader_of_committee(self):
return self.memberships.filter(
group__type=GroupType.COMMITTEE, membership_type=MembershipType.LEADER
).exists()

def has_unanswered_evaluations(self):
return self.get_unanswered_evaluations().exists()

Expand Down
3 changes: 1 addition & 2 deletions app/content/serializers/user.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.contrib.auth.hashers import make_password
from rest_framework import serializers
from rest_framework.exceptions import ValidationError

from django.contrib.auth.hashers import make_password

from dry_rest_permissions.generics import DRYGlobalPermissionsField

from app.common.enums import Groups, GroupType
Expand Down
6 changes: 4 additions & 2 deletions app/forms/models/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,10 @@ def has_write_permission(cls, request):
form = GroupForm.objects.filter(id=form_id).first()
group = form.group if form else None
return (
group and group.has_object_group_form_permission(request)
) or check_has_access(cls.write_access, request)
(group and group.has_object_group_form_permission(request))
or check_has_access(cls.write_access, request)
or request.user.is_leader_of_committee
)

@classmethod
def has_list_permission(cls, request):
Expand Down
1 change: 0 additions & 1 deletion app/tests/kontres/test_reservation_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def test_reservation_creation_fails_without_sober_watch(member, bookable_item):
)

assert response.status_code == 400
print(response.data)
expected_error_message = "Du må velge en edruvakt for reservasjonen."
actual_error_messages = response.data.get("non_field_errors", [])
assert any(
Expand Down

0 comments on commit f086ac2

Please sign in to comment.