diff --git a/plone/app/discussion/configure.zcml b/plone/app/discussion/configure.zcml index 1a2e663b..4a19dafd 100644 --- a/plone/app/discussion/configure.zcml +++ b/plone/app/discussion/configure.zcml @@ -7,50 +7,59 @@ i18n_domain="plone" > - + - - - - - + + + + + - - - - - - + + + + + + - + - + - + - + - + - - - - + + + + + - + - + - + - + - + + + + + + diff --git a/plone/app/discussion/profiles/uninstall/browserlayer.xml b/plone/app/discussion/profiles/uninstall/browserlayer.xml new file mode 100644 index 00000000..078a4cbb --- /dev/null +++ b/plone/app/discussion/profiles/uninstall/browserlayer.xml @@ -0,0 +1,6 @@ + + + + diff --git a/plone/app/discussion/profiles/uninstall/catalog.xml b/plone/app/discussion/profiles/uninstall/catalog.xml new file mode 100644 index 00000000..fe787701 --- /dev/null +++ b/plone/app/discussion/profiles/uninstall/catalog.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/plone/app/discussion/profiles/uninstall/controlpanel.xml b/plone/app/discussion/profiles/uninstall/controlpanel.xml new file mode 100644 index 00000000..2506618d --- /dev/null +++ b/plone/app/discussion/profiles/uninstall/controlpanel.xml @@ -0,0 +1,14 @@ + + + + + + diff --git a/plone/app/discussion/profiles/uninstall/registry.xml b/plone/app/discussion/profiles/uninstall/registry.xml new file mode 100644 index 00000000..234fa24d --- /dev/null +++ b/plone/app/discussion/profiles/uninstall/registry.xml @@ -0,0 +1,6 @@ + + + + diff --git a/plone/app/discussion/setuphandlers.py b/plone/app/discussion/setuphandlers.py index ed3e575d..e16eb4c6 100644 --- a/plone/app/discussion/setuphandlers.py +++ b/plone/app/discussion/setuphandlers.py @@ -12,15 +12,35 @@ "Link", ] +BEHAVIOR = "plone.allowdiscussion" + def add_discussion_behavior_to_default_types(context): """Add the discussion behavior to all default types, if they exist.""" types_tool = getToolByName(context, "portal_types") for type_name in DEFAULT_TYPES: - if type_name in types_tool.objectIds(): - types_tool[type_name].behaviors += ("plone.allowdiscussion",) + if type_name in types_tool.objectIds() and BEHAVIOR not in types_tool[type_name].behaviors: + types_tool[type_name].behaviors += (BEHAVIOR,) + + +def remove_discussion_behavior_to_default_types(context): + """Remove the discussion behavior from all default types, if they exist.""" + types_tool = getToolByName(context, "portal_types") + for type_name in types_tool.objectIds(): + fti = types_tool[type_name] + if getattr(fti, "behaviors", None) is None: + continue + if BEHAVIOR in fti.behaviors: + behaviors = list(fti.behaviors) + behaviors.remove(BEHAVIOR) + fti.behaviors = tuple(behaviors) def post_install(context): """Post install script""" add_discussion_behavior_to_default_types(context) + + +def post_uninstall(context): + """Post uninstall script""" + remove_discussion_behavior_to_default_types(context)