From 8fae6d26c3ef432c92c9d33d1fc08d1704523cc5 Mon Sep 17 00:00:00 2001
From: Hangzhi Yu <hangzhi@protonmail.com>
Date: Sat, 16 Apr 2022 20:17:21 +0200
Subject: [PATCH] Update group and student overviews to show all objects a
 person has privileges on

---
 aleksis/apps/alsijil/model_extensions.py | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/aleksis/apps/alsijil/model_extensions.py b/aleksis/apps/alsijil/model_extensions.py
index c5502d54e..a2c9b8dc7 100644
--- a/aleksis/apps/alsijil/model_extensions.py
+++ b/aleksis/apps/alsijil/model_extensions.py
@@ -11,6 +11,7 @@ from calendarweek import CalendarWeek
 from aleksis.apps.alsijil.managers import PersonalNoteQuerySet
 from aleksis.apps.chronos.models import Event, ExtraLesson, LessonPeriod
 from aleksis.core.models import Group, Person
+from aleksis.core.util.core_helpers import get_site_preferences
 
 from .models import ExcuseType, ExtraMark, LessonDocumentation, PersonalNote
 
@@ -385,8 +386,16 @@ def get_groups_with_lessons(cls: Group):
 def get_owner_groups_with_lessons(self: Person):
     """Get all groups the person is an owner of and which have related lessons.
 
-    Groups which have child groups with related lessons are also included.
+    Groups which have child groups with related lessons are also included, as well as all
+    child groups of the groups owned by the person with related lessons if the
+    inherit_privileges_from_parent_group preference is turned on.
     """
+    if get_site_preferences()["alsijil__inherit_privileges_from_parent_group"]:
+        return (
+            Group.get_groups_with_lessons()
+            .filter(Q(owners=self) | Q(parent_groups__owners=self))
+            .distinct()
+        )
     return Group.get_groups_with_lessons().filter(owners=self).distinct()
 
 
-- 
GitLab