Esempio n. 1
0
    def _setup_actions(self):
        """ """
        context = self.portal
        self.loginAsPortalOwner()
        tool = context.getAdapter('pa')()

        tool._setObject('root_level', ActionCategory('root_level'))

        root_level = getattr(tool, 'root_level')
        root_level._setObject('action_category_level1',
                              ActionCategory('action_category_level1'))
        action_category_level1 = getattr(root_level, 'action_category_level1')
        action_category_level1.title = u'Action category level1'

        kwargs = {}
        kwargs['title'] = 'Action root'
        kwargs['description'] = 'Such an root action'
        kwargs['i18n_domain'] = 'plone'
        kwargs['url_expr'] = 'string:${here/portal_url}/action_root'
        kwargs['link_target'] = '_self'
        kwargs['available_expr'] = 'python:True'
        kwargs['permissions'] = 'View'
        kwargs['visible'] = True

        root_level._setObject('action_root', Action('action_root', **kwargs))
        action_root = getattr(root_level, 'action_root')
        action_root.manage_addProperty(id='class_',
                                       value='my-class-root',
                                       type='string')

        kwargs = {}
        kwargs['title'] = 'Action level 1'
        kwargs['description'] = 'Such an level 1 action'
        kwargs['i18n_domain'] = 'plone'
        kwargs['url_expr'] = 'string:${here/portal_url}/action_level1'
        kwargs['link_target'] = '_blank'
        kwargs['available_expr'] = 'python:True'
        kwargs['permissions'] = 'View'
        kwargs['visible'] = True

        action_category_level1._setObject('action_level1',
                                          Action('action_level1', **kwargs))
        action_level1 = getattr(action_category_level1, 'action_level1')

        root_level._setObject('action_category_empty',
                              ActionCategory('action_category_empty'))
        action_category_empty = getattr(root_level, 'action_category_empty')
        action_category_empty.title = u'Action category empty'
Esempio n. 2
0
    def _populate(self, obj):
        from Products.CMFCore.ActionInformation import Action
        from Products.CMFCore.ActionInformation import ActionCategory

        obj._setObject('foo_category', ActionCategory('foo_category'))
        obj.action_providers = ('portal_actions', )
        obj.foo_category._setObject('foo_action', Action('foo_action'))
        obj.foo_category.foo_action.i18n_domain = 'foo_domain'
Esempio n. 3
0
def get_category():
    """Obtem a categoria do portal_actions"""
    portal_actions = api.portal.get_tool(name='portal_actions')
    category = portal_actions.get(ACTION_CATEGORY, None)
    if not category:
        portal_actions._setObject(ACTION_CATEGORY, ActionCategory(ACTION_CATEGORY))
        return get_category()
    return category
Esempio n. 4
0
    def setUp(self):
        from Products.CMFCore.ActionInformation import ActionCategory

        PlacelessSetup.setUp(self)
        zcml.load_config('meta.zcml', Products.Five)
        zcml.load_config('configure.zcml', Products.CMFCore.exportimport)

        self._obj = ActionCategory('foo_category')
        self._XML = _ACTIONCATEGORY_XML
 def getOrCreateCategory(self, name):
     """Get or create (if necessary) category"""
     portal_actions = self.portal_actions
     if name not in map(
             lambda x: x.id,
             filter(lambda x: IActionCategory.providedBy(x),
                    portal_actions.objectValues())):
         portal_actions._setObject(name, ActionCategory(name))
     return self.getActionCategory(name)
Esempio n. 6
0
    def setUp(self):
        import Products.CMFCore
        from Products.CMFCore.ActionInformation import ActionCategory

        NodeAdapterTestCase.setUp(self)
        zcml.load_config('configure.zcml', Products.CMFCore)

        self._obj = ActionCategory('foo_category')
        self._XML = _ACTIONCATEGORY_XML
Esempio n. 7
0
 def setupActions(self, parent, kids=PORTAL_ACTIONS):
     ids = parent.objectIds()
     for id, child in kids:
         if child['type'] == 'action' and id not in ids:
             parent._setObject(id, Action(id, **child))
             continue
         if child['type'] == 'category':
             if id not in ids:
                 parent._setObject(id, ActionCategory(id))
             if child.get('children', {}):
                 self.setupActions(getattr(parent, id), child['children'])
