From 29f62605a302a57b8915acf1fbb9306f5c99db76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Beaul=C3=A9?= Date: Sun, 29 Dec 2024 10:51:59 -0500 Subject: [PATCH] Add permissions for confirming/weighting rounds --- tabbycat/tournaments/views.py | 10 +++++++++- tabbycat/users/permissions.py | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tabbycat/tournaments/views.py b/tabbycat/tournaments/views.py index 95aaf73fe6e..7de8f7e77ef 100644 --- a/tabbycat/tournaments/views.py +++ b/tabbycat/tournaments/views.py @@ -19,7 +19,7 @@ from results.models import BallotSubmission from results.prefetch import populate_confirmed_ballots from tournaments.models import Round -from users.permissions import has_permission +from users.permissions import has_permission, Permission from utils.misc import redirect_round, redirect_tournament, reverse_round, reverse_tournament from utils.mixins import (AdministratorMixin, AssistantMixin, CacheMixin, TabbycatPageTitlesMixin, WarnAboutDatabaseUseMixin, WarnAboutLegacySendgridConfigVarsMixin) @@ -128,6 +128,7 @@ class TournamentAdminHomeView(AdministratorMixin, BaseTournamentDashboardHomeVie class CompleteRoundCheckView(AdministratorMixin, RoundMixin, TemplateView): template_name = 'round_complete_check.html' + view_permission = True def get_context_data(self, **kwargs): prior_rounds_not_completed = self.tournament.round_set.filter( @@ -152,6 +153,7 @@ def get_context_data(self, **kwargs): class CompleteRoundToggleSilentView(AdministratorMixin, RoundMixin, PostOnlyRedirectView): round_redirect_pattern_name = 'tournament-complete-round-check' + edit_permission = Permission.SILENCE_ROUND def post(self, request, *args, **kwargs): self.round.silent = request.POST["state"] != "True" @@ -168,6 +170,7 @@ def post(self, request, *args, **kwargs): class CompleteRoundView(RoundMixin, AdministratorMixin, LogActionMixin, PostOnlyRedirectView): action_log_type = ActionLogEntry.ActionType.ROUND_COMPLETE + edit_permission = Permission.CONFIRM_ROUND def post(self, request, *args, **kwargs): self.round.completed = True @@ -259,6 +262,9 @@ class SetCurrentRoundView(AdministratorMixin, TournamentMixin, FormView): page_title = _('Set Current Round') page_emoji = '🙏' + view_permission = True + edit_permission = Permission.CONFIRM_ROUND + def get_form_class(self): if self.tournament.breakcategory_set.count() <= 1: return SetCurrentRoundSingleBreakCategoryForm @@ -308,6 +314,8 @@ def get_context_data(self, **kwargs): class SetRoundWeightingsView(AdministratorMixin, TournamentMixin, FormView): template_name = 'set_round_weights.html' form_class = RoundWeightForm + view_permission = True + edit_permission = Permission.EDIT_ROUND def get_form_kwargs(self): kwargs = super().get_form_kwargs() diff --git a/tabbycat/users/permissions.py b/tabbycat/users/permissions.py index 7a1925954b9..8078ed6d085 100644 --- a/tabbycat/users/permissions.py +++ b/tabbycat/users/permissions.py @@ -146,6 +146,8 @@ class Permission(TextChoices): EDIT_ROUND = 'edit.round', _("edit round attributes") DELETE_ROUND = 'delete.round', _("delete rounds") CREATE_ROUND = 'add.round', _("create rounds") + CONFIRM_ROUND = 'confirm.round', _("confirm rounds") + SILENCE_ROUND = 'silence.round', _("silence rounds") VIEW_EMAIL_STATUSES = 'view.emails', _("view email statuses") SEND_EMAILS = 'send.emails', _("send participants email messages")