diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4742c40e9c188be38460d8ac43d3220a03467302..942050b39cfc079da57a127843b16ff99af41a5d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,11 @@ and this project adheres to `Semantic Versioning`_. Unreleased ---------- +Fixed +~~~~~ + +* Creating new seating plans was still forbidden for some users. + `1.0.1`_ - 2022-09-01 --------------------- diff --git a/aleksis/apps/stoelindeling/rules.py b/aleksis/apps/stoelindeling/rules.py index 38dab4ce629d904183f145ea35151fd780e2ebe6..61e9a82322894a631e15d08482f6395ca8ff85a6 100644 --- a/aleksis/apps/stoelindeling/rules.py +++ b/aleksis/apps/stoelindeling/rules.py @@ -5,11 +5,15 @@ from aleksis.core.util.predicates import ( has_global_perm, has_object_perm, has_person, - is_group_owner, ) from .models import SeatingPlan -from .util.perms import is_plan_child_group_owner, is_plan_group_owner +from .util.perms import ( + is_group_owner, + is_group_owner_of_any_group, + is_plan_child_group_owner, + is_plan_group_owner, +) # View seating plan list view_seatingplans_predicate = has_person & ( @@ -36,13 +40,13 @@ add_perm("stoelindeling.view_seatingplan_for_group_rule", view_seatingplan_for_g # Add seating plan create_seatingplan_predicate = has_person & ( - has_global_perm("stoelindeling.add_seatingplan") | is_group_owner | is_plan_group_owner + has_global_perm("stoelindeling.add_seatingplan") | is_group_owner_of_any_group ) add_perm("stoelindeling.create_seatingplan_rule", create_seatingplan_predicate) # Copy seating plan -copy_seatingplan_for_group_predicate = ( - view_seatingplan_for_group_predicate & create_seatingplan_predicate +copy_seatingplan_for_group_predicate = view_seatingplan_for_group_predicate & ( + create_seatingplan_predicate | is_plan_group_owner ) add_perm("stoelindeling.copy_seatingplan_for_group_rule", copy_seatingplan_for_group_predicate) diff --git a/aleksis/apps/stoelindeling/util/perms.py b/aleksis/apps/stoelindeling/util/perms.py index 2b00e287cf3fa95e4410a163604736b732fcb6bb..6c336b963f4b87e8ebeaae449980bb8d49a4199c 100644 --- a/aleksis/apps/stoelindeling/util/perms.py +++ b/aleksis/apps/stoelindeling/util/perms.py @@ -8,6 +8,12 @@ from aleksis.core.models import Group, Person from ..models import SeatingPlan +@predicate +def is_group_owner_of_any_group(user) -> bool: + """Predicate which checks if the user is a owner of any group.""" + return user.person.owner_of.all().exists() + + @predicate def is_group_owner(user, group: Group) -> bool: """Predicate which checks if the user is a owner of the group."""