From f7d5eb63699e1f43081b1b9ac347efe11dc8cede Mon Sep 17 00:00:00 2001
From: Tom Teichler <tom.teichler@teckids.org>
Date: Sat, 12 Mar 2022 01:26:46 +0100
Subject: [PATCH] Fix use of predicate

---
 aleksis/apps/paweljong/predicates.py | 17 +++++++++++++----
 aleksis/apps/paweljong/rules.py      |  2 +-
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/aleksis/apps/paweljong/predicates.py b/aleksis/apps/paweljong/predicates.py
index 1816f37..5585bf0 100644
--- a/aleksis/apps/paweljong/predicates.py
+++ b/aleksis/apps/paweljong/predicates.py
@@ -1,3 +1,5 @@
+from typing import Union
+
 from django.contrib.auth import get_user_model
 
 from rules import predicate
@@ -5,7 +7,7 @@ from rules import predicate
 from aleksis.core.models import Group, Person
 from aleksis.core.util.predicates import check_object_permission
 
-from .models import EventRegistration, Voucher
+from .models import Event, EventRegistration, Voucher
 
 User = get_user_model()
 
@@ -23,11 +25,18 @@ def is_own_registration(user: User, registration: EventRegistration) -> bool:
 
 
 @predicate
-def is_organiser(user: User, obj: EventRegistration) -> bool:
+def is_organiser(user: User, obj: Union[Event, EventRegistration]) -> bool:
     """Predicate which checks if the user is an organiser."""
-    return user.person in obj.event.linked_group.owners.all()
+    if isinstance(obj, EventRegistration):
+        event = obj.event
+    elif isinstance(obj, Event):
+        event = obj
+    else:
+        raise TypeError("This predicate can only check Event and EventRegistration.")
+
+    return user.person in event.linked_group.owners.all()
 
 @predicate
-def is_event_published(obj: EventRegistration) -> bool:
+def is_event_published(user: User, obj: EventRegistration) -> bool:
     """Predicate which checks if the event is published."""
     return obj.published
diff --git a/aleksis/apps/paweljong/rules.py b/aleksis/apps/paweljong/rules.py
index f6e1a80..feef9ea 100644
--- a/aleksis/apps/paweljong/rules.py
+++ b/aleksis/apps/paweljong/rules.py
@@ -225,6 +225,6 @@ can_view_menu_predicate = has_person & (
     | view_terms_predicate
     | view_vouchers_predicate
     | view_events_predicate
-    | view_events_registration_states_predicate
+    | view_registration_states_predicate
 )
 rules.add_perm("paweljong.view_menu", can_view_menu_predicate)
-- 
GitLab