Reputation: 2431
I'm on plone 4.1 and I need to create a portal role by code and I cannot find any official reference.
After a bit of grepping I found this:
acl_users.portal_role_manager.addRole
Which seems to create the role but the role afaict is not available anywhere, nor in the security tab nor in the roles listed on /@@usergroup-userprefs.
Then I found also an "_addRole" on the portal object (which I think comes from eggs/Zope2-2.13.8-py2.6.egg/OFS/role.py).
I found a use of this in http://repositorio.interlegis.gov.br/ILSAAP/trunk/InstallUtils/installers/installRoles.py
and I'm now using
portal._addRole(new_role)
try:
acl_users.portal_role_manager.addRole(new_role)
except:
pass
that works! :)
The use real use-case is a specific blueprint for transmogrifier:
The question is: is this the way to go?
Upvotes: 3
Views: 320
Reputation: 245
Roles are store localy in each zodb object so you can modify like that
## Roles are store on __ac_roles__ attribute of object.
roles = list(portal.__ac_roles__)
roles += 'yournewrole'
portal.__ac_roles__ = tuple(roles)
I think it's enough for your use case.
Upvotes: 2