示例#1
0
    def listActions(self, info=None, object=None):
        # Return actions for reply and show replies
        if object is None and info is None:
            return ()
        if info is None:
            info = getOAI(self, object)
        if object is None:
            object = info.object
        content = object
        if content is None or not self.isDiscussionAllowedFor(content):
            return ()

        discussion = self.getDiscussionFor(content)
        if discussion.aq_base == content.aq_base:
            discussion_url = info.object_url
        else:
            discussion_url = discussion.absolute_url()

        actions = (
            {'name': 'Reply',
             'url': discussion_url + '/discussion_reply_form',
             'permissions': [ReplyToItem],
             'category': 'object'
             },
            )

        return actions
示例#2
0
    def listActions(self, info=None, object=None):
        # Return actions for reply and show replies
        if object is None and info is None:
            return ()
        if info is None:
            info = getOAI(self, object)
        if object is None:
            object = info.object
        content = object
        if content is None or not self.isDiscussionAllowedFor(content):
            return ()

        discussion = self.getDiscussionFor(content)
        if discussion.aq_base == content.aq_base:
            discussion_url = info.object_url
        else:
            discussion_url = discussion.absolute_url()

        actions = ({
            'name': 'Reply',
            'url': discussion_url + '/discussion_reply_form',
            'permissions': [ReplyToItem],
            'category': 'object'
        }, )

        return actions
示例#3
0
    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)
        #
        info = getOAI(self, object)
        actions = self.listActions(info=info)

        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['id'] and category == ai['category']:
                        filtered_actions.append(ai)
            actions = filtered_actions

        action_infos = []
        for ai in actions:
            if check_permissions:
                permissions = ai.get( 'permissions', () )
                if permissions:
                    category = ai['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(ai)
            if max + 1 and len(action_infos) >= max:
                break
        return action_infos
示例#4
0
    def listActions(self, info=None, object=None):

        """ Returns a list of actions to be displayed to the user.

        o Invoked by the portal_actions tool.

        o Allows workflows to include actions to be displayed in the
          actions box.

        o Object actions are supplied by workflows that apply to the object.

        o Global actions are supplied by all workflows.
        """
        if info is None:
            info = getOAI(self, object)
        if object is None:
            object = info.object
        chain = self.getChainFor(info.object)
        did = {}
        actions = []

        for wf_id in chain:
            did[wf_id] = 1
            wf = self.getWorkflowById(wf_id)
            if wf is not None:
                a = wf.listObjectActions(info)
                if a is not None:
                    actions.extend(a)
                a = wf.listGlobalActions(info)
                if a is not None:
                    actions.extend(a)

        wf_ids = self.getWorkflowIds()
        for wf_id in wf_ids:
            if not did.has_key(wf_id):
                wf = self.getWorkflowById(wf_id)
                if wf is not None:
                    a = wf.listGlobalActions(info)
                    if a is not None:
                        actions.extend(a)
        return actions
示例#5
0
    def listActions(self, info=None, object=None):
        """ Returns a list of actions to be displayed to the user.

        o Invoked by the portal_actions tool.

        o Allows workflows to include actions to be displayed in the
          actions box.

        o Object actions are supplied by workflows that apply to the object.

        o Global actions are supplied by all workflows.
        """
        if info is None:
            info = getOAI(self, object)
        if object is None:
            object = info.object
        chain = self.getChainFor(info.object)
        did = {}
        actions = []

        for wf_id in chain:
            did[wf_id] = 1
            wf = self.getWorkflowById(wf_id)
            if wf is not None:
                a = wf.listObjectActions(info)
                if a is not None:
                    actions.extend(a)
                a = wf.listGlobalActions(info)
                if a is not None:
                    actions.extend(a)

        wf_ids = self.getWorkflowIds()
        for wf_id in wf_ids:
            if not did.has_key(wf_id):
                wf = self.getWorkflowById(wf_id)
                if wf is not None:
                    a = wf.listGlobalActions(info)
                    if a is not None:
                        actions.extend(a)
        return actions
示例#6
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 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
示例#7
0
 def _getOAI(self, object):
     return getOAI(self, object)
示例#8
0
 def _getOAI(self, object):
     return getOAI(self, object)
示例#9
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