Esempio n. 8
0
 def test_getActionObject(self):
     tool = self._makeOne()
     tool._setObject('object', ActionCategory('object'))
     tool.object._setObject('newstyle_id', Action('newstyle_id'))
     tool.addAction('an_id', 'name', '', '', '', 'object')
     rval = tool.getActionObject('object/an_id')
     self.assertEqual(rval, tool._actions[0])
     rval = tool.getActionObject('object/newstyle_id')
     self.assertEqual(rval, None)
     rval = tool.getActionObject('object/not_existing_id')
     self.assertEqual(rval, None)
     self.assertRaises(ValueError, tool.getActionObject, 'wrong_format')
Esempio n. 9
0
def migrateOldActions(context):
    portal = getToolByName(context, 'portal_url').getPortalObject()
    special_providers = [
        'portal_controlpanel', 'portal_types', 'portal_workflow'
    ]
    # We don't need to operate on the providers that are still valid and
    # should ignore the control panel as well
    providers = [
        obj for obj in portal.objectValues()
        if hasattr(obj, '_actions') and obj.getId() not in special_providers
    ]
    non_empty_providers = [p for p in providers if len(p._actions) > 0]
    for provider in non_empty_providers:
        for action in provider._actions:
            category = action.category
            # check if the category already exists, otherwise create it
            new_category = getattr(aq_base(portal.portal_actions), category,
                                   None)
            if new_category is None:
                portal.portal_actions._setObject(category,
                                                 ActionCategory(id=category))
                new_category = portal.portal_actions[category]

            # Special handling for Expressions
            url_expr = ''
            if action.action:
                url_expr = action.action.text
            available_expr = ''
            if action.condition:
                available_expr = action.condition.text

            new_action = Action(action.id,
                                title=action.title,
                                description=action.description,
                                url_expr=url_expr,
                                available_expr=available_expr,
                                permissions=action.permissions,
                                visible=action.visible)

            # Only add an action if there isn't one with that name already
            if getattr(aq_base(new_category), action.id, None) is None:
                new_category._setObject(action.id, new_action)

        # Remove old actions from upgraded providers
        provider._actions = ()
    logger.info(
        'Upgraded old actions to new actions stored in portal_actions.')
Esempio n. 10
0
    def validateActionFields(self, cat_name, data, allow_dup=False):
        """Check action fields on validity"""
        errors = {}

        if allow_dup:
            # create dummy category to avoid id
            # duplication during action update
            category = ActionCategory(cat_name)
        else:
            # get or create (if necessary) actions category
            category = self.getOrCreateCategory(cat_name)

        # validate action id
        chooser = INameChooser(category)
        try:
            chooser.checkName(data['id'], self.context)
        except Exception, e:
            errors['id'] = self._formatError(e, **{'id': data['id']})
    def _makeOne(self, *args, **kw):
        from Products.CMFCore.ActionInformation import ActionCategory

        return ActionCategory(*args, **kw)
Esempio n. 12
0
 def test_getActionObject_skips_newstyle_actions(self):
     tool = self._makeOne()
     tool._setObject('object', ActionCategory('object'))
     tool.object._setObject('newstyle_id', Action('newstyle_id'))
     rval = tool.getActionObject('object/newstyle_id')
     self.assertEqual(rval, None)
Esempio n. 13
0
 def test_getActionObject_nonesuch_returns_None(self):
     tool = self._makeOne()
     tool._setObject('object', ActionCategory('object'))
     rval = tool.getActionObject('object/not_existing_id')
     self.assertEqual(rval, None)
Esempio n. 14
0
    def setUp(self):
        from Products.CMFCore.ActionInformation import ActionCategory

        NodeAdapterTestCase.setUp(self)
        self._obj = ActionCategory('foo_category')
        self._XML = _ACTIONCATEGORY_XML
 def add_category(self, name):
     category = ActionCategory()
     category.id = name
     self.portal_actions._setObject(name, category)
     return category