Skip to content

Commit

Permalink
🐛 Limit team queryset for creating roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Jip J. Dekker committed Apr 27, 2017
1 parent b5f366c commit 79c3ae8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions website/involvement/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ def get_queryset(self, request):
return qs


class RoleCreateView(CreateView):
def get_form(self, form_class=None):
form = super(RoleCreateView, self).get_form(form_class=form_class)
if not is_admin(self.request.user):
form.fields['team'].queryset = official_of(self.request.user)
return form


class RoleEditView(EditView):
def get_form(self, form_class=None):
form = super(RoleEditView, self).get_form(form_class=form_class)
if not is_admin(self.request.user):
form.fields['team'].queryset = official_of(self.request.user)
return form


class RoleAdmin(ModelAdmin):
model = Role
menu_label = _('Roles')
Expand All @@ -51,6 +67,8 @@ class RoleAdmin(ModelAdmin):
# https://code.djangoproject.com/ticket/8851#no1
list_filter = ('team', 'archived')
permission_helper_class = RulesPermissionHelper
create_view_class = RoleCreateView
edit_view_class = RoleEditView

def get_queryset(self, request):
if is_admin(request.user):
Expand Down

0 comments on commit 79c3ae8

Please sign in to comment.