Skip to content

Commit a87f833

Browse files
authored
fix: CampaignTeamListView permission check (#1029)
2 parents 116105a + d70a7d2 commit a87f833

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

bullet/bullet_admin/views/emails.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from functools import cached_property
2+
13
from competitions.branches import Branch
24
from django.contrib import messages
35
from django.core.exceptions import PermissionDenied
@@ -145,19 +147,21 @@ class CampaignTeamListView(PermissionCheckMixin, TemplateView):
145147
required_permissions = [is_admin]
146148
template_name = "bullet_admin/emails/teams.html"
147149

148-
def dispatch(self, request, *args, **kwargs):
149-
if not self.can_access():
150-
return self.handle_fail()
151-
152-
self.campaign = get_object_or_404(
150+
@cached_property
151+
def campaign(self):
152+
return get_object_or_404(
153153
EmailCampaign,
154154
competition=get_active_competition(self.request),
155-
pk=kwargs["pk"],
155+
pk=self.kwargs["pk"],
156156
)
157-
if not can_edit_campaign(self.request, self.campaign):
158-
return self.handle_fail()
159157

160-
return super().dispatch(request, *args, **kwargs)
158+
def check_custom_permission(self, user: User) -> bool | None:
159+
"""
160+
You must be branch admin to edit global emails,
161+
or country admin to edit emails targeting your countries,
162+
or venue admin to edit emails targeting your venues.
163+
"""
164+
return can_edit_campaign(self.request, self.campaign)
161165

162166
def get_context_data(self, **kwargs):
163167
ctx = super().get_context_data(**kwargs)

0 commit comments

Comments
 (0)