How do I create a new role in code?

Mark Phillips mark at phillipsmarketing.biz
Sun Dec 2 19:38:02 UTC 2007


You are correct - I have found that to be a great way to find the API for different tasks, especially when coupled with the DocFinder tab. 

However, that solution only adds the role to the acl_users area, and not the security tab. In order to add a role in Plone 2.5, one has to add the role in two places - the acl_users and the Security tab. take a look at http://plone.org/documentation/faq/adding-role/?searchterm=add%20a%20role.

I go the acl_users part to work (see below). My original question was reagarding the Security tab in the ZMI. How do I replicate the Add Role funtion in my Install.py script? I can't seem to find a reference in the DocFinder tab for that section.

Thanks again!

Mark


-----Original Message-----
From: product-developers-bounces at lists.plone.org on behalf of Encolpe Degoute
Sent: Sun 12/2/2007 12:22 PM
To: product-developers at lists.plone.org
Subject: Re: How do I create a new role in code?
 
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


_______________________________________________
Product-Developers mailing list
Product-Developers at lists.plone.org
http://lists.plone.org/mailman/listinfo/product-developers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20071202/5e188bdc/attachment-0002.html>


More information about the Product-Developers mailing list