Skip to content

Commit

Permalink
Merge branch 'master' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun authored Nov 7, 2024
2 parents 83c5c44 + 9ebe7a4 commit c182392
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog

Unreleased
==========
fix: Replace SortableAdminMixin by SortableAdminBase for WorkflowAdmin
fix: Restore "In Collection" button in the toolbar

2.2.1 (2024-07-02)
==================
Expand Down
2 changes: 1 addition & 1 deletion djangocms_moderation/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _add_moderation_buttons(self):
if not helpers.is_registered_for_moderation(self.toolbar.obj):
return

if self._is_versioned() and self.toolbar.edit_mode_active:
if self._is_versioned() and (self.toolbar.edit_mode_active or self.toolbar.preview_mode_active):
moderation_request = helpers.get_active_moderation_request(self.toolbar.obj)
if moderation_request:
title, url = helpers.get_moderation_button_title_and_url(
Expand Down
14 changes: 14 additions & 0 deletions djangocms_moderation/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ def inner(self, obj, request):
return inner


def _check_registered_for_moderation(message):
"""
Fail check if object is registered for moderation
"""
def inner(version, user):
if is_registered_for_moderation(version.content):
raise ConditionFailed(message)

return inner


admin.VersionAdmin._get_publish_link = _get_publish_link(
admin.VersionAdmin._get_publish_link
)
Expand Down Expand Up @@ -152,5 +163,8 @@ def inner(self, obj, request):
_("Cannot edit a version in an active moderation collection")
)
]
models.Version.check_publish += [
_check_registered_for_moderation(_("Content cannot be published directly. Use the moderation process."))
]

fields.PlaceholderRelationField.default_checks += [_is_placeholder_review_unlocked]
8 changes: 8 additions & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,11 @@ def test_workflow_admin_renders_correctly(self):
# django-admin-sortable2 injected its inputs
self.assertContains(result, '<script src="/static/adminsortable2/js/adminsortable2.min.js"></script>')
self.assertContains(result, '<input type="hidden" name="steps-0-id"')

def test_moderated_models_cannot_be_published(self):
from djangocms_versioning.exceptions import ConditionFailed

version = self.mr1.version

with self.assertRaises(ConditionFailed):
version.check_publish(self.get_superuser())

0 comments on commit c182392

Please sign in to comment.