-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
svn path=/Products.CMFPlone/trunk/; revision=45988
- Loading branch information
0 parents
commit 854be6e
Showing
1,029 changed files
with
64,619 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
from Products.CMFActionIcons.ActionIconsTool import ActionIconsTool as BaseTool | ||
from Products.CMFActionIcons.permissions import View | ||
from Products.CMFCore.utils import getToolByName | ||
from AccessControl import ClassSecurityInfo | ||
from App.class_init import InitializeClass | ||
from Products.CMFPlone.PloneBaseTool import PloneBaseTool | ||
from Products.CMFPlone.PloneTool import _icons as iconcache | ||
from Products.CMFPlone.log import log_deprecated | ||
|
||
|
||
WHITELISTED_AI = set([ | ||
'controlpanel/ImagingSettings', | ||
'controlpanel/tinymce', | ||
'controlpanel/versioning', | ||
]) | ||
|
||
|
||
def removeAICacheEntry(category, id): | ||
if (category, id) in iconcache.keys(): | ||
del iconcache[(category, id)] | ||
|
||
|
||
class ActionIconsTool(PloneBaseTool, BaseTool): | ||
|
||
meta_type = 'Plone Action Icons Tool' | ||
security = ClassSecurityInfo() | ||
toolicon = 'skins/plone_images/confirm_icon.png' | ||
|
||
security.declareProtected(View, 'renderActionIcon') | ||
def renderActionIcon( self, | ||
category, | ||
action_id, | ||
default=None, | ||
context=None ): | ||
""" Returns the actual object for the icon. If you | ||
pass in a path elements in default it will attempt | ||
to traverse to that path. Otherwise it will return | ||
None | ||
""" | ||
icon = self.queryActionIcon( category, | ||
action_id, | ||
default=default, | ||
context=context ) | ||
if icon is not None: | ||
portal=getToolByName(self, 'portal_url').getPortalObject() | ||
return portal.restrictedTraverse(icon) | ||
|
||
return default | ||
|
||
def getActionIcon( self, category, action_id, context=None ): | ||
ai = BaseTool.getActionIcon(self, category, action_id, | ||
context=context) | ||
if ai: | ||
log_deprecated("The icon for the '%s/%s' action was obtained from " | ||
"the action icons tool. The action icons tool has " | ||
"been deprecated and will be removed in Plone 5. " | ||
"You should register action icons directly on the " | ||
"action now, using the 'icon_expr' " | ||
"setting." % (category, action_id)) | ||
return ai | ||
return None | ||
|
||
def queryActionIcon( self, category, action_id | ||
, default=None, context=None ): | ||
ai = BaseTool.queryActionIcon(self, category, action_id, | ||
default=default, context=context) | ||
if ai: | ||
log_deprecated("The icon for the '%s/%s' action was obtained from " | ||
"the action icons tool. The action icons tool has " | ||
"been deprecated and will be removed in Plone 5. " | ||
"You should register action icons directly on the " | ||
"action now, using the 'icon_expr' " | ||
"setting." % (category, action_id)) | ||
return ai | ||
return None | ||
|
||
def addActionIcon(self, category, action_id, icon_expr, title=None, | ||
priority=0): | ||
combination = '%s/%s' % (category, action_id) | ||
if combination not in WHITELISTED_AI: | ||
log_deprecated("An icon for the '%s' action is being added to " | ||
"the action icons tool. The action icons tool has " | ||
"been deprecated and will be removed in Plone 5. " | ||
"You should register action icons directly on the " | ||
"action now, using the 'icon_expr' " | ||
"setting." % combination) | ||
return BaseTool.addActionIcon(self, category, action_id, icon_expr, | ||
title, priority) | ||
|
||
#Below we need to invalidate the cache for icons. We have to | ||
#hardocde the module dict because we do not have events, yet. | ||
def updateActionIcon( self | ||
, category | ||
, action_id | ||
, icon_expr | ||
, title=None | ||
, priority=0 | ||
): | ||
""" update ActionIcons and remove cache entry """ | ||
log_deprecated("The icon for the '%s/%s' action is being updated on " | ||
"the action icons tool. The action icons tool has " | ||
"been deprecated and will be removed in Plone 5. " | ||
"You should register action icons directly on the " | ||
"action now, using the 'icon_expr' " | ||
"setting." % (category, action_id)) | ||
BaseTool.updateActionIcon(self, category, action_id, icon_expr, | ||
title, priority) | ||
removeAICacheEntry(category, action_id) | ||
|
||
def removeActionIcon( self, category, action_id ): | ||
""" remove ActionIcon and remove cache entry """ | ||
BaseTool.removeActionIcon(self, category, action_id) | ||
removeAICacheEntry(category, action_id) | ||
|
||
def clearActionIcons( self ): | ||
""" clear ActionIcons and cache entries """ | ||
BaseTool.clearActionIcons(self) | ||
iconcache.clear() | ||
|
||
def manage_updateActionIcon( self | ||
, category | ||
, action_id | ||
, icon_expr | ||
, title | ||
, priority | ||
, REQUEST | ||
): | ||
""" update ActionIcons from ZMI and remove cache entry """ | ||
BaseTool.manage_updateActionIcon( self, category, action_id, icon_expr, | ||
title, priority, REQUEST ) | ||
removeAICacheEntry(category, action_id) | ||
|
||
def manage_removeActionIcon( self, category, action_id, REQUEST ): | ||
""" remove ActionIcons from ZMI and remove cache entry """ | ||
BaseTool.manage_removeActionIcon(self, category, action_id, REQUEST) | ||
removeAICacheEntry(category, action_id) | ||
|
||
ActionIconsTool.__doc__ = BaseTool.__doc__ | ||
|
||
InitializeClass(ActionIconsTool) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
from AccessControl import ClassSecurityInfo | ||
from App.class_init import InitializeClass | ||
from Products.CMFCore.ActionInformation import ActionInfo | ||
from Products.CMFCore.ActionsTool import ActionsTool as BaseTool | ||
from Products.CMFCore.interfaces import IActionProvider | ||
from Products.CMFPlone.PloneBaseTool import PloneBaseTool | ||
from Products.CMFCore.interfaces import IActionCategory | ||
|
||
class ActionsTool(PloneBaseTool, BaseTool): | ||
|
||
meta_type = 'Plone Actions Tool' | ||
toolicon = 'skins/plone_images/confirm_icon.png' | ||
|
||
security = ClassSecurityInfo() | ||
|
||
# | ||
# ActionProvider interface | ||
# | ||
security.declarePrivate('listActions') | ||
def listActions(self, info=None, object=None, | ||
categories=None, ignore_categories=None): | ||
""" List all the actions defined by a provider. | ||
""" | ||
actions = list(self._actions) | ||
|
||
if ignore_categories is None: | ||
ignore_categories = () | ||
|
||
if categories is None: | ||
categories = [cat for cat in self | ||
if cat not in ignore_categories] | ||
else: | ||
categories = [cat for cat in self | ||
if cat in categories] | ||
|
||
for category in categories: | ||
if IActionCategory.providedBy(self[category]): | ||
actions.extend(self[category].listActions()) | ||
return tuple(actions) | ||
|
||
security.declarePublic('listActionInfos') | ||
def listActionInfos(self, action_chain=None, object=None, | ||
check_visibility=1, check_permissions=1, | ||
check_condition=1, max=-1, | ||
categories=None, ignore_categories=None): | ||
# List ActionInfo objects. | ||
# (method is without docstring to disable publishing) | ||
actions = self.listActions(object=object, | ||
categories=categories, | ||
ignore_categories=ignore_categories) | ||
if not actions: | ||
return [] | ||
|
||
ec = self._getExprContext(object) | ||
actions = [ ActionInfo(action, ec) for action in actions ] | ||
|
||
if action_chain: | ||
filtered_actions = [] | ||
if isinstance(action_chain, basestring): | ||
action_chain = (action_chain,) | ||
for action_ident in action_chain: | ||
sep = action_ident.rfind('/') | ||
category, id = action_ident[:sep], action_ident[sep+1:] | ||
for ai in actions: | ||
if id == ai['id'] and category == ai['category']: | ||
filtered_actions.append(ai) | ||
actions = filtered_actions | ||
|
||
if ignore_categories is not None: | ||
actions = [ai for ai in actions | ||
if ai['category'] not in ignore_categories] | ||
|
||
action_infos = [] | ||
for ai in actions: | ||
if check_visibility and not ai['visible']: | ||
continue | ||
if check_permissions and not ai['allowed']: | ||
continue | ||
if check_condition and not ai['available']: | ||
continue | ||
action_infos.append(ai) | ||
if max + 1 and len(action_infos) >= max: | ||
break | ||
return action_infos | ||
|
||
# | ||
# 'portal_actions' interface methods | ||
# | ||
security.declarePublic('listFilteredActionsFor') | ||
def listFilteredActionsFor(self, object=None, | ||
ignore_providers=(), | ||
ignore_categories=None): | ||
""" List all actions available to the user. | ||
""" | ||
actions = [] | ||
|
||
providers = [name for name in self.listActionProviders() | ||
if name not in ignore_providers] | ||
|
||
# Include actions from specific tools. | ||
for provider_name in providers: | ||
provider = getattr(self, provider_name, None) | ||
# Skip missing action providers. | ||
if provider is None: | ||
continue | ||
if IActionProvider.providedBy(provider): | ||
if provider_name == 'portal_actions': | ||
actions.extend(provider.listActionInfos( | ||
object=object, | ||
ignore_categories=ignore_categories | ||
)) | ||
else: | ||
actions.extend(provider.listActionInfos(object=object)) | ||
|
||
# Include actions from object. | ||
if object is not None: | ||
if IActionProvider.providedBy(object): | ||
actions.extend(object.listActionInfos(object=object)) | ||
|
||
# Reorganize the actions by category. | ||
filtered_actions={'user':[], | ||
'folder':[], | ||
'object':[], | ||
'global':[], | ||
'workflow':[], | ||
} | ||
|
||
for action in actions: | ||
catlist = filtered_actions.setdefault(action['category'], []) | ||
catlist.append(action) | ||
|
||
return filtered_actions | ||
|
||
InitializeClass(ActionsTool) |
Oops, something went wrong.