question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sorting pages with a parent_page_types restriction raises a MovePagePermissionError

See original GitHub issue

Issue Summary

If you have a list of pages that are restricted to a certain parent page type and you toggle the sorting via “sort menu order”, sorting raises a MovePagePermissionError.

Steps to Reproduce

  1. Start a new project with wagtail start myproject
  2. Edit home/models.py, and add another page type:
class AnotherPage(Page):
    parent_page_types = ["home.HomePage"]
  1. run python manage.py makemigrations and python manage.py migrate
  2. Go to the Wagtail Admin, and add a few child pages under the Home page
  3. While viewing the contents of the Home page, toggle the page sorting option via More -> Sort Menu Order: image
  4. Try to reorder the pages. The order is not being saved. My local development server outputs the following:
raise MovePagePermissionError(
wagtail.core.actions.move_page.MovePagePermissionError: You do not have permission to move the page to the target specified.

If I remove the parent_page_types restriction from the model definition, everything works as expected.

  • I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: (yes / ~no~)

Technical details

  • Python version: 3.9.7
  • Django version: 3.2.12 and 4.0.2
  • Wagtail version: 2.16.1
  • Browser version: Firefox 96.0.3

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:13 (13 by maintainers)

github_iconTop GitHub Comments

3reactions
thijskramercommented, Mar 3, 2022

Is there anything I have to do that prevents this PR from being merged?

2reactions
robmoormancommented, Feb 17, 2022

Update: parent.specific_class is wrong (it’s the same as the cls in this case. But it’s definitely not the case.

The parent is wrong is this case. It’s not the parent but the target page (left/right pos)…

Making this parent (a trace higher) also wrong:

def can_move_to(self, parent):
    """
    Checks if this page instance can be moved to be a subpage of a parent
    page instance.
    """
    # Prevent pages from being moved to different language sections
    # The only page that can have multi-lingual children is the root page
    parent_is_root = parent.depth == 1
    if not parent_is_root and parent.locale_id != self.locale_id:
        return False

    return self.can_exist_under(parent)

This parent is also wrong.

Highest trace is this:

  def move(self, target, pos=None, user=None):
      """
      Extension to the treebeard 'move' method to ensure that url_path is updated,
      and to emit a 'pre_page_move' and 'post_page_move' signals.
      """
      return MovePageAction(self, target, pos=pos, user=user).execute()

This returns False in can_move_to:

        # reject moves that are forbidden by subpage_types / parent_page_types rules
        # (these rules apply to superusers too)
        if not self.page.specific.can_move_to(destination):

This code uses the can_move_to from a Page (see first code snippet here) and that’s expecint a truly parent but it’s not… as this is the destination page (left/rigth), so from the same page type.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found