Skip to content

Commit 962ef05

Browse files
committed
feat(recyclebin): refactor delete actions to utilize centralized recycle bin messaging
1 parent a66acc9 commit 962ef05

File tree

3 files changed

+50
-41
lines changed

3 files changed

+50
-41
lines changed

src/plone/app/content/browser/actions.py

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
from Acquisition import aq_inner
33
from Acquisition import aq_parent
44
from OFS.CopySupport import CopyError
5+
from plone.app.content.utils import get_recycle_bin_message
56
from plone.base import PloneMessageFactory as _
7+
from plone.base.interfaces.recyclebin import IRecycleBin
68
from plone.base.utils import get_user_friendly_types
79
from plone.base.utils import safe_text
810
from plone.locking.interfaces import ILockable
@@ -21,7 +23,6 @@
2123
from zope.component import getMultiAdapter
2224
from zope.component import queryMultiAdapter
2325
from zope.component import queryUtility
24-
from zope.component.hooks import getSite
2526
from zope.container.interfaces import INameChooser
2627
from zope.event import notify
2728
from zope.interface import Interface
@@ -90,32 +91,16 @@ def handle_delete(self, action):
9091
parent.manage_delObjects(self.context.getId())
9192

9293
# Check if recycle bin is enabled and show appropriate message
93-
try:
94-
recyclebin_enabled_view = getMultiAdapter(
95-
(getSite(), self.request), name="recyclebin-enabled"
96-
)
97-
recycling_enabled = recyclebin_enabled_view()
98-
except Exception:
99-
recycling_enabled = False
94+
recycle_bin = queryUtility(IRecycleBin)
95+
recycling_enabled = recycle_bin.is_enabled() if recycle_bin else False
10096

10197
if recycling_enabled:
102-
# Get retention period from registry (default to 30 days if not found)
98+
# Get retention period from registry
10399
registry = queryUtility(IRegistry)
104-
retention_period = 30 # default
105-
if registry is not None:
106-
try:
107-
retention_period = registry.get(
108-
"recyclebin-controlpanel.retention_period", 30
109-
)
110-
except Exception:
111-
retention_period = 30
100+
retention_period = registry["recyclebin-controlpanel.retention_period"]
112101

113-
IStatusMessage(self.request).add(
114-
_(
115-
"${title} has been moved to the recycle bin. It can be restored by administrators and will be permanently deleted after ${days} days.",
116-
mapping={"title": title, "days": retention_period},
117-
)
118-
)
102+
message = get_recycle_bin_message(title=title, retention_period=retention_period)
103+
IStatusMessage(self.request).add(message)
119104
else:
120105
IStatusMessage(self.request).add(
121106
_("${title} has been deleted.", mapping={"title": title})

src/plone/app/content/browser/contents/delete.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from AccessControl import Unauthorized
22
from AccessControl.Permissions import delete_objects
33
from plone.app.content.browser.contents import ContentsBaseAction
4+
from plone.app.content.utils import get_recycle_bin_message
45
from plone.app.content.interfaces import IStructureAction
56
from plone.base import PloneMessageFactory as _
7+
from plone.base.interfaces.recyclebin import IRecycleBin
68
from plone.locking.interfaces import ILockable
79
from plone.registry.interfaces import IRegistry
810
from Products.CMFCore.utils import getToolByName
@@ -51,30 +53,17 @@ class DeleteActionView(ContentsBaseAction):
5153
def success_msg(self):
5254
"""Dynamic success message that includes recycle bin information."""
5355
# Check if recycle bin is enabled
54-
try:
55-
recyclebin_enabled_view = getMultiAdapter(
56-
(getSite(), self.request), name="recyclebin-enabled"
57-
)
58-
recycling_enabled = recyclebin_enabled_view()
59-
except Exception:
60-
recycling_enabled = False
56+
recycle_bin = queryUtility(IRecycleBin)
57+
recycling_enabled = recycle_bin.is_enabled() if recycle_bin else False
6158

6259
if not recycling_enabled:
6360
return _("Successfully deleted items")
6461

65-
# Get retention period from registry (default to 30 days if not found)
62+
# Get retention period from registry
6663
registry = queryUtility(IRegistry)
67-
retention_period = 30 # default
68-
if registry is not None:
69-
try:
70-
retention_period = registry.get("recyclebin-controlpanel.retention_period", 30)
71-
except Exception:
72-
retention_period = 30
64+
retention_period = registry["recyclebin-controlpanel.retention_period"]
7365

74-
return _(
75-
"Successfully moved items to recycle bin. Items can be restored by administrators and will be permanently deleted after ${days} days.",
76-
mapping={"days": retention_period},
77-
)
66+
return get_recycle_bin_message(retention_period=retention_period)
7867

7968
def __call__(self):
8069
if self.request.form.get("render") == "yes":

src/plone/app/content/utils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,38 @@ def json_dumps(data):
4040

4141
# can eventually provide custom handling here if we want
4242
json_loads = simplejson.loads
43+
44+
45+
def get_recycle_bin_message(title=None, retention_period=0):
46+
"""Generate appropriate message for recycled items based on retention period.
47+
48+
Args:
49+
title: The title of the deleted item (optional, for single item messages)
50+
retention_period: Number of days to retain items (0 = indefinite)
51+
52+
Returns:
53+
Translated message string
54+
"""
55+
from plone.base import PloneMessageFactory as _
56+
57+
if title:
58+
# Single item message
59+
if retention_period == 0:
60+
return _(
61+
"${title} has been moved to the recycle bin. It can be restored by administrators.",
62+
mapping={"title": title},
63+
)
64+
else:
65+
return _(
66+
"${title} has been moved to the recycle bin. It can be restored by administrators and will be permanently deleted after ${days} days.",
67+
mapping={"title": title, "days": retention_period},
68+
)
69+
else:
70+
# Multiple items message
71+
if retention_period == 0:
72+
return _("Successfully moved items to recycle bin. Items can be restored by administrators.")
73+
else:
74+
return _(
75+
"Successfully moved items to recycle bin. Items can be restored by administrators and will be permanently deleted after ${days} days.",
76+
mapping={"days": retention_period},
77+
)

0 commit comments

Comments
 (0)