def test_version_lock_state_locked(self):
        """
        A published version does not have an entry in the locked column in the admin
        """
        published_version = factories.PollVersionFactory(state=PUBLISHED)

        self.assertEqual("", self.hijacked_admin.locked(published_version))
예제 #2
0
    def test_unlock_link_only_present_for_draft_versions(self):
        draft_version = factories.PollVersionFactory(
            created_by=self.user_author)
        published_version = Version.objects.create(
            content=factories.PollContentFactory(
                poll=draft_version.content.poll),
            created_by=factories.UserFactory(),
            state=constants.PUBLISHED)
        draft_unlock_url = self.get_admin_url(
            self.versionable.version_model_proxy, 'unlock', draft_version.pk)
        draft_unlock_control = render_to_string(
            'djangocms_version_locking/admin/unlock_icon.html',
            {'unlock_url': draft_unlock_url})
        published_unlock_url = self.get_admin_url(
            self.versionable.version_model_proxy, 'unlock',
            published_version.pk)
        published_unlock_control = render_to_string(
            'djangocms_version_locking/admin/unlock_icon.html',
            {'unlock_url': published_unlock_url})
        changelist_url = version_list_url(draft_version.content)

        with self.login_user_context(self.superuser):
            response = self.client.post(changelist_url)

        # The draft version unlock control exists
        self.assertContains(response, draft_unlock_control, html=True)
        # The published version exists
        self.assertNotContains(response, published_unlock_control, html=True)
    def test_version_is_locked_for_draft(self):
        """
        A version lock is present when a content version is in a draft state
        """
        draft_version = factories.PollVersionFactory(state=constants.DRAFT)

        self.assertTrue(hasattr(draft_version, 'versionlock'))
    def test_version_lock_state_unlocked(self):
        """
        A draft version does have an entry in the locked column in the  and is not empty
        """
        draft_version = factories.PollVersionFactory(state=DRAFT)

        self.assertNotEqual("", self.hijacked_admin.locked(draft_version))
    def test_version_is_unlocked_for_publishing(self):
        """
        A version lock is not present when a content version is in a published or unpublished state
        """
        poll_version = factories.PollVersionFactory(state=constants.DRAFT)
        publish_url = self.get_admin_url(self.versionable.version_model_proxy, 'publish', poll_version.pk)
        unpublish_url = self.get_admin_url(self.versionable.version_model_proxy, 'unpublish', poll_version.pk)
        user = self.get_staff_user_with_no_permissions()

        with self.login_user_context(user):
            self.client.post(publish_url)

        updated_poll_version = Version.objects.get(pk=poll_version.pk)

        # The state is now PUBLISHED
        self.assertEqual(updated_poll_version.state, constants.PUBLISHED)
        # Version lock does not exist
        self.assertFalse(hasattr(updated_poll_version, 'versionlock'))

        with self.login_user_context(user):
            self.client.post(unpublish_url)

        updated_poll_version = Version.objects.get(pk=poll_version.pk)

        # The state is now UNPUBLISHED
        self.assertEqual(updated_poll_version.state, constants.UNPUBLISHED)
        # Version lock does not exist
        self.assertFalse(hasattr(updated_poll_version, 'versionlock'))
    def test_draft_version_copy_creates_draft_lock(self):
        """
        A version lock is created for a new draft version copied from a draft version
        """
        user = factories.UserFactory()
        draft_version = factories.PollVersionFactory(state=constants.DRAFT)
        new_version = draft_version.copy(user)

        self.assertTrue(hasattr(new_version, 'versionlock'))
    def test_published_version_copy_creates_draft_lock(self):
        """
        A version lock is created for a published version copied from a draft version
        """
        user = factories.UserFactory()
        published_version = factories.PollVersionFactory(state=constants.PUBLISHED)
        new_version = published_version.copy(user)

        self.assertTrue(hasattr(new_version, 'versionlock'))
