wagtail-nest / wagtail-review

A Wagtail extension for gathering annotations and feedback on pages before publication
BSD 3-Clause "New" or "Revised" License
49 stars 19 forks source link

Feat: Update for wagtail version 6 #54

Closed oladhari closed 2 months ago

oladhari commented 5 months ago

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 commented 2 months ago

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