Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update check framework to not allow publishing for moderated models #282

Merged
merged 7 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())
Loading