Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra permissions and link permisions with views #2390

Merged
merged 10 commits into from
Jan 28, 2024
24 changes: 17 additions & 7 deletions tabbycat/adjallocation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from participants.models import Adjudicator, Region
from participants.prefetch import populate_feedback_scores
from tournaments.mixins import DebateDragAndDropMixin, TournamentMixin
from users.permissions import has_permission
from users.permissions import has_permission, Permission
from utils.misc import ranks_dictionary, redirect_tournament, reverse_tournament
from utils.mixins import AdministratorMixin
from utils.views import ModelFormSetView
Expand Down Expand Up @@ -91,6 +91,8 @@ class EditDebateAdjudicatorsView(BaseEditDebateOrPanelAdjudicatorsView):
page_title = gettext_lazy("Edit Allocation")
prefetch_adjs = True # Fetched in full as get_serialised

view_permission = Permission.VIEW_DEBATEADJUDICATORS

def get_extra_info(self):
info = super().get_extra_info()
return info
Expand All @@ -105,6 +107,8 @@ class EditPanelAdjudicatorsView(BaseEditDebateOrPanelAdjudicatorsView):
template_name = "edit_panel_adjudicators.html"
page_title = gettext_lazy("Edit Panels")

view_permission = Permission.VIEW_PREFORMEDPANELS

