1 | from Products.Archetypes.public import listTypes |
---|
2 | from Products.Archetypes.Extensions.utils import installTypes, install_subskin |
---|
3 | from Products.CMFCore import CMFCorePermissions |
---|
4 | from Products.CMFCore.utils import getToolByName |
---|
5 | from StringIO import StringIO |
---|
6 | |
---|
7 | def install(self): |
---|
8 | """ install product """ |
---|
9 | out = StringIO() |
---|
10 | portal = getToolByName(self,'portal_url').getPortalObject() |
---|
11 | acl = self.acl_users |
---|
12 | try: |
---|
13 | portal._addRole('Editor') |
---|
14 | except KeyError: |
---|
15 | pass |
---|
16 | if acl.meta_type != 'Pluggable Auth Service': |
---|
17 | acl.changeOrCreateGroups(roles = ['Editor'], new_groups=['Editors']) |
---|
18 | else: |
---|
19 | from Products.PluggableAuthService.interfaces.plugins import IRolesPlugin |
---|
20 | from Products.PluggableAuthService.interfaces.plugins import IRoleEnumerationPlugin |
---|
21 | plugins = acl._getOb( 'plugins' ) |
---|
22 | roles = plugins.listPlugins(IRolesPlugin) |
---|
23 | enumerators = plugins.listPlugins(IRoleEnumerationPlugin) |
---|
24 | role_enums = set(roles) and set(enumerators) |
---|
25 | |
---|
26 | ids = [] |
---|
27 | for rp in role_enums: |
---|
28 | all_roles = rp[1].enumerateRoles() |
---|
29 | ids += [a['id'] for a in all_roles] |
---|
30 | if 'Editor' not in ids: |
---|
31 | acl.addRole('Editor') |
---|
32 | |
---|
33 | if 'Editors' not in acl.getGroupIds(): |
---|
34 | acl._doAddGroup('Editors', roles = ('Editor',)) |
---|
35 | |
---|
36 | out.write('Added Editors group and Editor role\n') |
---|
37 | |
---|
38 | wt = getToolByName(portal, 'portal_workflow') |
---|
39 | fflow = wt.folder_workflow |
---|
40 | pflow = wt.plone_workflow |
---|
41 | |
---|
42 | for name, state in fflow.states.items(): |
---|
43 | for p in state.getManagedPermissions(): |
---|
44 | info = state.getPermissionInfo(p) |
---|
45 | state.setPermission(p, info['acquired'], tuple(info['roles'])+('Editor',)) |
---|
46 | |
---|
47 | for name, state in pflow.states.items(): |
---|
48 | for p in state.getManagedPermissions(): |
---|
49 | info = state.getPermissionInfo(p) |
---|
50 | state.setPermission(p, info['acquired'], tuple(info['roles'])+('Editor',)) |
---|
51 | |
---|
52 | return out.getvalue() |
---|