예제 #8
0
    def test_unlock_view_redirects_404_when_not_draft(self):
        poll_version = factories.PollVersionFactory(state=constants.PUBLISHED,
                                                    created_by=self.superuser)
        unlock_url = self.get_admin_url(self.versionable.version_model_proxy,
                                        'unlock', poll_version.pk)

        # 404 when not in draft
        with self.login_user_context(self.superuser):
            response = self.client.post(unlock_url, follow=True)

        self.assertEqual(response.status_code, 404)
예제 #9
0
    def test_user_has_change_permission(self):
        """
        Test that the user who created the version has permission to change it
        """
        author = self.get_superuser()
        content = factories.PollVersionFactory(state=DRAFT, created_by=author)
        url = self.get_admin_url(PollContent, 'change', content.pk)

        with self.login_user_context(author):
            response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
예제 #10
0
    def test_version_locking_css_media_loaded(self):
        """
        The verison locking css media is loaded on the page
        """
        poll_version = factories.PollVersionFactory(created_by=self.superuser)
        changelist_url = version_list_url(poll_version.content)
        css_file = "djangocms_version_locking/css/version-locking.css"

        with self.login_user_context(self.superuser):
            response = self.client.post(changelist_url)

        self.assertContains(response, css_file)
    def test_version_copy_adds_correct_locked_user(self):
        """
        A copied version creates a lock for the user that copied the version.
        The users should not be the same.
        """
        original_user = factories.UserFactory()
        original_version = factories.PollVersionFactory(created_by=original_user)
        copy_user = factories.UserFactory()
        copied_version = original_version.copy(copy_user)

        self.assertNotEqual(original_user, copy_user)
        self.assertEqual(original_version.versionlock.created_by, original_user)
        self.assertEqual(copied_version.versionlock.created_by, copy_user)
    def test_user_has_change_permission(self):
        """
        The user who created the version has permission to change it
        """
        content = factories.PollVersionFactory(
            state=DRAFT, created_by=self.user_has_change_perms)
        url = self.get_admin_url(self.versionable.version_model_proxy,
                                 'change', content.pk)

        with self.login_user_context(self.user_has_change_perms):
            response = self.client.get(url)

        self.assertEqual(response.status_code, 200)
예제 #13
0
    def test_edit_action_link_disabled_state(self):
        """
        The edit action is disabled for a different user to the locked user
        """
        version = factories.PollVersionFactory(created_by=self.user_author)
        author_request = RequestFactory()
        author_request.user = self.user_author
        otheruser_request = RequestFactory()
        otheruser_request.user = self.superuser
        actual_disabled_state = self.version_admin._get_edit_link(
            version, otheruser_request)

        self.assertIn("inactive", actual_disabled_state)
    def test_unlock_link_present_for_user_with_privileges(self):
        poll_version = factories.PollVersionFactory(
            state=constants.DRAFT, created_by=self.user_author)
        changelist_url = version_list_url(poll_version.content)
        unlock_url = self.get_admin_url(self.versionable.version_model_proxy,
                                        'unlock', poll_version.pk)
        unlock_control = render_to_string(
            'djangocms_version_locking/admin/unlock_icon.html',
            {'unlock_url': unlock_url})

        with self.login_user_context(self.user_has_unlock_perms):
            response = self.client.post(changelist_url)
        self.assertContains(response, unlock_control, html=True)
예제 #15
0
    def test_edit_action_link_enabled_state(self):
        """
        The edit action is active
        """
        version = factories.PollVersionFactory(created_by=self.user_author)
        author_request = RequestFactory()
        author_request.user = self.user_author
        otheruser_request = RequestFactory()
        otheruser_request.user = self.superuser

        actual_enabled_state = self.version_admin._get_edit_link(
            version, author_request)

        self.assertNotIn("inactive", actual_enabled_state)
    def test_user_does_not_have_change_permission(self):
        """
        A different user from the user who created
        the version does not have permission to change it
        """
        author = factories.UserFactory(is_staff=True)
        content = factories.PollVersionFactory(state=DRAFT, created_by=author)
        url = self.get_admin_url(self.versionable.version_model_proxy,
                                 'change', content.pk)

        with self.login_user_context(self.user_has_change_perms):
            response = self.client.get(url)

        self.assertEqual(response.status_code, 403)
예제 #17
0
    def test_user_does_not_have_change_permission(self):
        """
        Test that a different user from the  user who created
        the version does not have permission to change it
        """
        author = factories.UserFactory()
        editor = self.get_superuser()
        content = factories.PollVersionFactory(state=DRAFT, created_by=author)
        url = self.get_admin_url(PollContent, 'change', content.pk)

        with self.login_user_context(editor):
            response = self.client.get(url)

        self.assertEqual(response.status_code, 403)
예제 #18
0
    def test_unlock_view_possible_for_user_with_permissions(self):
        poll_version = factories.PollVersionFactory(
            state=constants.DRAFT, created_by=self.user_author)
        unlock_url = self.get_admin_url(self.versionable.version_model_proxy,
                                        'unlock', poll_version.pk)

        with self.login_user_context(self.user_has_unlock_perms):
            response = self.client.post(unlock_url, follow=True)

        self.assertEqual(response.status_code, 200)

        # Fetch the latest state of this version
        updated_poll_version = Version.objects.get(pk=poll_version.pk)

        # The version is not locked
        self.assertFalse(hasattr(updated_poll_version, 'versionlock'))
    def test_version_unlock_keep_side_frame(self):
        """
        When clicking on an versionables enabled unlock icon, the sideframe is kept open
        """
        version = factories.PollVersionFactory(created_by=self.user_author)
        author_request = RequestFactory()
        author_request.user = self.user_author
        otheruser_request = RequestFactory()
        otheruser_request.user = self.superuser

        actual_enabled_state = self.version_admin._get_unlock_link(
            version, otheruser_request)

        # The url link should keep the sideframe open
        self.assertIn("js-versioning-keep-sideframe", actual_enabled_state)
        self.assertNotIn("js-versioning-close-sideframe", actual_enabled_state)
    def test_archive_link_only_present_for_author_for_draft(self):
        draft_version = factories.PollVersionFactory(
            created_by=self.user_author)

        with self.login_user_context(self.superuser):
            request = RequestFactory()
            request.user = self.superuser
            archive_url = self.version_admin._get_archive_link(
                draft_version, request)
            self.assertIn("inactive", archive_url)

        with self.login_user_context(self.user_author):
            request = RequestFactory()
            request.user = self.user_author
            archive_url = self.version_admin._get_archive_link(
                draft_version, request)
            self.assertNotIn("inactive", archive_url)
예제 #21
0
    def test_unlock_link_not_present_for_author(self):
        # FIXME: May be redundant now as this requirement was probably removed at a later date due
        #  to the fact that an author may be asked to unlock their version for someone else to use!
        author = self.get_superuser()
        poll_version = factories.PollVersionFactory(state=constants.DRAFT,
                                                    created_by=author)
        changelist_url = version_list_url(poll_version.content)
        unlock_url = self.get_admin_url(self.versionable.version_model_proxy,
                                        'unlock', poll_version.pk)
        unlock_control = render_to_string(
            'djangocms_version_locking/admin/unlock_icon.html',
            {'unlock_url': unlock_url})

        with self.login_user_context(author):
            response = self.client.get(changelist_url)

        self.assertNotContains(response, unlock_control, html=True)
    def test_unpublish_link_shoulnt_present_for_author_for_draft(self):
        draft_version = factories.PollVersionFactory(
            created_by=self.user_author)

        with self.login_user_context(self.superuser):
            request = RequestFactory()
            request.user = self.superuser
            unpublish_url = self.version_admin._get_unpublish_link(
                draft_version, request)
            self.assertIn("", unpublish_url)

        with self.login_user_context(self.user_author):
            request = RequestFactory()
            request.user = self.user_author
            unpublish_url = self.version_admin._get_unpublish_link(
                draft_version, request)
            self.assertIn("", unpublish_url)
    def test_discard_link_only_present_for_author_for_draft(self):
        draft_version = factories.PollVersionFactory(
            created_by=self.user_author, state=constants.DRAFT)

        with self.login_user_context(self.superuser):
            request = RequestFactory()
            request.user = self.superuser
            discard_url = self.version_admin._get_discard_link(
                draft_version, request)
            self.assertIn("inactive", discard_url)

        with self.login_user_context(self.user_author):
            request = RequestFactory()
            request.user = self.user_author
            discard_url = self.version_admin._get_discard_link(
                draft_version, request)
            self.assertNotIn("inactive", discard_url)
