2011-04-08 22:20:34 +02:00
|
|
|
from plone.app.discussion.interfaces import IDiscussionSettings
|
2015-05-03 08:16:39 +02:00
|
|
|
from plone.registry.interfaces import IRegistry
|
2017-01-10 18:09:01 +01:00
|
|
|
from Products.CMFCore.utils import getToolByName
|
2015-05-03 08:16:39 +02:00
|
|
|
from zope.component import getUtility
|
|
|
|
|
2017-01-10 18:09:01 +01:00
|
|
|
import logging
|
|
|
|
|
2011-04-08 22:20:34 +02:00
|
|
|
|
2022-05-01 23:14:09 +02:00
|
|
|
default_profile = "profile-plone.app.discussion:default"
|
|
|
|
logger = logging.getLogger("plone.app.discussion")
|
2014-03-03 16:15:12 +01:00
|
|
|
|
2011-04-08 22:20:34 +02:00
|
|
|
|
|
|
|
def update_registry(context):
|
|
|
|
registry = getUtility(IRegistry)
|
|
|
|
registry.registerInterface(IDiscussionSettings)
|
2014-03-03 16:15:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def update_rolemap(context):
|
2022-05-01 23:14:09 +02:00
|
|
|
context.runImportStepFromProfile(default_profile, "rolemap")
|
2017-01-10 18:09:01 +01:00
|
|
|
|
|
|
|
|
2019-12-05 21:55:23 +01:00
|
|
|
def upgrade_comment_workflows_retain_current_workflow(context):
|
2017-01-10 18:09:01 +01:00
|
|
|
# If the current comment workflow is the one_state_workflow, running our
|
|
|
|
# import step will change it to comment_one_state_workflow. This is good.
|
|
|
|
# If it was anything else, we should restore this. So get the original
|
|
|
|
# chain.
|
2022-05-01 23:14:09 +02:00
|
|
|
portal_type = "Discussion Item"
|
|
|
|
wf_tool = getToolByName(context, "portal_workflow")
|
2017-01-10 18:09:01 +01:00
|
|
|
orig_chain = list(wf_tool.getChainFor(portal_type))
|
|
|
|
|
|
|
|
# Run the workflow step. This sets the chain to
|
|
|
|
# comment_one_state_workflow.
|
2022-05-01 23:14:09 +02:00
|
|
|
context.runImportStepFromProfile(default_profile, "workflow")
|
2017-01-10 18:09:01 +01:00
|
|
|
|
|
|
|
# Restore original workflow chain if needed.
|
2022-05-01 23:14:09 +02:00
|
|
|
old_workflow = "one_state_workflow"
|
2017-01-10 18:09:01 +01:00
|
|
|
if old_workflow not in orig_chain:
|
|
|
|
# Restore the chain. Probably comment_review_workflow.
|
|
|
|
wf_tool.setChainForPortalTypes([portal_type], orig_chain)
|
|
|
|
elif len(orig_chain) > 1:
|
|
|
|
# This is strange, but I guess it could happen.
|
|
|
|
if old_workflow in orig_chain:
|
|
|
|
# Replace with new one.
|
|
|
|
idx = orig_chain.index(old_workflow)
|
2022-05-01 23:14:09 +02:00
|
|
|
orig_chain[idx] = "comment_one_state_workflow"
|
2017-01-10 18:09:01 +01:00
|
|
|
# Restore the chain.
|
|
|
|
wf_tool.setChainForPortalTypes([portal_type], orig_chain)
|
|
|
|
|
2019-12-05 21:55:23 +01:00
|
|
|
|
|
|
|
def upgrade_comment_workflows_apply_rolemapping(context):
|
2017-01-10 18:09:01 +01:00
|
|
|
# Now go over the comments, update their role mappings, and reindex the
|
|
|
|
# allowedRolesAndUsers index.
|
2022-05-01 23:14:09 +02:00
|
|
|
portal_type = "Discussion Item"
|
|
|
|
catalog = getToolByName(context, "portal_catalog")
|
|
|
|
wf_tool = getToolByName(context, "portal_workflow")
|
2019-12-05 21:55:23 +01:00
|
|
|
new_chain = list(wf_tool.getChainFor(portal_type))
|
|
|
|
workflows = [wf_tool.getWorkflowById(wf_id) for wf_id in new_chain]
|
2017-01-10 18:09:01 +01:00
|
|
|
for brain in catalog.unrestrictedSearchResults(portal_type=portal_type):
|
|
|
|
try:
|
|
|
|
comment = brain.getObject()
|
|
|
|
for wf in workflows:
|
|
|
|
wf.updateRoleMappingsFor(comment)
|
|
|
|
comment.reindexObjectSecurity()
|
|
|
|
except (AttributeError, KeyError):
|
2022-05-01 23:14:41 +02:00
|
|
|
logger.info(f"Could not reindex comment {brain.getURL()}")
|
2019-06-27 19:59:20 +02:00
|
|
|
|
|
|
|
|
2019-12-05 21:55:23 +01:00
|
|
|
def upgrade_comment_workflows(context):
|
|
|
|
upgrade_comment_workflows_retain_current_workflow(context)
|
|
|
|
upgrade_comment_workflows_apply_rolemapping(context)
|
|
|
|
|
|
|
|
|
2019-06-27 19:59:20 +02:00
|
|
|
def add_js_to_plone_legacy(context):
|
2022-05-01 23:14:09 +02:00
|
|
|
context.runImportStepFromProfile(default_profile, "plone.app.registry")
|
2020-01-14 15:59:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
def extend_review_workflow(context):
|
|
|
|
"""Apply changes made to review workflow."""
|
|
|
|
upgrade_comment_workflows_retain_current_workflow(context)
|