Add a new role in the sharing tab for Plone 3


If you want to display a new role in the sharing tabe of Plone 3 it requires a
good knowledge of ZCA. First you need to create another specific role then an
utility. These complexity allows you to control which roles are displayed
using workflows.

Lets take the example of the well known Manager role.

Create the delegating role

First you have to define a new role. The auto defined convention said that it
should be named as Sharing page: Delegate XXX role. As often you need to
register this new role both in Python and ZCML:

permissions.py

# -*- coding: utf-8 -*-
from Products.CMFCore.permissions import setDefaultRoles
from AccessControl import ModuleSecurityInfo

security = ModuleSecurityInfo("my.egg.permissions")

security.declarePublic("DelegateManagerRole")
DelegateManagerRole = "Sharing page: Delegate Manager role"
setDefaultRoles(DelegateManagerRole, ('Manager',))

permissions.zcml

<configure xmlns="http://namespaces.zope.org/zope"
    i18n_domain="my.egg">

    <!-- Our custom permissions -->
    <permission
        id="plone.DelegateManagerRole"
        title="Sharing page: Delegate Manager role"
        />

</configure>

Create your Role utility

Now you have a delagating role to control how to share your role you need to
create an utility that implements the ISharingPageRole interface. This
interface requires two attributes:

  • title: a translated title
  • required_permission: the permission defined just before

localroles.py

# -*- coding: utf-8 -*-
from zope.interface import implements
from plone.app.workflow.interfaces import ISharingPageRole

from my.egg import permissions
from my.egg import MyEggMessageFactory as _

class ManagerRole(object):
    implements(ISharingPageRole)

    title = _(u"title_can_manage", default=u"Can manage")
    required_permission = permissions.DelegateManagerRole

At last we have to register this utility and the permissions.zcml defined
above.

configure.zcml

<include file="permissions.zcml" />

  <!-- Local roles managed in the @@sharing view -->
  <utility
      name="Manager"
      factory=".localroles.ManagerRole"
      />

By default the sharing tab hide Manager, Owner and Member role
because they can create troubles when they are used in a wrong way. If you
think to show them be sure that persons that will use it are informed how they
can put their site upside down.

One Response to Add a new role in the sharing tab for Plone 3

  1. Martin Aspeli dit :

    If you install collective.sharingroles (or Plone 4, where this is part of plone.app.workflow), you can achieve the same thing with GenericSetup, which should be a lot easier.

%d blogueurs aiment cette page :