How do I create a new role in code?

Encolpe Degoute encolpe.degoute at ingeniweb.com
Sun Dec 2 19:22:31 UTC 2007


Then the best way, as often, is to read unittests.
In CMFPlone/tests/testFolderLocalRoleForm.py you can read:

self.portal.acl_users.addRole('Baz')

Regards,

Mark Phillips a écrit :
> Thanks for your speedy response! I am using plone 2.5.2 and zope 2.9.7
> on Linux.
> 
> I have been using Cooper's book (Building Websites with Plone) as a
> guide and I am close to finishing the whole product. Although Generic
> setup looks like it may be easier, I am already down the learning curve
> path with Cooper's book and I am 90% done, so I don't want to switch
> development methodologies now.
> 
> Any suggestions on how I add the role to the security tab, as if I were
> using the ZMI? I checked the Docfinder tab for the Add Role part of the
> Security tab, but there is nothing in the Docfinder that talks about
> adding a role. I just need the API to finish this part of the project.
> 
> Thanks again!
> 
> Mark
> 
> On Sun, 2007-12-02 at 11:30 -0500, Encolpe Degoute wrote:
>> For which Plone version are you programming ?
>> For Plone 2.5 or Plone 3.0 you should use a Generic Setup profile to
>> do
>> this.
>> Take a look at CMFPlone/profile/default/rolemap.xml
>>
>> Mark Phillips a écrit :
>>> I am writing a new workflow for my plone site, and I need to create
>> a
>>> new role for the workflow. I can add the new role through the ZMI
>> by:
>>> 1. adding the role to zcl_users
>>> 2. adding the role under the Security tab
>>>
>>> I can accomplish the first task with this code in my Install.py:
>>> acltool = getToolByName(self, 'acl_users')
>>>     rmanager = acltool.portal_role_manager
>>>     roleIds = rmanager.listRoleIds()
>>>     if not 'Editor' in roleIds:
>>>         rmanager.addRole('Editor', title="Content Editor")
>>>         print >> out, "Added Editor role"
>>>     else:
>>>         print >> out, "Editor Role already in place"
>>>
>>> How do I add the role under the security tab in the root of my site?
>>>
>>> If I just do the above, the role does not show up anywhere in the
>> site.
>>
>>
>> --
>> Encolpe Degoute
>> INGENIWEB (TM) - S.A.S 50000 Euros - RC B 438 725 632
>> 17 rue Louise Michel - 92300 Levallois Perret - France
>> web : www.ingeniweb.com - « les Services Web Ingénieux »
>> Tel : 01.78.15.24.08 / Fax : 01 47 57 39 14
>>
>>
>> _______________________________________________
>> Product-Developers mailing list
>> Product-Developers at lists.plone.org
>> http://lists.plone.org/mailman/listinfo/product-developers
>>
>>


-- 
Encolpe Degoute
INGENIWEB (TM) - S.A.S 50000 Euros - RC B 438 725 632
17 rue Louise Michel - 92300 Levallois Perret - France
web : www.ingeniweb.com - « les Services Web Ingénieux »
Tel : 01.78.15.24.08 / Fax : 01 47 57 39 14





More information about the Product-Developers mailing list