Пример #1
0
    def test_editable_pages_for_superuser(self):
        user = get_user_model().objects.get(email="*****@*****.**")
        homepage = Page.objects.get(url_path="/home/")
        christmas_page = EventPage.objects.get(
            url_path="/home/events/christmas/")
        unpublished_event_page = EventPage.objects.get(
            url_path="/home/events/tentative-unpublished-event/")
        someone_elses_event_page = EventPage.objects.get(
            url_path="/home/events/someone-elses-event/")

        user_perms = UserPagePermissionsProxy(user)
        editable_pages = user_perms.editable_pages()
        can_edit_pages = user_perms.can_edit_pages()
        publishable_pages = user_perms.publishable_pages()
        can_publish_pages = user_perms.can_publish_pages()

        self.assertTrue(editable_pages.filter(id=homepage.id).exists())
        self.assertTrue(editable_pages.filter(id=christmas_page.id).exists())
        self.assertTrue(
            editable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertTrue(
            editable_pages.filter(id=someone_elses_event_page.id).exists())

        self.assertTrue(can_edit_pages)

        self.assertTrue(publishable_pages.filter(id=homepage.id).exists())
        self.assertTrue(
            publishable_pages.filter(id=christmas_page.id).exists())
        self.assertTrue(
            publishable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertTrue(
            publishable_pages.filter(id=someone_elses_event_page.id).exists())

        self.assertTrue(can_publish_pages)
Пример #2
0
    def test_editable_pages_for_non_editing_user(self):
        user = get_user_model().objects.get(username='******')
        homepage = Page.objects.get(url_path='/home/')
        christmas_page = EventPage.objects.get(
            url_path='/home/events/christmas/')
        unpublished_event_page = EventPage.objects.get(
            url_path='/home/events/tentative-unpublished-event/')
        someone_elses_event_page = EventPage.objects.get(
            url_path='/home/events/someone-elses-event/')

        user_perms = UserPagePermissionsProxy(user)
        editable_pages = user_perms.editable_pages()
        can_edit_pages = user_perms.can_edit_pages()
        publishable_pages = user_perms.publishable_pages()
        can_publish_pages = user_perms.can_publish_pages()

        self.assertFalse(editable_pages.filter(id=homepage.id).exists())
        self.assertFalse(editable_pages.filter(id=christmas_page.id).exists())
        self.assertFalse(
            editable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertFalse(
            editable_pages.filter(id=someone_elses_event_page.id).exists())

        self.assertFalse(can_edit_pages)

        self.assertFalse(publishable_pages.filter(id=homepage.id).exists())
        self.assertFalse(
            publishable_pages.filter(id=christmas_page.id).exists())
        self.assertFalse(
            publishable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertFalse(
            publishable_pages.filter(id=someone_elses_event_page.id).exists())

        self.assertFalse(can_publish_pages)
    def test_editable_pages_for_non_editing_user(self):
        user = get_user_model().objects.get(username='******')
        homepage = Page.objects.get(url_path='/home/')
        christmas_page = EventPage.objects.get(url_path='/home/events/christmas/')
        unpublished_event_page = EventPage.objects.get(url_path='/home/events/tentative-unpublished-event/')
        someone_elses_event_page = EventPage.objects.get(url_path='/home/events/someone-elses-event/')

        user_perms = UserPagePermissionsProxy(user)
        editable_pages = user_perms.editable_pages()
        can_edit_pages = user_perms.can_edit_pages()
        publishable_pages = user_perms.publishable_pages()
        can_publish_pages = user_perms.can_publish_pages()

        self.assertFalse(editable_pages.filter(id=homepage.id).exists())
        self.assertFalse(editable_pages.filter(id=christmas_page.id).exists())
        self.assertFalse(editable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertFalse(editable_pages.filter(id=someone_elses_event_page.id).exists())

        self.assertFalse(can_edit_pages)

        self.assertFalse(publishable_pages.filter(id=homepage.id).exists())
        self.assertFalse(publishable_pages.filter(id=christmas_page.id).exists())
        self.assertFalse(publishable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertFalse(publishable_pages.filter(id=someone_elses_event_page.id).exists())

        self.assertFalse(can_publish_pages)
Пример #4
0
    def test_editable_pages_for_user_with_edit_permission(self):
        event_moderator = get_user_model().objects.get(
            email='*****@*****.**')
        homepage = Page.objects.get(url_path='/home/')
        christmas_page = EventPage.objects.get(
            url_path='/home/events/christmas/')
        unpublished_event_page = EventPage.objects.get(
            url_path='/home/events/tentative-unpublished-event/')
        someone_elses_event_page = EventPage.objects.get(
            url_path='/home/events/someone-elses-event/')

        user_perms = UserPagePermissionsProxy(event_moderator)
        editable_pages = user_perms.editable_pages()
        can_edit_pages = user_perms.can_edit_pages()
        publishable_pages = user_perms.publishable_pages()
        can_publish_pages = user_perms.can_publish_pages()

        self.assertFalse(editable_pages.filter(id=homepage.id).exists())
        self.assertTrue(editable_pages.filter(id=christmas_page.id).exists())
        self.assertTrue(
            editable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertTrue(
            editable_pages.filter(id=someone_elses_event_page.id).exists())

        self.assertTrue(can_edit_pages)

        self.assertFalse(publishable_pages.filter(id=homepage.id).exists())
        self.assertTrue(
            publishable_pages.filter(id=christmas_page.id).exists())
        self.assertTrue(
            publishable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertTrue(
            publishable_pages.filter(id=someone_elses_event_page.id).exists())

        self.assertTrue(can_publish_pages)
Пример #5
0
 def get_pages_with_reviews_for_user(cls, user):
     """
     Return a queryset of pages which have reviews, for which the user has edit permission
     """
     user_perms = UserPagePermissionsProxy(user)
     reviewed_pages = cls.objects.values_list('page_revision__page_id',
                                              flat=True).distinct()
     return user_perms.editable_pages().filter(pk__in=reviewed_pages)
Пример #6
0
def usage(request, pk):
    workflow = get_object_or_404(Workflow, id=pk)

    perms = UserPagePermissionsProxy(request.user)

    pages = workflow.all_pages() & perms.editable_pages()
    paginator = Paginator(pages, per_page=10)
    pages = paginator.get_page(request.GET.get('p'))

    return render(request, 'wagtailadmin/workflows/usage.html', {
        'workflow': workflow,
        'used_by': pages,
    })
Пример #7
0
 def get_pages_with_reviews_for_user(cls, user):
     """
     Return a queryset of pages which have reviews, for which the user has edit permission
     """
     user_perms = UserPagePermissionsProxy(user)
     reviewed_pages = (cls.objects.order_by('-created_at').values_list(
         'page_revision__page_id', '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 (user_perms.editable_pages().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'))