From e2a9ac59a4ac11a93e4ae47c86edff51763d3470 Mon Sep 17 00:00:00 2001
From: Jonathan Weth <git@jonathanweth.de>
Date: Tue, 14 Jun 2022 21:45:22 +0200
Subject: [PATCH] Adjust permissions for instructions

---
 aleksis/apps/alsijil/models.py          | 3 ++-
 aleksis/apps/alsijil/util/predicates.py | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/aleksis/apps/alsijil/models.py b/aleksis/apps/alsijil/models.py
index ee3b88386..f5ac86590 100644
--- a/aleksis/apps/alsijil/models.py
+++ b/aleksis/apps/alsijil/models.py
@@ -531,7 +531,8 @@ class Instruction(SchoolTermRelatedExtensibleModel):
         null=True,
         verbose_name=_("Groups"),
         help_text=_(
-            "The instruction will be shown for the members and owners of the selected groups."
+            "The instruction will be shown for the members and owners of the selected groups. "
+            "Leave empty to show for all groups."
         ),
         related_name="instructions",
     )
diff --git a/aleksis/apps/alsijil/util/predicates.py b/aleksis/apps/alsijil/util/predicates.py
index 377779d30..8ba629852 100644
--- a/aleksis/apps/alsijil/util/predicates.py
+++ b/aleksis/apps/alsijil/util/predicates.py
@@ -288,13 +288,15 @@ def is_owner_of_any_group(user: User, obj):
 def has_any_instruction(user: User, obj):
     """Predicate which checks if the user has any instruction."""
     return Instruction.objects.filter(
-        Q(groups__members=user.person) | Q(groups__owners=user.person)
+        Q(groups__members=user.person) | Q(groups__owners=user.person) | Q(groups__isnull=False)
     ).exists()
 
 
 @predicate
 def is_instruction_for_person(user: User, obj: Instruction):
     """Predicate which checks if the instruction is for the person."""
+    if not obj.groups.all():
+        return True
     return (
         user
         in Person.objects.filter(
-- 
GitLab