[3296] | 1 | from Products.Archetypes import public as atapi |
---|
| 2 | try: |
---|
| 3 | from Products.CMFCore import permissions as cmfcore_permissions |
---|
| 4 | except ImportError: |
---|
| 5 | from Products.CMFCore import CMFCorePermissions as cmfcore_permissions |
---|
| 6 | import config |
---|
| 7 | |
---|
| 8 | # Roles |
---|
| 9 | |
---|
| 10 | # Permissions |
---|
| 11 | |
---|
| 12 | # This file is used to set up permissions for your product. |
---|
| 13 | |
---|
| 14 | # The code below will create a unique add permission for each of your |
---|
| 15 | # content types. The permission for adding the type MyContentType will |
---|
| 16 | # be 'MyProject: Add MyContentType'. If instead you want to specify |
---|
| 17 | # your own add permission (e.g. use the CMF's 'Add portal content' |
---|
| 18 | # permission), you can use the ADD_PERMISSIONS dictionary to do so. |
---|
| 19 | |
---|
| 20 | # ADD_PERMISSIONS is used to specify the name of the permission |
---|
| 21 | # used for adding one of your content types. For example: |
---|
| 22 | # |
---|
| 23 | # ADD_PERMISSIONS = {'MyFirstContentType': 'Add portal content', |
---|
| 24 | # 'MySecondContentType': 'My other permission', |
---|
| 25 | # } |
---|
| 26 | |
---|
| 27 | ADD_PERMISSIONS = {} |
---|
| 28 | |
---|
| 29 | # The SITEWIDE_PERMISSIONS dictionary is used for assigning permissions |
---|
| 30 | # to different roles site-wide. For example, if you create the new roles |
---|
| 31 | # 'Czar' and 'Peasant', you could give them the 'Add portal folders' and |
---|
| 32 | # 'Delete objects' permissions like so: |
---|
| 33 | # |
---|
| 34 | # SITEWIDE_PERMISSIONS = ( |
---|
| 35 | # (['Czar', 'Peasant'], ['Add portal folders', 'Delete objects'']), |
---|
| 36 | # ) |
---|
| 37 | # |
---|
| 38 | # In general, the pattern is |
---|
| 39 | # |
---|
| 40 | # SITEWIDE_PERMISSIONS = ( |
---|
| 41 | # ([list of roles], [list of permissions]), |
---|
| 42 | # ([second list of roles], [second list of permissions]), |
---|
| 43 | # ) |
---|
| 44 | # |
---|
| 45 | # The site-wide permissions are set in Extensions/Install.py |
---|
| 46 | |
---|
| 47 | SITEWIDE_PERMISSIONS = () |
---|
| 48 | |
---|
| 49 | def initialize(): |
---|
| 50 | permissions = {} |
---|
| 51 | types = atapi.listTypes(config.PROJECT_NAME) |
---|
| 52 | for atype in types: |
---|
| 53 | portal_type = atype['portal_type'] |
---|
| 54 | permission = ADD_PERMISSIONS.get(portal_type, None) |
---|
| 55 | if permission is None: |
---|
| 56 | # construct a permission on the fly |
---|
| 57 | permission = "%s: Add %s" % (config.PROJECT_NAME, |
---|
| 58 | portal_type) |
---|
| 59 | cmfcore_permissions.setDefaultRoles(permission, ('Manager',)) |
---|
| 60 | permissions[portal_type] = permission |
---|
| 61 | |
---|
| 62 | return permissions |
---|