diff --git a/wagtail/wagtailadmin/tests/test_pages_views.py b/wagtail/wagtailadmin/tests/test_pages_views.py index 28a558bbb..e9a3a32a1 100644 --- a/wagtail/wagtailadmin/tests/test_pages_views.py +++ b/wagtail/wagtailadmin/tests/test_pages_views.py @@ -837,6 +837,9 @@ class TestPageCopy(TestCase, WagtailTestUtils): # Check that the copy exists self.assertTrue(self.root_page.get_children().filter(slug='hello-world-2').exists()) + # Check that the owner of the page is set correctly + self.assertEqual(self.root_page.get_children().filter(slug='hello-world-2').first().owner, self.user) + def test_page_copy_post_existing_slug(self): # This tests the existing slug checking on page copy diff --git a/wagtail/wagtailadmin/views/pages.py b/wagtail/wagtailadmin/views/pages.py index c9cae9e16..d0dd21e2b 100644 --- a/wagtail/wagtailadmin/views/pages.py +++ b/wagtail/wagtailadmin/views/pages.py @@ -660,7 +660,7 @@ def copy(request, page_id): # Check if user is submitting if request.method == 'POST' and form.is_valid(): # Copy the page - page.copy( + new_page = page.copy( recursive=form.cleaned_data['copy_subpages'], update_attrs={ 'title': form.cleaned_data['new_title'], @@ -668,6 +668,9 @@ def copy(request, page_id): } ) + # Assign usef of this request as the owner of all the new pages + new_page.get_descendants(inclusive=True).update(owner=request.user) + # Give a success message back to the user if form.cleaned_data['copy_subpages']: messages.success(request, _("Page '{0}' and {1} subpages copied.").format(page.title, subpage_count))