diff --git a/aleksis/apps/paweljong/rules.py b/aleksis/apps/paweljong/rules.py index b524f2c3bd30cb59f5b37f2309fabb2239184393..7e52d04e137f80870edae358a8ebb5ab663a9824 100644 --- a/aleksis/apps/paweljong/rules.py +++ b/aleksis/apps/paweljong/rules.py @@ -55,13 +55,21 @@ rules.add_perm("paweljong.create_vouchers_rule", create_vouchers_predicate) # View events view_events_predicate = has_person & ( - has_global_perm("paweljong.view_event") | has_any_object("paweljong.view_event", Event) + has_global_perm("paweljong.view_event") | has_any_object("paweljong.view_event_rule", Event) ) rules.add_perm("paweljong.view_events_rule", view_events_predicate) +# Edit events +change_events_predicate = has_person & ( + has_global_perm("paweljong.change_event") | has_any_object("paweljong.change_event_rule", Event) +) +rules.add_perm("paweljong.change_events_rule", change_events_predicate) + # Edit event change_event_predicate = has_person & ( - has_global_perm("paweljong.change_event") | has_object_perm("paweljong.change_event") + has_global_perm("paweljong.change_event") + | has_object_perm("paweljong.change_event") + | is_organiser ) rules.add_perm("paweljong.change_event_rule", change_event_predicate) diff --git a/aleksis/apps/paweljong/templates/paweljong/event/detail.html b/aleksis/apps/paweljong/templates/paweljong/event/detail.html index f553959001486dc0e850f2a090d0a614c02cb880..93ee3dad2341011009c09a54a0c2ed0c715ec649 100644 --- a/aleksis/apps/paweljong/templates/paweljong/event/detail.html +++ b/aleksis/apps/paweljong/templates/paweljong/event/detail.html @@ -14,17 +14,14 @@ {% block content %} <h4>{{ event }}</h4> - {% has_perm 'paweljong.manage_event' user event as can_manage_event %} + {% has_perm 'paweljong.change_event_rule' user event as can_change_event_rule %} - {% if can_manage_event %} + {% if can_change_event_rule %} <p> - {% if can_manage_event %} - <a href="{% url 'edit_event_by_slug' event.slug %}" class="btn waves-effect waves-light"> - <i class="material-icons left iconify" data-icon="mdi:edit"></i> - {% trans "Edit" %} - </a> - {% endif %} - + <a href="{% url 'edit_event_by_slug' event.slug %}" class="btn waves-effect waves-light"> + <i class="material-icons left iconify" data-icon="mdi:edit"></i> + {% trans "Edit" %} + </a> </p> {% endif %} diff --git a/aleksis/apps/paweljong/views.py b/aleksis/apps/paweljong/views.py index 3b1f54228b131fe5ce8cdce5d6d6b771ff3016e9..47d228db56ab15f035c5deceb98719748c4f795f 100644 --- a/aleksis/apps/paweljong/views.py +++ b/aleksis/apps/paweljong/views.py @@ -144,7 +144,7 @@ class EventRegistrationCreateView(PermissionRequiredMixin, AdvancedCreateView): model = EventRegistration form_class = EditEventRegistrationForm - permission_required = "paweljong.create_eventregistration_rule" + permission_required = "paweljong.create_registration_rule" template_name = "paweljong/event_registration/create.html" success_url = reverse_lazy("registrations") success_message = _("The event registration has been created.") @@ -156,14 +156,14 @@ class EventRegistrationEditView(PermissionRequiredMixin, AdvancedEditView): model = EventRegistration form_class = EditEventRegistrationForm - permission_required = "paweljong.change_eventregistration_rule" + permission_required = "paweljong.change_registration_rule" template_name = "paweljong/event_registration/edit.html" success_url = reverse_lazy("registrations") success_message = _("The event registration has been saved.") @permission_required( - "paweljong.change_eventregistration_rule", + "paweljong.change_registration_rule", fn=objectgetter_optional(EventRegistration, None, False), ) def edit_registration(request: HttpRequest, pk) -> HttpResponse: @@ -894,8 +894,11 @@ class RetractRegistration(PermissionRequiredMixin, View): permission_required = "paweljong.can_retract_registration_rule" + def get_object(self, *args, **kwargs): + return EventRegistration.objects.get(id=self.kwargs["pk"]) + def get(self, *args, **kwargs): - registration = EventRegistration.objects.get(id=self.kwargs["pk"]) + registration = self.get_object() registration.retract() messages.success(self.request, _("Registration successfully retracted.")) @@ -979,8 +982,11 @@ class CheckInRegistration(PermissionRequiredMixin, View): permission_required = "paweljong.change_registration_rule" + def get_object(self, *args, **kwargs): + return EventRegistration.objects.get(id=self.kwargs["pk"]) + def get(self, *args, **kwargs): - registration = EventRegistration.objects.get(id=self.kwargs["pk"]) + registration = self.get_object() try: registration.mark_checked_in()