Example #1
0
    def test_editable_pages_for_non_editing_user(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.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)
Example #2
0
    def is_active(self):
        # Hide the panel if the user can't edit or publish pages
        user_perms = UserPagePermissionsProxy(self.request.user)
        if not user_perms.can_edit_pages() and not user_perms.can_publish_pages():
            return False

        # Hide the panel if there are no notification preferences
        return self.get_form().fields
Example #3
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     user_perms = UserPagePermissionsProxy(self.instance.user)
     if not user_perms.can_publish_pages():
         del self.fields["submitted_notifications"]
     if not user_perms.can_edit_pages():
         del self.fields["approved_notifications"]
         del self.fields["rejected_notifications"]
         del self.fields["updated_comments_notifications"]