Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Update for wagtail version 6 #54

Closed
oladhari opened this issue May 25, 2024 · 1 comment
Closed

Feat: Update for wagtail version 6 #54

oladhari opened this issue May 25, 2024 · 1 comment

Comments

@oladhari
Copy link

oladhari commented May 25, 2024

this is the error that is appearing:

ImportError: cannot import name 'UserPagePermissionsProxy' from 'wagtail.models' 

and here how it is explained to be fixed:
The wagtail.models.UserPagePermissionsProxy class and get_pages_with_direct_explore_permission, get_explorable_root_page and users_with_page_permission functions have been removed; equivalent functionality exists in the wagtail.permission_policies.pages.PagePermissionPolicy class.

here how it should be the code:

from wagtail.permission_policies.pages import PagePermissionPolicy

 @classmethod
    def get_pages_with_reviews_for_user(cls, user):
        """
        Return a queryset of pages which have reviews, for which the user has edit permission
        """
        permission_policy = PagePermissionPolicy()
        reviewed_pages = cls.objects.order_by("-created_at").values_list(
            revision_page_fk_relation, "created_at"
        )
        # Annotate datetime when a review was last created for this page
        last_review_requested_at = Case(
            *[When(pk=pk, then=Value(created_at)) for pk, created_at in reviewed_pages],
            output_field=models.DateTimeField(),
        )
        return (
            permission_policy.instances_user_has_permission_for(user, "change")
            .filter(pk__in=(page[0] for page in reviewed_pages))
            .annotate(last_review_requested_at=last_review_requested_at)
            .order_by("-last_review_requested_at")
        )
        
@gasman
Copy link
Contributor

gasman commented Aug 19, 2024

The commit to address this was made in 2ee7230, but didn't make it into a release yet - working on that now.

@gasman gasman closed this as completed Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants