Ejemplo n.º 1
0
 def inner(version, user):
     try:
         # if there's a prepoluated field on version object
         # representing a draft lock, use it
         cached_draft_version_user_id = getattr(version,
                                                "_draft_version_user_id")
         if cached_draft_version_user_id and cached_draft_version_user_id != user.pk:
             raise ConditionFailed(
                 message.format(
                     user="******".format(cached_draft_version_user_id)))
     except AttributeError:
         draft_version = get_latest_draft_version(version)
         lock = version_is_locked(draft_version)
         if lock and lock.created_by != user:
             raise ConditionFailed(message.format(user=lock.created_by))
Ejemplo n.º 2
0
    def test_menuitem_move_node_does_modify_check_on_version(
        self, mocked_check, mocked_messages
    ):
        mocked_check.side_effect = ConditionFailed(
            "Go look at some cat pictures instead"
        )
        menu_content = factories.MenuContentWithVersionFactory(version__created_by=self.user)
        child = factories.ChildMenuItemFactory(parent=menu_content.root)
        child_of_child = factories.ChildMenuItemFactory(parent=child)
        move_url = reverse(
            "admin:djangocms_navigation_menuitem_move_node", args=(menu_content.id,)
        )
        data = {
            "node_id": child_of_child.pk,
            "sibling_id": menu_content.root.pk,
            "as_child": 1,
        }

        response = self.client.post(move_url, data=data)

        # 400 response with error message that came from version.check_modify
        self.assertEqual(response.status_code, 400)
        self.assertEqual(mocked_messages.call_count, 1)
        self.assertEqual(
            mocked_messages.call_args[0][1], "Go look at some cat pictures instead"
        )
        self.assertEqual(b"Go look at some cat pictures instead", response.content)
        mocked_check.assert_called_once_with(self.get_superuser())
Ejemplo n.º 3
0
    def test_menuitem_add_view_does_modify_check_on_version(
        self, mocked_check, mocked_messages
    ):
        mocked_check.side_effect = ConditionFailed(
            "Go look at some cat pictures instead"
        )
        menu_content = factories.MenuContentWithVersionFactory()
        add_url = reverse(
            "admin:djangocms_navigation_menuitem_add", args=(menu_content.id,)
        )
        content_type = ContentType.objects.get(app_label="cms", model="page")
        page = factories.PageContentFactory().page
        data = {
            "title": "My new Title",
            "content_type": content_type.pk,
            "object_id": page.pk,
            "_ref_node_id": menu_content.root.id,
            "numchild": 1,
            "link_target": "_blank",
            "_position": "first-child",
        }

        response = self.client.post(add_url, data)

        # Redirect happened, error message displayed and check modify used
        self.assertRedirectsToVersionList(response, menu_content)
        self.assertDjangoErrorMessage(
            "Go look at some cat pictures instead", mocked_messages
        )
        mocked_check.assert_called_once_with(self.get_superuser())
Ejemplo n.º 4
0
def is_file_content_valid_for_revert(version, user):
    content = version.content
    if isinstance(content, filer.models.File) and check_file_exists_in_folder(content):
        raise ConditionFailed(
            _('File with name "{}" already exists in "{}" folder').format(
                content.label, content.folder,
            )
        )
Ejemplo n.º 5
0
 def inner(version, user):
     """
     Checks if version is a draft and in review
     """
     draft_version = get_latest_draft_version(version)
     if (draft_version
             and is_registered_for_moderation(draft_version.content)
             and is_obj_review_locked(draft_version.content, user)):
         raise ConditionFailed(message)
Ejemplo n.º 6
0
def is_file_content_valid_for_discard(version, user):
    content = version.content
    if isinstance(content, filer.models.File):
        try:
            latest_version = Version.objects.filter_by_grouper(content.grouper).exclude(pk=version.pk).latest('created')
        except Version.DoesNotExist:
            return
        if check_file_exists_in_folder(latest_version.content):
            raise ConditionFailed(
                _('File with name "{}" already exists in "{}" folder').format(
                    latest_version.content.label, latest_version.content.folder,
                )
            )
Ejemplo n.º 7
0
    def test_menuitem_changelist_does_modify_check_on_version(
            self, mocked_check, mocked_messages):
        mocked_check.side_effect = ConditionFailed(
            "Go look at some cat pictures instead")
        menu_content = factories.MenuContentWithVersionFactory()
        list_url = reverse("admin:djangocms_navigation_menuitem_list",
                           args=(menu_content.id, ))

        response = self.client.get(list_url)

        # Redirect happened, error message displayed and check modify used
        self.assertRedirectsToVersionList(response, menu_content.menu)
        self.assertDjangoErrorMessage("Go look at some cat pictures instead",
                                      mocked_messages)
        mocked_check.assert_called_once_with(self.get_superuser())
Ejemplo n.º 8
0
    def test_menuitem_change_view_does_modify_check_on_version(
            self, mocked_check, mocked_messages):
        mocked_check.side_effect = ConditionFailed(
            "Go look at some cat pictures instead")
        menu_content = factories.MenuContentWithVersionFactory()
        item = factories.ChildMenuItemFactory(parent=menu_content.root)
        change_url = reverse(
            "admin:djangocms_navigation_menuitem_change",
            kwargs={
                "menu_content_id": menu_content.pk,
                "object_id": item.pk
            },
        )

        response = self.client.get(change_url)

        # Redirect happened, error message displayed and check modify used
        self.assertRedirectsToVersionList(response, menu_content.menu)
        self.assertDjangoErrorMessage("Go look at some cat pictures instead",
                                      mocked_messages)
        mocked_check.assert_called_once_with(self.get_superuser())
Ejemplo n.º 9
0
 def inner(version, user):
     if is_registered_for_moderation(
             version.content) and is_obj_review_locked(
                 version.content, user):
         raise ConditionFailed(message)
Ejemplo n.º 10
0
 def inner(version, user):
     draft_version = get_latest_draft_version(version)
     lock = version_is_locked(draft_version)
     if lock and lock.created_by != user:
         raise ConditionFailed(message.format(user=lock.created_by))
Ejemplo n.º 11
0
 def inner(version, user):
     lock = version_is_locked(version)
     if lock and lock.created_by != user:
         raise ConditionFailed(message.format(user=lock.created_by))