mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-04 21:44:44 +00:00
This commit is contained in:
parent
db1e4aad15
commit
a226c7f5af
3 changed files with 34 additions and 4 deletions
|
|
@ -418,7 +418,9 @@ class BaseGroupCollectionMemberPermissionFormSet(forms.BaseFormSet):
|
|||
collections = [
|
||||
form.cleaned_data['collection']
|
||||
for form in self.forms
|
||||
if form not in self.deleted_forms
|
||||
# need to check for presence of 'collection' in cleaned_data,
|
||||
# because a completely blank form passes validation
|
||||
if form not in self.deleted_forms and 'collection' in form.cleaned_data
|
||||
]
|
||||
if len(set(collections)) != len(collections):
|
||||
# collections list contains duplicates
|
||||
|
|
@ -435,7 +437,10 @@ class BaseGroupCollectionMemberPermissionFormSet(forms.BaseFormSet):
|
|||
)
|
||||
|
||||
# get a set of (collection, permission) tuples for all ticked permissions
|
||||
forms_to_save = [form for form in self.forms if form not in self.deleted_forms]
|
||||
forms_to_save = [
|
||||
form for form in self.forms
|
||||
if form not in self.deleted_forms and 'collection' in form.cleaned_data
|
||||
]
|
||||
|
||||
final_permission_records = set()
|
||||
for form in forms_to_save:
|
||||
|
|
|
|||
|
|
@ -295,7 +295,9 @@ class BaseGroupPagePermissionFormSet(forms.BaseFormSet):
|
|||
pages = [
|
||||
form.cleaned_data['page']
|
||||
for form in self.forms
|
||||
if form not in self.deleted_forms
|
||||
# need to check for presence of 'page' in cleaned_data,
|
||||
# because a completely blank form passes validation
|
||||
if form not in self.deleted_forms and 'page' in form.cleaned_data
|
||||
]
|
||||
if len(set(pages)) != len(pages):
|
||||
# pages list contains duplicates
|
||||
|
|
@ -309,7 +311,10 @@ class BaseGroupPagePermissionFormSet(forms.BaseFormSet):
|
|||
)
|
||||
|
||||
# get a set of (page, permission_type) tuples for all ticked permissions
|
||||
forms_to_save = [form for form in self.forms if form not in self.deleted_forms]
|
||||
forms_to_save = [
|
||||
form for form in self.forms
|
||||
if form not in self.deleted_forms and 'page' in form.cleaned_data
|
||||
]
|
||||
|
||||
final_permission_records = set()
|
||||
for form in forms_to_save:
|
||||
|
|
|
|||
|
|
@ -311,6 +311,26 @@ class TestGroupCreateView(TestCase, WagtailTestUtils):
|
|||
)
|
||||
)
|
||||
|
||||
def test_can_submit_blank_permission_form(self):
|
||||
# the formsets for page / collection permissions should gracefully
|
||||
# handle (and ignore) forms that have been left entirely blank
|
||||
response = self.post({
|
||||
'name': "test group",
|
||||
'page_permissions-0-page': [''],
|
||||
'page_permissions-TOTAL_FORMS': ['1'],
|
||||
'document_permissions-0-collection': [''],
|
||||
'document_permissions-TOTAL_FORMS': ['1'],
|
||||
})
|
||||
|
||||
self.assertRedirects(response, reverse('wagtailusers_groups:index'))
|
||||
# The test group now exists, with no page / document permissions
|
||||
new_group = Group.objects.get(name='test group')
|
||||
self.assertEqual(new_group.page_permissions.all().count(), 0)
|
||||
self.assertEqual(
|
||||
new_group.collection_permissions.filter(permission=self.add_doc_permission).count(),
|
||||
0
|
||||
)
|
||||
|
||||
|
||||
class TestGroupEditView(TestCase, WagtailTestUtils):
|
||||
def setUp(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue