diff --git a/app/content/models/user.py b/app/content/models/user.py index 26e3a4b9a..66974c563 100644 --- a/app/content/models/user.py +++ b/app/content/models/user.py @@ -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() diff --git a/app/content/serializers/user.py b/app/content/serializers/user.py index 44a207122..fc2d91625 100644 --- a/app/content/serializers/user.py +++ b/app/content/serializers/user.py @@ -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 diff --git a/app/forms/models/forms.py b/app/forms/models/forms.py index 870d55b54..dc1411826 100644 --- a/app/forms/models/forms.py +++ b/app/forms/models/forms.py @@ -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): diff --git a/app/tests/kontres/test_reservation_integration.py b/app/tests/kontres/test_reservation_integration.py index d78dc9770..81ffaae6b 100644 --- a/app/tests/kontres/test_reservation_integration.py +++ b/app/tests/kontres/test_reservation_integration.py @@ -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(