def get_extra_info(self):
info = super().get_extra_info()
info['backUrl'] = reverse_tournament('panel-adjudicators-index',
Expand Down Expand Up @@ -146,12 +150,6 @@ class BaseAdjudicatorConflictsView(LogActionMixin, AdministratorMixin, Tournamen

formset_factory_kwargs = {}

def get_view_permission(self):
return 'view.%s' % (self.formset_model.__name__.lower())

def get_edit_permission(self):
return 'edit.%s' % (self.formset_model.__name__.lower())

def get_formset_factory_kwargs(self):
can_edit = has_permission(self.request.user, self.get_edit_permission(), self.tournament)
kwargs = super().get_formset_factory_kwargs()
Expand Down Expand Up @@ -187,6 +185,9 @@ def formset_valid(self, formset):

class AdjudicatorTeamConflictsView(BaseAdjudicatorConflictsView):

view_permission = Permission.VIEW_ADJ_TEAM_CONFLICTS
edit_permission = Permission.EDIT_ADJ_TEAM_CONFLICTS

tienne-B marked this conversation as resolved.
Show resolved Hide resolved
action_log_type = ActionLogEntry.ACTION_TYPE_CONFLICTS_ADJ_TEAM_EDIT
formset_model = AdjudicatorTeamConflict
page_title = gettext_lazy("Adjudicator-Team Conflicts")
Expand Down Expand Up @@ -231,6 +232,9 @@ def add_message(self, nsaved, ndeleted):

class AdjudicatorAdjudicatorConflictsView(BaseAdjudicatorConflictsView):

view_permission = Permission.VIEW_ADJ_ADJ_CONFLICTS
edit_permission = Permission.EDIT_ADJ_ADJ_CONFLICTS

action_log_type = ActionLogEntry.ACTION_TYPE_CONFLICTS_ADJ_ADJ_EDIT
formset_model = AdjudicatorAdjudicatorConflict
page_title = gettext_lazy("Adjudicator-Adjudicator Conflicts")
Expand Down Expand Up @@ -271,6 +275,9 @@ def add_message(self, nsaved, ndeleted):

class AdjudicatorInstitutionConflictsView(BaseAdjudicatorConflictsView):

view_permission = Permission.VIEW_ADJ_INST_CONFLICTS
edit_permission = Permission.EDIT_ADJ_INST_CONFLICTS

action_log_type = ActionLogEntry.ACTION_TYPE_CONFLICTS_ADJ_INST_EDIT
formset_model = AdjudicatorInstitutionConflict
page_title = gettext_lazy("Adjudicator-Institution Conflicts")
Expand Down Expand Up @@ -310,6 +317,9 @@ def add_message(self, nsaved, ndeleted):

class TeamInstitutionConflictsView(BaseAdjudicatorConflictsView):

view_permission = Permission.VIEW_TEAM_INST_CONFLICTS
edit_permission = Permission.EDIT_TEAM_INST_CONFLICTS

action_log_type = ActionLogEntry.ACTION_TYPE_CONFLICTS_TEAM_INST_EDIT
formset_model = TeamInstitutionConflict
page_title = gettext_lazy("Team-Institution Conflicts")
Expand Down
2 changes: 1 addition & 1 deletion tabbycat/adjfeedback/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ def modify_adjudicator(self, request, adjudicator):
class SetAdjudicatorBreakingStatusView(AdministratorMixin, TournamentMixin, LogActionMixin, View):

action_log_type = ActionLogEntry.ACTION_TYPE_ADJUDICATOR_BREAK_SET
edit_permission = Permission.EDIT_SETBREAKING
edit_permission = Permission.EDIT_ADJ_BREAK

def post(self, request, *args, **kwargs):
body = self.request.body.decode('utf-8')
Expand Down
13 changes: 13 additions & 0 deletions tabbycat/availability/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from draw.models import Debate
from participants.models import Adjudicator, Team
from tournaments.mixins import RoundMixin
from users.permissions import Permission
from utils.misc import reverse_round
from utils.mixins import AdministratorMixin
from utils.tables import TabbycatTableBuilder
Expand Down Expand Up @@ -206,6 +207,10 @@ def get_table(self):


class AvailabilityTypeTeamView(AvailabilityTypeBase):

view_permission = Permission.VIEW_ROUNDAVAILABILITIES_TEAM
edit_permission = Permission.EDIT_ROUNDAVAILABILITIES_TEAM

page_title = gettext_lazy("Team Availability")
page_emoji = '👂'
model = Team
Expand All @@ -225,6 +230,10 @@ def annotate_checkins(queryset, t):


class AvailabilityTypeAdjudicatorView(AvailabilityTypeBase):

view_permission = Permission.VIEW_ROUNDAVAILABILITIES_ADJ
edit_permission = Permission.EDIT_ROUNDAVAILABILITIES_ADJ

page_title = gettext_lazy("Adjudicator Availability")
page_emoji = '👂'
model = Adjudicator
Expand All @@ -244,6 +253,10 @@ def annotate_checkins(queryset, t):


class AvailabilityTypeVenueView(AvailabilityTypeBase):

view_permission = Permission.VIEW_ROUNDAVAILABILITIES_VENUE
edit_permission = Permission.EDIT_ROUNDAVAILABILITIES_VENUE

page_title = gettext_lazy("Room Availability")
page_emoji = '🎪'
model = Venue
Expand Down
5 changes: 5 additions & 0 deletions tabbycat/checkins/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from participants.models import Person, Speaker
from participants.serializers import InstitutionSerializer
from tournaments.mixins import PublicTournamentPageMixin, TournamentMixin
from users.permissions import Permission
from utils.misc import reverse_tournament
from utils.mixins import AdministratorMixin, AssistantMixin
from utils.views import PostOnlyRedirectView
Expand Down Expand Up @@ -63,6 +64,8 @@ class CheckInPeopleStatusView(BaseCheckInStatusView):
page_title = _("People's Check-In Statuses")
window_preference = 'checkin_window_people'

edit_permission = Permission.EDIT_PARTICIPANT_CHECKIN

def get_context_data(self, **kwargs):

team_codes = use_team_code_names(self.tournament, admin=self.for_admin)
Expand Down Expand Up @@ -120,6 +123,8 @@ class CheckInVenuesStatusView(BaseCheckInStatusView):
page_title = _("Rooms' Check-In Statuses")
window_preference = 'checkin_window_venues'

edit_permission = Permission.EDIT_ROOM_CHECKIN

def get_context_data(self, **kwargs):
venues = []
for venue in self.tournament.relevant_venues.select_related('checkin_identifier').prefetch_related('venuecategory_set').all():
Expand Down
10 changes: 9 additions & 1 deletion tabbycat/draw/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
TournamentMixin)
from tournaments.models import Round
from tournaments.utils import get_side_name
from users.permissions import Permission
from utils.misc import reverse_round, reverse_tournament
from utils.mixins import AdministratorMixin
from utils.tables import TabbycatTableBuilder
Expand Down Expand Up @@ -445,6 +446,8 @@ def get_queryset(self):
class AdminDrawView(RoundMixin, AdministratorMixin, AdminDrawUtilitiesMixin, VueTableTemplateView):
detailed = False

view_permission = Permission.VIEW_ADMIN_DRAW

def get_page_title(self):
round = self.round
self.page_emoji = '👀'
Expand Down Expand Up @@ -655,7 +658,7 @@ class DrawStatusEdit(LogActionMixin, AdministratorMixin, RoundMixin, PostOnlyRed


class CreateDrawView(DrawStatusEdit):

edit_permission = Permission.GENERATE_DEBATE
action_log_type = ActionLogEntry.ACTION_TYPE_DRAW_CREATE

def post(self, request, *args, **kwargs):
Expand Down Expand Up @@ -741,6 +744,7 @@ class ConfirmDrawRegenerationView(AdministratorMixin, TemplateView):


class DrawReleaseView(DrawStatusEdit):
edit_permission = Permission.RELEASE_DRAW
action_log_type = ActionLogEntry.ACTION_TYPE_DRAW_RELEASE
round_redirect_pattern_name = 'draw-display'

Expand All @@ -761,6 +765,7 @@ def post(self, request, *args, **kwargs):


class DrawUnreleaseView(DrawStatusEdit):
edit_permission = Permission.UNRELEASE_DRAW
action_log_type = ActionLogEntry.ACTION_TYPE_DRAW_UNRELEASE
round_redirect_pattern_name = 'draw-display'

Expand All @@ -777,6 +782,7 @@ def post(self, request, *args, **kwargs):


class SetRoundStartTimeView(DrawStatusEdit):
edit_permission = Permission.EDIT_STARTTIME
action_log_type = ActionLogEntry.ACTION_TYPE_ROUND_START_TIME_SET
round_redirect_pattern_name = 'draw-display'

Expand Down Expand Up @@ -828,6 +834,7 @@ def get_table(self):


class SideAllocationsView(AdministratorMixin, BaseSideAllocationsView):
view_permission = Permission.EDIT_ALLOCATESIDES
pass


Expand All @@ -839,6 +846,7 @@ class EditDebateTeamsView(DebateDragAndDropMixin, AdministratorMixin, TemplateVi
template_name = "edit_debate_teams.html"
page_title = gettext_lazy("Edit Matchups")
prefetch_teams = False # Fetched in full as get_serialised
edit_permission = Permission.EDIT_DEBATETEAMS

def get_serialised_allocatable_items(self):
# TODO: account for shared teams
Expand Down
5 changes: 5 additions & 0 deletions tabbycat/importer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from participants.utils import populate_code_names
from tournaments.mixins import TournamentMixin
from tournaments.models import Tournament
from users.permissions import Permission
from utils.misc import redirect_tournament, reverse_tournament
from utils.mixins import AdministratorMixin
from utils.views import PostOnlyRedirectView
Expand Down Expand Up @@ -97,6 +98,7 @@ def done(self, form_list, form_dict, **kwargs):

class ImportInstitutionsWizardView(BaseImportWizardView):
model = Institution
edit_permission = Permission.ADD_INSTITUTIONS
form_list = [
('raw', ImportInstitutionsRawForm),
('details', modelformset_factory(Institution, fields=('name', 'code'), extra=0)),
Expand All @@ -112,6 +114,7 @@ def get_message(self, count):

class ImportVenuesWizardView(BaseImportWizardView):
model = Venue
edit_permission = Permission.ADD_ROOMS
form_list = [
('raw', ImportVenuesRawForm),
('details', modelformset_factory(Venue, form=VenueDetailsForm, extra=0)),
Expand Down Expand Up @@ -171,6 +174,7 @@ def get_details_instance_initial(self):

class ImportTeamsWizardView(BaseImportByInstitutionWizardView):
model = Team
edit_permission = Permission.ADD_TEAMS
form_list = [
('numbers', ImportTeamsNumbersForm),
('details', modelformset_factory(Team, form=TeamDetailsForm, formset=TeamDetailsFormSet, extra=0)),
Expand All @@ -193,6 +197,7 @@ def get_message(self, count):

class ImportAdjudicatorsWizardView(BaseImportByInstitutionWizardView):
model = Adjudicator
edit_permission = Permission.ADD_ADJUDICATORS
form_list = [
('numbers', ImportAdjudicatorsNumbersForm),
('details', modelformset_factory(Adjudicator, form=AdjudicatorDetailsForm, extra=0)),
Expand Down
7 changes: 5 additions & 2 deletions tabbycat/motions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from tournaments.mixins import (CurrentRoundMixin, OptionalAssistantTournamentPageMixin,
PublicTournamentPageMixin, RoundMixin, TournamentMixin)
from tournaments.models import Round
from users.permissions import Permission
from utils.misc import redirect_round
from utils.mixins import AdministratorMixin
from utils.views import ModelFormSetView, PostOnlyRedirectView
Expand Down Expand Up @@ -43,7 +44,8 @@ def get_context_data(self, **kwargs):
class EditMotionsView(AdministratorMixin, LogActionMixin, RoundMixin, ModelFormSetView):
# Django doesn't have a class-based view for formsets, so this implements
# the form processing analogously to FormView, with less decomposition.

view_permission = Permission.VIEW_MOTION
edit_permission = Permission.EDIT_MOTION
template_name = 'motions_edit.html'
action_log_type = ActionLogEntry.ACTION_TYPE_MOTION_EDIT
formset_model = Motion
Expand Down Expand Up @@ -167,7 +169,7 @@ def post(self, request, *args, **kwargs):


class ReleaseMotionsView(BaseReleaseMotionsView):

edit_permission = Permission.RELEASE_MOTION
action_log_type = ActionLogEntry.ACTION_TYPE_MOTIONS_RELEASE
motions_released = True

Expand Down Expand Up @@ -266,6 +268,7 @@ class AdminRoundMotionStatisticsView(AdministratorMixin, RoundMotionStatisticsVi


class AdminGlobalMotionStatisticsView(AdministratorMixin, GlobalMotionStatisticsView):
view_permission = Permission.VIEW_MOTIONSTAB
pass


Expand Down
6 changes: 5 additions & 1 deletion tabbycat/participants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from tournaments.mixins import (PublicTournamentPageMixin,
SingleObjectFromTournamentMixin, TournamentMixin)
from tournaments.models import Round
from users.permissions import Permission
from utils.misc import redirect_tournament, reverse_tournament
from utils.mixins import AdministratorMixin, AssistantMixin
from utils.tables import TabbycatTableBuilder
Expand Down Expand Up @@ -69,6 +70,7 @@ def get_context_data(self, **kwargs):


class AdminParticipantsListView(AdministratorMixin, BaseParticipantsListView):
view_permission = Permission.VIEW_PARTICIPANTS
template_name = 'participants_list.html'
admin = True

Expand Down Expand Up @@ -118,6 +120,7 @@ def get_table(self):


class AdminInstitutionsListView(AdministratorMixin, BaseInstitutionsListView):
view_permission = Permission.VIEW_INSTITUTIONS
template_name = 'participants_list.html'
admin = True

Expand Down Expand Up @@ -323,7 +326,7 @@ class EditSpeakerCategoriesView(LogActionMixin, AdministratorMixin, TournamentMi
# uniqueness checks will work. Since this is a superuser form, they can
# access all tournaments anyway, so tournament forgery wouldn't be a
# security risk.

view_permission = Permission.VIEW_SPEAKER_CATEGORIES
template_name = 'speaker_categories_edit.html'
formset_model = SpeakerCategory
action_log_type = ActionLogEntry.ACTION_TYPE_SPEAKER_CATEGORIES_EDIT
Expand Down Expand Up @@ -386,6 +389,7 @@ class EditSpeakerCategoryEligibilityView(AdministratorMixin, TournamentMixin, Vu
template_name = 'edit_speaker_eligibility.html'
page_title = _("Speaker Category Eligibility")
page_emoji = '🍯'
edit_permission = Permission.EDIT_SPEAKER_CATEGORIES

def get_table(self):
table = TabbycatTableBuilder(view=self, sort_key='team')
Expand Down
5 changes: 4 additions & 1 deletion tabbycat/privateurls/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from participants.views import BaseRecordView
from tournaments.mixins import PersonalizablePublicTournamentPageMixin, SingleObjectByRandomisedUrlMixin, TournamentMixin
from tournaments.models import Round
from users.permissions import Permission
from utils.misc import reverse_tournament
from utils.mixins import AdministratorMixin
from utils.tables import TabbycatTableBuilder
Expand Down Expand Up @@ -60,6 +61,7 @@ def get_participants_to_email(self, already_sent: bool = False) -> 'QuerySet[Per

class RandomisedUrlsView(RandomisedUrlsMixin, VueTableTemplateView):

view_permission = Permission.VIEW_PRIVATE_URLS
template_name = 'private_urls.html'
tables_orientation = 'columns'

Expand Down Expand Up @@ -113,6 +115,7 @@ def get_tables(self) -> List[TabbycatTableBuilder]:
class GenerateRandomisedUrlsView(AdministratorMixin, TournamentMixin, PostOnlyRedirectView):

tournament_redirect_pattern_name = 'privateurls-list'
edit_permission = Permission.GENERATE_PRIVATE_URLS

def post(self, request: 'HttpRequest', *args, **kwargs) -> 'HttpResponseRedirect':
tournament = self.tournament
Expand Down Expand Up @@ -149,7 +152,7 @@ def post(self, request: 'HttpRequest', *args, **kwargs) -> 'HttpResponseRedirect

class EmailRandomisedUrlsView(RoleColumnMixin, TournamentTemplateEmailCreateView):
page_subtitle = _("Private URLs")

edit_permission = Permission.SEND_PRIVATE_URLS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also add a view permission here, maybe a new one as this also has email addresses, so more personal details.

event = BulkNotification.EventType.URL
subject_template = 'url_email_subject'
message_template = 'url_email_message'
Expand Down
2 changes: 2 additions & 0 deletions tabbycat/results/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
RoundMixin, SingleObjectByRandomisedUrlMixin, SingleObjectFromTournamentMixin,
TournamentMixin)
from tournaments.models import Round
from users.permissions import Permission
from utils.misc import get_ip_address, reverse_round, reverse_tournament
from utils.mixins import AdministratorMixin, AssistantMixin
from utils.tables import TabbycatTableBuilder
Expand Down Expand Up @@ -378,6 +379,7 @@ def post(self, request, *args, **kwargs):

class AdministratorBallotSetMixin(AdministratorMixin):
template_name = 'ballot_entry.html'
edit_permission = Permission.ADD_BALLOTSUBMISSIONS
tabroom = True

def get_success_url(self):
Expand Down
Loading
Loading