def setupUWODynamicGroups(self): if 'Manager' not in self.REQUEST.AUTHENTICATED_USER.getRoles(): return 'if you were a manager then you could run this script' if isPloneSite(self): ploneSites = [self] elif hasattr(self, 'objectItems'): ploneSites = [obj for (id, obj) in self.objectItems() if isPloneSite(obj)] else: ploneSites = [] if len(ploneSites) == 0: return 'no valid plone sites were found; you have accomplished nothing' results = [] for ploneSite in ploneSites: results.append(ploneSite.id) results.append('-' * 40) portal_groups = getToolByName(ploneSite, 'portal_groups') acl_users = getToolByName(ploneSite, 'acl_users') if hasattr(acl_users, 'dynamic_groups_provider'): results.append('dynamic_groups_provider already exists') else: addDynamicGroupsPlugin(acl_users, 'dynamic_groups_provider', 'Dynamic Groups Provider') results.append('created dynamic_groups_provider') dynamicGroupsProvider = acl_users.dynamic_groups_provider for (name, predicate) in uwoGroups: if hasattr(dynamicGroupsProvider, name): results.append('dynamic group: %s already exists' % name) elif portal_groups.getGroupById(name) is not None: results.append('a static group named: %s already exists' % name) else: dynamicGroupsProvider.addGroup(name, predicate, title=name) results.append('created dynamic group: %s' % name) dynamicGroupsProvider.manage_activateInterfaces(['IGroupsPlugin', 'IGroupEnumerationPlugin']) results.append('dynamic_groups_provider activated') if hasattr(acl_users, 'ldap_authentication'): ldap_acl_users = acl_users.ldap_authentication.acl_users if 'eduPersonAffiliation' in ldap_acl_users.getSchemaConfig(): results.append('eduPersonAffiliation ldap schema item already exists') else: ldap_acl_users.manage_addLDAPSchemaItem('eduPersonAffiliation', friendly_name='eduPersonAffiliation', multivalued=True, public_name='eduPersonAffiliation') results.append('added eduPersonAffiliation ldap schema item') else: results.append('ldap does not seem to be set-up on this plone site; no ldap schema item was added') results.append('') return '\n'.join(results)
def post_install(context): """ - sets an acl user group to hold all intranet users - setup the dynamic groups plugin - sets the addable types for the ploneintranet policy """ marker = 'ploneintranet-workspace.marker' if context.readDataFile(marker) is None: return portal = api.portal.get() # Set up a group to hold all intranet users if api.group.get(groupname=INTRANET_USERS_GROUP_ID) is None: api.group.create(groupname=INTRANET_USERS_GROUP_ID) # All users have Reader role on portal root api.group.grant_roles(groupname=INTRANET_USERS_GROUP_ID, roles=['Reader', ], obj=portal) # Set up dynamic groups plugin to put all users into the above group pas = api.portal.get_tool('acl_users') if DYNAMIC_GROUPS_PLUGIN_ID not in pas.objectIds(): addDynamicGroupsPlugin( pas, DYNAMIC_GROUPS_PLUGIN_ID, "ploneintranet.workspace Dynamic Groups" ) plugin = pas[DYNAMIC_GROUPS_PLUGIN_ID] plugin.addGroup( group_id=INTRANET_USERS_GROUP_ID, predicate='python: True', title='All Intranet Users', description='', active=True, ) # activate the plugin (all interfaces) activatePluginInterfaces(portal, DYNAMIC_GROUPS_PLUGIN_ID) # deactivate the enumerate groups interface for collective.workspace activatePluginInterfaces(portal, 'workspace_groups', disable=['IGroupEnumerationPlugin']) # Set up the ploneintranet policy for all addable types default_types = [] types = api.portal.get_tool('portal_types') for type_info in types.listTypeInfo(): if type_info.global_allow: default_types.append(type_info.getId()) if default_types: pwftool = api.portal.get_tool('portal_placeful_workflow') policy = pwftool['ploneintranet_policy'] policy.setChainForPortalTypes(default_types, ('(Default)',))
def post_install(context): """ - adds the global "workspaces" container - sets an acl user group to hold all intranet users - setup the dynamic groups plugin - sets the addable types for the ploneintranet policy """ marker = 'ploneintranet.workspace_default.txt' if context.readDataFile(marker) is None: return portal = api.portal.get() if 'workspaces' not in portal: api.content.create( container=portal, type='ploneintranet.workspace.workspacecontainer', title='Workspaces' ) if TEMPLATES_FOLDER not in portal: api.content.create( container=portal, id=TEMPLATES_FOLDER, type='ploneintranet.workspace.workspacecontainer', title='Templates' ) # Set up a group to hold all intranet users if api.group.get(groupname=INTRANET_USERS_GROUP_ID) is None: api.group.create(groupname=INTRANET_USERS_GROUP_ID) # Set up dynamic groups plugin to put all users into the above group pas = api.portal.get_tool('acl_users') if DYNAMIC_GROUPS_PLUGIN_ID not in pas.objectIds(): addDynamicGroupsPlugin( pas, DYNAMIC_GROUPS_PLUGIN_ID, "ploneintranet.workspace Dynamic Groups" ) plugin = pas[DYNAMIC_GROUPS_PLUGIN_ID] plugin.addGroup( group_id=INTRANET_USERS_GROUP_ID, predicate='python: True', title='All Intranet Users', description='', active=True, ) # activate the plugin (all interfaces) activatePluginInterfaces(portal, DYNAMIC_GROUPS_PLUGIN_ID) # deactivate the enumerate groups interface for collective.workspace activatePluginInterfaces(portal, 'workspace_groups', disable=['IGroupEnumerationPlugin']) # Set up the ploneintranet policy for all addable types # Re-run ploneintranet.workspace:default after installing extra types! default_types = [] types = api.portal.get_tool('portal_types') for type_info in types.listTypeInfo(): if type_info.global_allow: default_types.append(type_info.getId()) if default_types: # Folders should be state-less! # Todo items use todo_workflow default_types = [ x for x in default_types if x not in ('Folder', 'todo')] pwftool = api.portal.get_tool('portal_placeful_workflow') policy = pwftool['ploneintranet_policy'] policy.setChainForPortalTypes(default_types, ('(Default)',))
def post_install(context): """ - adds the global "workspaces" container - adds the global "templates" case templates container (actual case template is provided by ploneintranet.suite) - sets an acl user group to hold all intranet users - setup the dynamic groups plugin - makes sure the membrane groups plugin is ordered before the recursive groups plugin - sets the addable types for the ploneintranet policy """ portal = api.portal.get() if 'workspaces' not in portal: api.content.create(container=portal, type='ploneintranet.workspace.workspacecontainer', title='Workspaces') if TEMPLATES_FOLDER not in portal: api.content.create(container=portal, id=TEMPLATES_FOLDER, type='ploneintranet.workspace.workspacecontainer', title='Templates') # Set up a group to hold all intranet users if api.group.get(groupname=INTRANET_USERS_GROUP_ID) is None: api.group.create(groupname=INTRANET_USERS_GROUP_ID) # Set up dynamic groups plugin to put all users into the above group pas = api.portal.get_tool('acl_users') if DYNAMIC_GROUPS_PLUGIN_ID not in pas.objectIds(): addDynamicGroupsPlugin(pas, DYNAMIC_GROUPS_PLUGIN_ID, "ploneintranet.workspace Dynamic Groups") plugin = pas[DYNAMIC_GROUPS_PLUGIN_ID] plugin.addGroup( group_id=INTRANET_USERS_GROUP_ID, predicate='python: True', title='All Intranet Users', description='', active=True, ) # activate the plugin (all interfaces) activatePluginInterfaces(portal, DYNAMIC_GROUPS_PLUGIN_ID) # deactivate the enumerate groups interface for collective.workspace activatePluginInterfaces(portal, 'workspace_groups', disable=['IGroupEnumerationPlugin']) # make sure the membrane_groups plugin comes before recursive_groups plugins = list(pas.plugins._getPlugins(IGroupsPlugin)) try: target_index = plugins.index('recursive_groups') if target_index > 0: target_index = target_index - 1 except ValueError: target_index = 0 plugins.remove('membrane_groups') plugins.insert(target_index, 'membrane_groups') pas.plugins._plugins[IGroupsPlugin] = tuple(plugins) # Set up the ploneintranet policy for all addable types # Re-run ploneintranet.workspace:default after installing extra types! default_types = [] types = api.portal.get_tool('portal_types') for type_info in types.listTypeInfo(): if type_info.global_allow: default_types.append(type_info.getId()) if default_types: # Folders should be state-less! # Todo items use todo_workflow default_types = [ x for x in default_types if x not in ('Folder', 'todo') ] pwftool = api.portal.get_tool('portal_placeful_workflow') policy = pwftool['ploneintranet_policy'] policy.setChainForPortalTypes(default_types, ('(Default)', ))