Hands-on...
- In the root folder of the product CPSMessages, create a new python module called permissions.py. The content of the file is:
from Products.CMFCore.permissions import setDefaultRoles
ReadMessages = 'Read Messages'
setDefaultRoles( ReadMessages, ('MessageRecipient'))
SendMessages = 'Send Messages'
setDefaultRoles( SendMessages, ('MessageSender')) - Import the module permissions.py from the module __init__.py of the product CPSMessages:
from Products.GenericSetup import profile_registry
from Products.GenericSetup import EXTENSION
from Products.CPSCore.interfaces import ICPSSite
import permissions
def initialize(context):"""
"""
profile_registry.registerProfile(
'default',
'CPS Messages',
'CPSMessages Product',
'profiles/default',
'CPSMessages',
EXTENSION,
for_= ICPSSite)
- Test the code now by restarting the Zope's instance and flicking through the Manage permissions interface. There should be the two new permissions Send messages and Read messages.
- Everything fine in step 3? Good. Let's say CPS to register the new roles and what permissions it should use for what role. In the folder of the default profile (path CPSMessages/profiles/default), add a new file called rolemap.xml. The content of the file is:
<?xml version="1.0"?>
<rolemap>
<roles>
<role name="MessageRecipient"/>
<role name="MessageSender"/>
</roles>
<permissions>
<permission name="Read Messages" acquire="False">
<role name="MessageRecipient"/>
</permission>
<permission name="Send Messages" acquire="False">
<role name="MessageSender"/>
</permission>
</permissions>
</rolemap> - Finally, let's say GenericSetup to import the new roles by adding this import step to the file import_steps.xml (path CPSMessages/profiles/default).
<?xml version="1.0"?>
<import-steps>
<import-step id="rolemap" version="20040523-01"
handler="Products.GenericSetup.rolemap.importRolemap"
title="Role / Permission Map">
Import custom roles and non-default role-permission mappings.
</import-step>
</import-steps> - Now go to the portal_setup tool and import the profile CPS Messages. Check the view to Manage permissions and check that permissions have been grant to the new roles.
No comments:
Post a Comment