Skip to content

Commit

Permalink
fix: Update check framework to not allow publishing for moderated mod…
Browse files Browse the repository at this point in the history
…els (#282)

* Update `check_publish

* Remove patch of get_publish_link

* Patch _get_publish_link and check_publish

* Add test
  • Loading branch information
fsbraun authored Nov 6, 2024
1 parent 6589f66 commit 9ebe7a4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
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 9ebe7a4

Please sign in to comment.