예제 #24
0
    def test_unlock_and_new_user_edit_creates_version_lock(self):
        """
        When a version is unlocked a different user (or the same) can then visit the edit link and take
        ownership of the version, this creates a version lock for the editing user
        """
        draft_version = factories.PollVersionFactory(
            created_by=self.user_author)
        draft_unlock_url = self.get_admin_url(
            self.versionable.version_model_proxy, 'unlock', draft_version.pk)

        # The version is owned by the author
        self.assertEqual(draft_version.created_by, self.user_author)
        # The version lock exists and is owned by the author
        self.assertEqual(draft_version.versionlock.created_by,
                         self.user_author)

        # Unlock the version with a different user with unlock permissions
        with self.login_user_context(self.user_has_unlock_perms):
            self.client.post(draft_unlock_url, follow=True)

        updated_draft_version = Version.objects.get(pk=draft_version.pk)
        updated_draft_edit_url = self.get_admin_url(
            self.versionable.version_model_proxy, 'edit_redirect',
            updated_draft_version.pk)

        # The version is still owned by the author
        self.assertTrue(updated_draft_version.created_by, self.user_author)
        # The version lock does not exist
        self.assertFalse(hasattr(updated_draft_version, 'versionlock'))

        # Visit the edit page with a user without unlock permissions
        with self.login_user_context(self.user_has_no_unlock_perms):
            self.client.post(updated_draft_edit_url)

        updated_draft_version = Version.objects.get(pk=draft_version.pk)

        # The version is now owned by the user with no permissions
        self.assertTrue(updated_draft_version.created_by,
                        self.user_has_no_unlock_perms)
        # The version lock exists and is now owned by the user with no permissions
        self.assertEqual(updated_draft_version.versionlock.created_by,
                         self.user_has_no_unlock_perms)
    def test_version_is_unlocked_for_archived(self):
        """
        A version lock is not present when a content version is in an archived state
        """
        poll_version = factories.PollVersionFactory(state=constants.DRAFT)
        archive_url = self.get_admin_url(self.versionable.version_model_proxy, 'archive', poll_version.pk)
        version_lock = version_is_locked(poll_version)
        user = self.get_superuser()
        version_lock.created_by = user
        version_lock.save()

        with self.login_user_context(user):
            self.client.post(archive_url)

        updated_poll_version = Version.objects.get(pk=poll_version.pk)

        # The state is now ARCHIVED
        self.assertEqual(updated_poll_version.state, constants.ARCHIVED)
        # Version lock does not exist
        self.assertFalse(hasattr(updated_poll_version, 'versionlock'))
    def test_archive_link_not_present_for_published_version(self):
        draft_version = factories.PollVersionFactory(
            created_by=self.user_author)
        published_version = Version.objects.create(
            content=factories.PollContentFactory(
                poll=draft_version.content.poll),
            created_by=factories.UserFactory(),
            state=constants.PUBLISHED)

        with self.login_user_context(self.user_author):
            request = RequestFactory()
            request.user = self.user_author
            discard_url = self.version_admin._get_discard_link(
                published_version, request)
            self.assertEqual("", discard_url)

        with self.login_user_context(self.user_author):
            request = RequestFactory()
            request.user = self.user_author
            discard_url = self.version_admin._get_discard_link(
                published_version, request)
            self.assertEqual("", discard_url)