|
| 1 | +from functools import cached_property |
| 2 | + |
1 | 3 | from competitions.branches import Branch |
2 | 4 | from django.contrib import messages |
3 | 5 | from django.core.exceptions import PermissionDenied |
@@ -145,19 +147,21 @@ class CampaignTeamListView(PermissionCheckMixin, TemplateView): |
145 | 147 | required_permissions = [is_admin] |
146 | 148 | template_name = "bullet_admin/emails/teams.html" |
147 | 149 |
|
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( |
153 | 153 | EmailCampaign, |
154 | 154 | competition=get_active_competition(self.request), |
155 | | - pk=kwargs["pk"], |
| 155 | + pk=self.kwargs["pk"], |
156 | 156 | ) |
157 | | - if not can_edit_campaign(self.request, self.campaign): |
158 | | - return self.handle_fail() |
159 | 157 |
|
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) |
161 | 165 |
|
162 | 166 | def get_context_data(self, **kwargs): |
163 | 167 | ctx = super().get_context_data(**kwargs) |
|
0 commit comments