From 7a3af1a90524a6269f305b5ab7ea173146e9acef Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Fri, 30 Aug 2024 12:11:08 +0200 Subject: [PATCH] Patch _get_publish_link and check_publish --- djangocms_moderation/monkeypatch.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/djangocms_moderation/monkeypatch.py b/djangocms_moderation/monkeypatch.py index 977ff29c..e24a2a33 100644 --- a/djangocms_moderation/monkeypatch.py +++ b/djangocms_moderation/monkeypatch.py @@ -106,17 +106,35 @@ def inner(version, user): return inner +def _get_publish_link(func): + """ + Monkey patch VersionAdmin's _get_publish_link to remove publish link, + if obj.content is registered with moderation + """ + + def inner(self, obj, request): + input(f"{obj=}, {is_registered_for_moderation(obj.content)=}") + if is_registered_for_moderation(obj.content): + return "" + return func(self, obj, request) + + return inner + + def _check_registered_for_moderation(message): """ Fail check if object is registered for moderation """ def inner(version, user): - if not is_registered_for_moderation(version.content): + 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 +) admin.VersionAdmin.get_state_actions = get_state_actions( admin.VersionAdmin.get_state_actions )