Пример #1
0
    def test_lock_page_for_editor(self):
        user = get_user_model().objects.get(email="*****@*****.**")
        christmas_page = EventPage.objects.get(
            url_path="/home/events/christmas/")

        perms = UserPagePermissionsProxy(user).for_page(christmas_page)

        self.assertFalse(perms.can_lock())
        self.assertFalse(perms.can_unlock())
Пример #2
0
    def test_lock_page_for_moderator_without_unlock_permission(self):
        user = get_user_model().objects.get(email="*****@*****.**")
        christmas_page = EventPage.objects.get(
            url_path="/home/events/christmas/")

        GroupPagePermission.objects.filter(group__name="Event moderators",
                                           permission_type="unlock").delete()

        perms = UserPagePermissionsProxy(user).for_page(christmas_page)

        self.assertTrue(perms.can_lock())
        self.assertFalse(perms.can_unlock())
Пример #3
0
    def test_lock_page_for_superuser(self):
        user = get_user_model().objects.get(email="*****@*****.**")
        christmas_page = EventPage.objects.get(
            url_path="/home/events/christmas/")
        locked_page = Page.objects.get(url_path="/home/my-locked-page/")

        perms = UserPagePermissionsProxy(user).for_page(christmas_page)
        locked_perms = UserPagePermissionsProxy(user).for_page(locked_page)

        self.assertTrue(perms.can_lock())
        self.assertFalse(
            locked_perms.can_unpublish())  # locked pages can't be unpublished
        self.assertTrue(perms.can_unlock())
Пример #4
0
    def test_page_lock_in_workflow(self):
        workflow, task = self.create_workflow_and_task()
        editor = get_user_model().objects.get(email="*****@*****.**")
        moderator = get_user_model().objects.get(
            email="*****@*****.**")
        christmas_page = EventPage.objects.get(
            url_path="/home/events/christmas/")
        christmas_page.save_revision()
        workflow.start(christmas_page, editor)

        moderator_perms = UserPagePermissionsProxy(moderator).for_page(
            christmas_page)

        # the moderator is in the group assigned to moderate the task, so they can lock the page, but can't unlock it
        # unless they're the locker
        self.assertTrue(moderator_perms.can_lock())
        self.assertFalse(moderator_perms.can_unlock())

        editor_perms = UserPagePermissionsProxy(editor).for_page(
            christmas_page)

        # the editor is not in the group assigned to moderate the task, so they can't lock or unlock the page
        self.assertFalse(editor_perms.can_lock())
        self.assertFalse(editor_perms.can_unlock())
Пример #5
0
    def test_lock_page_for_editor_with_lock_permission(self):
        user = get_user_model().objects.get(email="*****@*****.**")
        christmas_page = EventPage.objects.get(
            url_path="/home/events/christmas/")

        GroupPagePermission.objects.create(
            group=Group.objects.get(name="Event editors"),
            page=christmas_page,
            permission_type="lock",
        )

        perms = UserPagePermissionsProxy(user).for_page(christmas_page)

        self.assertTrue(perms.can_lock())

        # Still shouldn't have unlock permission
        self.assertFalse(perms.can_unlock())
Пример #6
0
    def test_lock_page_for_moderator_whole_locked_page_without_unlock_permission(
            self):
        user = get_user_model().objects.get(email="*****@*****.**")
        christmas_page = EventPage.objects.get(
            url_path="/home/events/christmas/")

        # Lock the page
        christmas_page.locked = True
        christmas_page.locked_by = user
        christmas_page.locked_at = timezone.now()
        christmas_page.save()

        GroupPagePermission.objects.filter(group__name="Event moderators",
                                           permission_type="unlock").delete()

        perms = UserPagePermissionsProxy(user).for_page(christmas_page)

        # Unlike in the previous test, the user can unlock this page as it was them who locked
        self.assertTrue(perms.can_lock())
        self.assertTrue(perms.can_unlock())