コード例 #1
0
ファイル: ActionProviderBase.py プロジェクト: bendavis78/zope
    def listActionInfos(self, action_chain=None, object=None,
                        check_visibility=1, check_permissions=1,
                        check_condition=1, max=-1):
        # List ActionInfo objects.
        # (method is without docstring to disable publishing)
        #
        ec = getExprContext(self, object)
        actions = self.listActions(object=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

        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
コード例 #2
0
ファイル: ActionProviderBase.py プロジェクト: goschtl/zope
    def listActionInfos(self, action_chain=None, object=None,
                        check_visibility=1, check_permissions=1,
                        check_condition=1, max=-1, ec=None):
        # List ActionInfo objects.
        # (method is without docstring to disable publishing)
        #
        if ec is None:
            ec = getExprContext(self, object)
        actions = self.listActions(object=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

        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
コード例 #3
0
ファイル: ActionProviderBase.py プロジェクト: goschtl/zope
    def listActionInfos(self, action_chain=None, object=None,
                        check_visibility=1, check_permissions=1,
                        check_condition=1, max=-1):
        # List Action info mappings.
        # (method is without docstring to disable publishing)
        #
        ec = getExprContext(self, object)
        actions = self.listActions(object=object)

        if action_chain:
            filtered_actions = []
            if isinstance(action_chain, StringType):
                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.getId() and category == ai.getCategory():
                        filtered_actions.append(ai)
            actions = filtered_actions

        action_infos = []
        for ai in actions:
            if check_visibility and not ai.getVisibility():
                continue
            if check_permissions:
                permissions = ai.getPermissions()
                if permissions:
                    category = ai.getCategory()
                    if (object is not None and
                        (category.startswith('object') or
                         category.startswith('workflow'))):
                        context = object
                    elif (ec.contexts['folder'] is not None and
                          category.startswith('folder')):
                        context = ec.contexts['folder']
                    else:
                        context = ec.contexts['portal']
                    for permission in permissions:
                        allowed = _checkPermission(permission, context)
                        if allowed:
                            break
                    if not allowed:
                        continue
            if check_condition and not ai.testCondition(ec):
                continue
            action_infos.append( ai.getAction(ec) )
            if max + 1 and len(action_infos) >= max:
                break
        return action_infos
コード例 #4
0
ファイル: ActionsTool.py プロジェクト: goschtl/zope
    def _listActionInfos(self, provider, object):
        """ for Action Providers written for CMF versions before 1.5
        """
        warn('ActionProvider interface not up to date. In CMF 1.6 '
             'portal_actions will ignore listActions() of \'%s\'.'
             % provider.getId(),
             DeprecationWarning)
        info = getOAI(self, object)
        actions = provider.listActions(info)

        action_infos = []
        if actions and type(actions[0]) is not DictionaryType:
            ec = getExprContext(self, object)
            for ai in actions:
                if not ai.getVisibility():
                    continue
                permissions = ai.getPermissions()
                if permissions:
                    category = ai.getCategory()
                    if (object is not None and
                        (category.startswith('object') or
                         category.startswith('workflow'))):
                        context = object
                    elif (info['folder'] is not None and
                          category.startswith('folder')):
                        context = info['folder']
                    else:
                        context = info['portal']
                    for permission in permissions:
                        allowed = _checkPermission(permission, context)
                        if allowed:
                            break
                    if not allowed:
                        continue
                if not ai.testCondition(ec):
                    continue
                action_infos.append( ai.getAction(ec) )
        else:
            for i in actions:
                if not i.get('visible', 1):
                    continue
                permissions = i.get('permissions', None)
                if permissions:
                    category = i['category']
                    if (object is not None and
                        (category.startswith('object') or
                         category.startswith('workflow'))):
                        context = object
                    elif (info['folder'] is not None and
                          category.startswith('folder')):
                        context = info['folder']
                    else:
                        context = info['portal']

                    for permission in permissions:
                        allowed = _checkPermission(permission, context)
                        if allowed:
                            break
                    if not allowed:
                        continue
                action_infos.append(i)
        return action_infos
コード例 #5
0
ファイル: ActionProviderBase.py プロジェクト: goschtl/zope
 def _getExprContext(self, object):
     return getExprContext(self, object)
コード例 #6
0
ファイル: ActionProviderBase.py プロジェクト: bendavis78/zope
 def _getExprContext(self, object):
     return getExprContext(self, object)
コード例 #7
0
    def _listActionInfos(self, provider, object):
        """ for Action Providers written for CMF versions before 1.5
        """
        warn(
            'ActionProvider interface not up to date. In CMF 1.6 '
            'portal_actions will ignore listActions() of \'%s\'.' %
            provider.getId(), DeprecationWarning)
        info = getOAI(self, object)
        actions = provider.listActions(info)

        action_infos = []
        if actions and not isinstance(actions[0], dict):
            ec = getExprContext(self, object)
            for ai in actions:
                if not ai.getVisibility():
                    continue
                permissions = ai.getPermissions()
                if permissions:
                    category = ai.getCategory()
                    if (object is not None
                            and (category.startswith('object')
                                 or category.startswith('workflow'))):
                        context = object
                    elif (info['folder'] is not None
                          and category.startswith('folder')):
                        context = info['folder']
                    else:
                        context = info['portal']
                    for permission in permissions:
                        allowed = _checkPermission(permission, context)
                        if allowed:
                            break
                    if not allowed:
                        continue
                if not ai.testCondition(ec):
                    continue
                action_infos.append(ai.getAction(ec))
        else:
            for i in actions:
                if not i.get('visible', 1):
                    continue
                permissions = i.get('permissions', None)
                if permissions:
                    category = i['category']
                    if (object is not None
                            and (category.startswith('object')
                                 or category.startswith('workflow'))):
                        context = object
                    elif (info['folder'] is not None
                          and category.startswith('folder')):
                        context = info['folder']
                    else:
                        context = info['portal']

                    for permission in permissions:
                        allowed = _checkPermission(permission, context)
                        if allowed:
                            break
                    if not allowed:
                        continue
                action_infos.append(i)
        return action_infos
コード例 #8
0
ファイル: ActionsTool.py プロジェクト: bendavis78/zope
    def listFilteredActionsFor(self, object=None):
        """ List all actions available to the user.
        """
        #cache = None
        #cache_mgr = getToolByName(self, 'portal_actionscache', None)

        #if cache_mgr is not None:
        #    cache = cache_mgr.ZCacheManager_getCache()

        #if cache is not None:
        #    pm = getToolByName(self, 'portal_membership')
        #    if object is None:
        #        object_url = ''
        #    else:
        #        object_url = object.absolute_url()
        #    if pm.isAnonymousUser():
        #        member = None
        #    else:
        #        member = pm.getAuthenticatedMember()
        #    # Prepare a cache key.
        #    keyset = {'object_url': object_url,
        #              'member': member,
        #             }
        #    result = cache.ZCache_get(ob=self, keywords=keyset)
        #    if result is not None:
        #        # Got a cached value.
        #        return result

        actions = []
        ec = getExprContext(self, object)

        # Include actions from specific tools.
        for provider_name in self.listActionProviders():
            provider = getattr(self, provider_name)
            if IActionProvider.isImplementedBy(provider):
                start = time()
                actions.extend(provider.listActionInfos(object=object, ec=ec))
                stop = time()
                open('/tmp/provider_times',
                     'a').write('%-20s: %8.3f\n' % (provider_name,
                                                    (stop - start) * 1000))
            else:
                # for Action Providers written for CMF versions before 1.5
                actions.extend(self._listActionInfos(provider, object))

        # Include actions from object.
        if object is not None:
            base = aq_base(object)
            if IActionProvider.isImplementedBy(base):
                actions.extend(object.listActionInfos(object=object))
            elif hasattr(base, 'listActions'):
                # for objects written for CMF versions before 1.5
                actions.extend(self._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)

        #if cache is not None:
        #    result = cache.ZCache_set(ob=self, data=filtered_actions,
        #                              keywords=keyset)
        return filtered_actions
コード例 #9
0
 def _getExprContext(self, object, extra_namespaces={}):
     return getExprContext(self, object, extra_namespaces=extra_namespaces)
コード例 #10
0
ファイル: ActionsTool.py プロジェクト: goschtl/zope
    def listFilteredActionsFor(self, object=None):
        """ List all actions available to the user.
        """
        #cache = None
        #cache_mgr = getToolByName(self, 'portal_actionscache', None)

        #if cache_mgr is not None:
        #    cache = cache_mgr.ZCacheManager_getCache()

        #if cache is not None:
        #    pm = getToolByName(self, 'portal_membership')
        #    if object is None:
        #        object_url = ''
        #    else:
        #        object_url = object.absolute_url()
        #    if pm.isAnonymousUser():
        #        member = None
        #    else:
        #        member = pm.getAuthenticatedMember()
        #    # Prepare a cache key.
        #    keyset = {'object_url': object_url,
        #              'member': member,
        #             }
        #    result = cache.ZCache_get(ob=self, keywords=keyset)
        #    if result is not None:
        #        # Got a cached value.
        #        return result

        actions = []
        ec = getExprContext(self, object)

        # Include actions from specific tools.
        for provider_name in self.listActionProviders():
            provider = getattr(self, provider_name)
            if IActionProvider.isImplementedBy(provider):
                start = time()
                actions.extend( provider.listActionInfos(object=object,
                                                         ec=ec) )
                stop = time()
                open( '/tmp/provider_times', 'a' ).write(
                   '%-20s: %8.3f\n' % (provider_name, (stop-start)*1000) )
            else:
                # for Action Providers written for CMF versions before 1.5
                actions.extend( self._listActionInfos(provider, object) )

        # Include actions from object.
        if object is not None:
            base = aq_base(object)
            if IActionProvider.isImplementedBy(base):
                actions.extend( object.listActionInfos(object=object) )
            elif hasattr(base, 'listActions'):
                # for objects written for CMF versions before 1.5
                actions.extend( self._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)

        #if cache is not None:
        #    result = cache.ZCache_set(ob=self, data=filtered_actions,
        #                              keywords=keyset)
        return filtered_actions