mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-04-12 02:50:59 +00:00
Validate the copy form on page paremissions for the new parent page
This commit is contained in:
parent
bb4ea5922c
commit
ae487a22c8
2 changed files with 8 additions and 3 deletions
|
|
@ -120,9 +120,9 @@ class CopyForm(forms.Form):
|
|||
def __init__(self, *args, **kwargs):
|
||||
# CopyPage must be passed a 'page' kwarg indicating the page to be copied
|
||||
self.page = kwargs.pop('page')
|
||||
self.user = kwargs.pop('user', None)
|
||||
can_publish = kwargs.pop('can_publish')
|
||||
super(CopyForm, self).__init__(*args, **kwargs)
|
||||
|
||||
self.fields['new_title'] = forms.CharField(initial=self.page.title, label=_("New title"))
|
||||
self.fields['new_slug'] = forms.SlugField(initial=self.page.slug, label=_("New slug"))
|
||||
self.fields['new_parent_page'] = forms.ModelChoiceField(
|
||||
|
|
@ -132,7 +132,6 @@ class CopyForm(forms.Form):
|
|||
label=_("New parent page"),
|
||||
help_text=_("This copy will be a child of this given parent page.")
|
||||
)
|
||||
|
||||
pages_to_copy = self.page.get_descendants(inclusive=True)
|
||||
subpage_count = pages_to_copy.count() - 1
|
||||
if subpage_count > 0:
|
||||
|
|
@ -170,6 +169,12 @@ class CopyForm(forms.Form):
|
|||
# New parent page given in form or parent of source, if parent_page is empty
|
||||
parent_page = cleaned_data.get('new_parent_page') or self.page.get_parent()
|
||||
|
||||
# check if user is allowed to create a page at given location.
|
||||
if not parent_page.permissions_for_user(self.user).can_add_subpage():
|
||||
self._errors['new_parent_page'] = self.error_class([
|
||||
_("You do not have permission to copy to page \"%(page_title)s\"") % {'page_title': parent_page.get_admin_display_title()}
|
||||
])
|
||||
|
||||
# Count the pages with the same slug within the context of our copy's parent page
|
||||
if slug and parent_page.get_children().filter(slug=slug).count():
|
||||
self._errors['new_slug'] = self.error_class(
|
||||
|
|
|
|||
|
|
@ -794,7 +794,7 @@ def copy(request, page_id):
|
|||
can_publish = parent_page.permissions_for_user(request.user).can_publish_subpage()
|
||||
|
||||
# Create the form
|
||||
form = CopyForm(request.POST or None, page=page, can_publish=can_publish)
|
||||
form = CopyForm(request.POST or None, user=request.user, page=page, can_publish=can_publish)
|
||||
|
||||
next_url = get_valid_next_url_from_request(request)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue