Let coaches update payment of the team

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-03-16 07:31:19 +01:00
parent 71e33b2177
commit afbc67c413
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
1 changed files with 7 additions and 3 deletions

View File

@ -449,9 +449,13 @@ class PaymentUpdateView(LoginRequiredMixin, UpdateView):
form_class = PaymentAdminForm
def dispatch(self, request, *args, **kwargs):
if not self.request.user.is_authenticated or \
not self.request.user.registration.is_admin \
and self.request.user.registration not in self.get_object().registrations.all():
user = self.request.user
object = self.get_object()
if not user.is_authenticated or \
not user.registration.is_admin \
and (user.registration.is_volunteer and user.registration in object.tournament.organizers.all()
or user.registration.is_student and user.registration not in object.registrations.all()
or user.registration.is_coach and user.registration.team != object.team):
return self.handle_no_permission()
return super().dispatch(request, *args, **kwargs)