diff --git a/src/plone/app/content/browser/actions.py b/src/plone/app/content/browser/actions.py index 6f16e53..9e3d8fa 100644 --- a/src/plone/app/content/browser/actions.py +++ b/src/plone/app/content/browser/actions.py @@ -2,6 +2,7 @@ from Acquisition import aq_inner from Acquisition import aq_parent from OFS.CopySupport import CopyError +from plone.app.content.utils import get_deleted_success_message from plone.base import PloneMessageFactory as _ from plone.base.utils import get_user_friendly_types from plone.base.utils import safe_text @@ -85,9 +86,10 @@ def handle_delete(self, action): # unlock object as it is locked by current user ILockable(self.context).unlock() parent.manage_delObjects(self.context.getId()) - IStatusMessage(self.request).add( - _("${title} has been deleted.", mapping={"title": title}) - ) + + # Show appropriate message (automatically handles recycle bin checks) + message = get_deleted_success_message(title=title) + IStatusMessage(self.request).add(message) else: IStatusMessage(self.request).add( _('"${title}" has already been deleted', mapping={"title": title}) diff --git a/src/plone/app/content/browser/contents/delete.py b/src/plone/app/content/browser/contents/delete.py index 8eb6018..f60a44a 100644 --- a/src/plone/app/content/browser/contents/delete.py +++ b/src/plone/app/content/browser/contents/delete.py @@ -2,6 +2,7 @@ from AccessControl.Permissions import delete_objects from plone.app.content.browser.contents import ContentsBaseAction from plone.app.content.interfaces import IStructureAction +from plone.app.content.utils import get_deleted_success_message from plone.base import PloneMessageFactory as _ from plone.locking.interfaces import ILockable from Products.CMFCore.utils import getToolByName @@ -43,9 +44,13 @@ def get_options(self): class DeleteActionView(ContentsBaseAction): required_obj_permission = delete_objects - success_msg = _("Successfully delete items") failure_msg = _("Failed to delete items") + @property + def success_msg(self): + """Dynamic success message that includes recycle bin information.""" + return get_deleted_success_message() + def __call__(self): if self.request.form.get("render") == "yes": confirm_view = getMultiAdapter( diff --git a/src/plone/app/content/utils.py b/src/plone/app/content/utils.py index a6131bb..e93c115 100644 --- a/src/plone/app/content/utils.py +++ b/src/plone/app/content/utils.py @@ -1,6 +1,10 @@ from DateTime import DateTime from persistent.list import PersistentList from persistent.mapping import PersistentMapping +from plone.base import PloneMessageFactory as _ +from plone.base.interfaces.recyclebin import IRecycleBin +from plone.registry.interfaces import IRegistry +from zope.component import queryUtility import datetime import Missing @@ -40,3 +44,56 @@ def json_dumps(data): # can eventually provide custom handling here if we want json_loads = simplejson.loads + + +def get_deleted_success_message(title=None): + """Generate appropriate success message for deleted items. + + Automatically checks if recycle bin is enabled and gets retention period + from registry to avoid code duplication. + + Args: + title: The title of the deleted item (optional, for single item messages) + + Returns: + Translated message string + """ + + # Check if recycle bin is enabled + recycle_bin = queryUtility(IRecycleBin) + recycling_enabled = recycle_bin.is_enabled() if recycle_bin else False + + if not recycling_enabled: + # Recycle bin is disabled, show regular deletion message + if title: + return _("${title} has been deleted.", mapping={"title": title}) + else: + return _("Successfully deleted items") + + # Recycle bin is enabled, get retention period and show recycle message + registry = queryUtility(IRegistry) + retention_period = registry["recyclebin-controlpanel.retention_period"] + + if title: + # Single item message + if retention_period == 0: + return _( + "${title} has been moved to the recycle bin. It can be restored by administrators.", + mapping={"title": title}, + ) + else: + return _( + "${title} has been moved to the recycle bin. It can be restored by administrators and will be permanently deleted after ${days} days.", + mapping={"title": title, "days": retention_period}, + ) + else: + # Multiple items message + if retention_period == 0: + return _( + "Successfully moved items to recycle bin. Items can be restored by administrators." + ) + else: + return _( + "Successfully moved items to recycle bin. Items can be restored by administrators and will be permanently deleted after ${days} days.", + mapping={"days": retention_period}, + )