def listFilteredActionsFor(self, object=None): '''Gets all actions available to the user and returns a mapping containing user actions, object actions, and global actions. ''' portal = aq_parent(aq_inner(self)) if object is None or not hasattr(object, 'aq_base'): folder = portal else: folder = object # Search up the containment hierarchy until we find an # object that claims it's a folder. while folder is not None: if getattr(aq_base(folder), 'isPrincipiaFolderish', 0): # found it. break else: folder = aq_parent(aq_inner(folder)) ec = createExprContext(folder, portal, object) actions = [] append = actions.append info = oai(self, folder, object) # Include actions from specific tools. for provider_name in self.listActionProviders(): provider = getattr(self, provider_name) self._listActions(append, provider, info, ec) # Include actions from object. if object is not None: base = aq_base(object) types_tool = getToolByName(self, 'portal_types') # we might get None back from getTypeInfo. We construct # a dummy TypeInformation object here in that case (the 'or' # case). This prevents us from needing to check the condition. ti = types_tool.getTypeInfo(object) or TypeInformation('Dummy') defs = ti.getActions() url = object_url = object.absolute_url() for d in defs: # we can't modify or expose the original actionsd... this # stems from the fact that getActions returns a ref to the # actual dictionary used to store actions instead of a # copy. We copy it here to prevent it from being modified. d = d.copy() d['id'] = d.get('id', None) if d['action']: url = '%s/%s' % (object_url, d['action']) d['url'] = url d['category'] = d.get('category', 'object') d['visible'] = d.get('visible', 1) actions.append(d) if hasattr(base, 'listActions'): self._listActions(append, object, info, ec) # Reorganize the actions by category, # filtering out disallowed actions. filtered_actions = { 'user': [], 'folder': [], 'object': [], 'global': [], 'workflow': [], } for action in actions: category = action['category'] permissions = action.get('permissions', None) visible = action.get('visible', 1) if not visible: continue verified = 0 if not permissions: # This action requires no extra permissions. verified = 1 else: if (object is not None and (category.startswith('object') or category.startswith('workflow'))): context = object elif (folder is not None and category.startswith('folder')): context = folder else: context = portal for permission in permissions: # The user must be able to match at least one of # the listed permissions. if _checkPermission(permission, context): verified = 1 break if verified: catlist = filtered_actions.get(category, None) if catlist is None: filtered_actions[category] = catlist = [] # Filter out duplicate actions by identity... if not action in catlist: catlist.append(action) # ...should you need it, here's some code that filters # by equality (use instead of the two lines above) #if not [a for a in catlist if a==action]: # catlist.append(action) return filtered_actions
def listFilteredActionsFor(self, object=None): '''Gets all actions available to the user and returns a mapping containing user actions, object actions, and global actions. ''' portal = aq_parent(aq_inner(self)) if object is None or not hasattr(object, 'aq_base'): folder = portal else: folder = object # Search up the containment hierarchy until we find an # object that claims it's a folder. while folder is not None: if getattr(aq_base(folder), 'isPrincipiaFolderish', 0): # found it. break else: folder = aq_parent(aq_inner(folder)) ec = createExprContext(folder, portal, object) actions = [] append = actions.append info = oai(self, folder, object) # Include actions from specific tools. for provider_name in self.listActionProviders(): provider = getattr(self, provider_name) self._listActions(append,provider,info,ec) # Include actions from object. if object is not None: base = aq_base(object) types_tool = getToolByName( self, 'portal_types' ) ti = types_tool.getTypeInfo( object ) if ti is not None: defs = ti.getActions() if defs: c_url = object.absolute_url() for d in defs: a = d['action'] if a: url = c_url + '/' + a else: url = c_url actions.append({ 'id': d.get('id', None), 'name': d['name'], 'action': d['action'], 'url': url, 'permissions': d['permissions'], 'category': d.get('category', 'object'), 'visible': d.get('visible', 1), }) if hasattr(base, 'listActions'): self._listActions(append,object,info,ec) # Reorganize the actions by category, # filtering out disallowed actions. filtered_actions={'user':[], 'folder':[], 'object':[], 'global':[], 'workflow':[], } for action in actions: category = action['category'] permissions = action.get('permissions', None) visible = action.get('visible', 1) if not visible: continue verified = 0 if not permissions: # This action requires no extra permissions. verified = 1 else: if category in ('object', 'workflow') and object is not None: context = object elif category == 'folder' and folder is not None: context = folder else: context = portal for permission in permissions: # The user must be able to match at least one of # the listed permissions. if _checkPermission(permission, context): verified = 1 break if verified: catlist = filtered_actions.get(category, None) if catlist is None: filtered_actions[category] = catlist = [] # Filter out duplicate actions by identity... if not action in catlist: catlist.append(action) # ...should you need it, here's some code that filters # by equality (use instead of the two lines above) #if not [a for a in catlist if a==action]: # catlist.append(action) return filtered_actions
def listFilteredActionsFor(self, object=None): '''Gets all actions available to the user and returns a mapping containing user actions, object actions, and global actions. ''' portal = aq_parent(aq_inner(self)) if object is None or not hasattr(object, 'aq_base'): folder = portal else: folder = object # Search up the containment hierarchy until we find an # object that claims it's a folder. while folder is not None: if getattr(aq_base(folder), 'isPrincipiaFolderish', 0): # found it. break else: folder = aq_parent(aq_inner(folder)) ec = createExprContext(folder, portal, object) actions = [] append = actions.append info = oai(self, folder, object) # Include actions from specific tools. for provider_name in self.listActionProviders(): provider = getattr(self, provider_name) self._listActions(append,provider,info,ec) # Include actions from object. if object is not None: base = aq_base(object) types_tool = getToolByName( self, 'portal_types' ) # we might get None back from getTypeInfo. We construct # a dummy TypeInformation object here in that case (the 'or' # case). This prevents us from needing to check the condition. ti = types_tool.getTypeInfo( object ) or TypeInformation('Dummy') defs = ti.getActions() url = object_url = object.absolute_url() for d in defs: # we can't modify or expose the original actionsd... this # stems from the fact that getActions returns a ref to the # actual dictionary used to store actions instead of a # copy. We copy it here to prevent it from being modified. d = d.copy() d['id'] = d.get('id', None) if d['action']: url = '%s/%s' % (object_url, d['action']) d['url'] = url d['category'] = d.get('category', 'object') d['visible'] = d.get('visible', 1) actions.append(d) if hasattr(base, 'listActions'): self._listActions(append,object,info,ec) # Reorganize the actions by category, # filtering out disallowed actions. filtered_actions={'user':[], 'folder':[], 'object':[], 'global':[], 'workflow':[], } for action in actions: category = action['category'] permissions = action.get('permissions', None) visible = action.get('visible', 1) if not visible: continue verified = 0 if not permissions: # This action requires no extra permissions. verified = 1 else: if (object is not None and (category.startswith('object') or category.startswith('workflow'))): context = object elif (folder is not None and category.startswith('folder')): context = folder else: context = portal for permission in permissions: # The user must be able to match at least one of # the listed permissions. if _checkPermission(permission, context): verified = 1 break if verified: catlist = filtered_actions.get(category, None) if catlist is None: filtered_actions[category] = catlist = [] # Filter out duplicate actions by identity... if not action in catlist: catlist.append(action) # ...should you need it, here's some code that filters # by equality (use instead of the two lines above) #if not [a for a in catlist if a==action]: # catlist.append(action) return filtered_actions
def listFilteredActionsFor(self, object=None): """ Return a mapping containing of all actions available to the user against object, bucketing into categories. """ portal = aq_parent(aq_inner(self)) if object is None or not hasattr(object, 'aq_base'): folder = portal else: folder = object # Search up the containment hierarchy until we find an # object that claims it's a folder. while folder is not None: if getattr(aq_base(folder), 'isPrincipiaFolderish', 0): # found it. break else: folder = aq_parent(aq_inner(folder)) ec = createExprContext(folder, portal, object) actions = [] append = actions.append info = oai(self, folder, object) # Include actions from specific tools. for provider_name in self.listActionProviders(): provider = getattr(self, provider_name) self._listActions(append,provider,info,ec) # Include actions from object. if object is not None: base = aq_base(object) if hasattr(base, 'listActions'): self._listActions(append,object,info,ec) # Reorganize the actions by category, # filtering out disallowed actions. filtered_actions={'user':[], 'folder':[], 'object':[], 'global':[], 'workflow':[], } for action in actions: category = action['category'] permissions = action.get('permissions', None) visible = action.get('visible', 1) if not visible: continue verified = 0 if not permissions: # This action requires no extra permissions. verified = 1 else: # startswith() is used so that we can have several # different categories that are checked in the object or # folder context. if (object is not None and (category.startswith('object') or category.startswith('workflow'))): context = object elif (folder is not None and category.startswith('folder')): context = folder else: context = portal for permission in permissions: # The user must be able to match at least one of # the listed permissions. if _checkPermission(permission, context): verified = 1 break if verified: catlist = filtered_actions.get(category, None) if catlist is None: filtered_actions[category] = catlist = [] # Filter out duplicate actions by identity... if not action in catlist: catlist.append(action) # ...should you need it, here's some code that filters # by equality (use instead of the two lines above) #if not [a for a in catlist if a==action]: # catlist.append(action) return filtered_actions
def listFilteredActionsFor(self, object=None): '''Gets all actions available to the user and returns a mapping containing user actions, object actions, and global actions. ''' portal = aq_parent(aq_inner(self)) if object is None or not hasattr(object, 'aq_base'): folder = portal else: folder = object # Search up the containment hierarchy until we find an # object that claims it's a folder. while folder is not None: if getattr(aq_base(folder), 'isPrincipiaFolderish', 0): # found it. break else: folder = aq_parent(aq_inner(folder)) ec = createExprContext(folder, portal, object) ai_objs = [] actions = [] info = oai(self, folder, object) # Include actions from specific tools. for provider_name in self.listActionProviders(): provider = getattr(self, provider_name) a = provider.listActions(info) if a and type(a[0]) is not type({}): ai_objs.extend(list(a)) else: for i in a: actions.append(i) if ai_objs: for ai in ai_objs: if ai.testCondition(ec): actions.append(ai.getAction(ec)) # Include actions from object. if object is not None: base = aq_base(object) types_tool = getToolByName(self, 'portal_types') ti = types_tool.getTypeInfo(object) if ti is not None: defs = ti.getActions() if defs: c_url = object.absolute_url() for d in defs: a = d['action'] if a: url = c_url + '/' + a else: url = c_url actions.append({ 'id': d.get('id', None), 'name': d['name'], 'url': url, 'permissions': d['permissions'], 'category': d.get('category', 'object'), 'visible': d.get('visible', 1), }) if hasattr(base, 'listActions'): a = object.listActions(info) if a: actions.extend(list(a)) # Reorganize the actions by category, # filtering out disallowed actions. filtered_actions = { 'user': [], 'folder': [], 'object': [], 'global': [], 'workflow': [], } for action in actions: category = action['category'] permissions = action.get('permissions', None) visible = action.get('visible', 1) if not visible: continue verified = 0 if not permissions: # This action requires no extra permissions. verified = 1 else: if category in ('object', 'workflow') and object is not None: context = object elif category == 'folder' and folder is not None: context = folder else: context = portal for permission in permissions: # The user must be able to match at least one of # the listed permissions. if _checkPermission(permission, context): verified = 1 break if verified: catlist = filtered_actions.get(category, None) if catlist is None: filtered_actions[category] = catlist = [] # If a bug occurs where actions appear more than once, # a little code right here can fix it. catlist.append(action) return filtered_actions
def listFilteredActionsFor(self, object=None): '''Gets all actions available to the user and returns a mapping containing user actions, object actions, and global actions. ''' portal = aq_parent(aq_inner(self)) if object is None or not hasattr(object, 'aq_base'): folder = portal else: folder = object # Search up the containment hierarchy until we find an # object that claims it's a folder. while folder is not None: if getattr(aq_base(folder), 'isPrincipiaFolderish', 0): # found it. break else: folder = aq_parent(aq_inner(folder)) ec = createExprContext(folder, portal, object) ai_objs = [] actions = [] info = oai(self, folder, object) # Include actions from specific tools. for provider_name in self.listActionProviders(): provider = getattr(self, provider_name) a = provider.listActions(info) if a and type(a[0]) is not type({}): ai_objs.extend(list(a)) else: for i in a: actions.append(i) if ai_objs: for ai in ai_objs: if ai.testCondition(ec): actions.append(ai.getAction(ec)) # Include actions from object. if object is not None: base = aq_base(object) types_tool = getToolByName( self, 'portal_types' ) ti = types_tool.getTypeInfo( object ) if ti is not None: defs = ti.getActions() if defs: c_url = object.absolute_url() for d in defs: a = d['action'] if a: url = c_url + '/' + a else: url = c_url actions.append({ 'id': d.get('id', None), 'name': d['name'], 'url': url, 'permissions': d['permissions'], 'category': d.get('category', 'object'), 'visible': d.get('visible', 1), }) if hasattr(base, 'listActions'): a = object.listActions(info) if a: actions.extend(list(a)) # Reorganize the actions by category, # filtering out disallowed actions. filtered_actions={'user':[], 'folder':[], 'object':[], 'global':[], 'workflow':[], } for action in actions: category = action['category'] permissions = action.get('permissions', None) visible = action.get('visible', 1) if not visible: continue verified = 0 if not permissions: # This action requires no extra permissions. verified = 1 else: if category in ('object', 'workflow') and object is not None: context = object elif category == 'folder' and folder is not None: context = folder else: context = portal for permission in permissions: # The user must be able to match at least one of # the listed permissions. if _checkPermission(permission, context): verified = 1 break if verified: catlist = filtered_actions.get(category, None) if catlist is None: filtered_actions[category] = catlist = [] # If a bug occurs where actions appear more than once, # a little code right here can fix it. catlist.append(action) return filtered_actions