def getFilteredActionDict(self, user_name=_MARKER): """ Returns menu items for a given user """ portal = self.getPortalObject() is_portal_manager = portal.portal_membership.checkPermission(\ Permissions.ManagePortal, self) downgrade_authenticated_user = user_name is not _MARKER and is_portal_manager if downgrade_authenticated_user: # downgrade to desired user original_security_manager = _setSuperSecurityManager(self, user_name) # call the method implementing it erp5_menu_dict = portal.portal_actions.listFilteredActionsFor(portal) if downgrade_authenticated_user: # restore original Security Manager setSecurityManager(original_security_manager) # Unlazyfy URLs and other lazy values so that it can be marshalled result = {} for key, action_list in erp5_menu_dict.items(): result[key] = map(lambda action:dict(action), action_list) return result
def getExpressConfigurationPreference(self, preference_id, default = None): """ Get Express configuration preference """ original_security_manager = _setSuperSecurityManager(self.getPortalObject()) portal_preferences = getToolByName(self, 'portal_preferences') preference_value = portal_preferences.getPreference(preference_id, default) setSecurityManager(original_security_manager) return preference_value
def getExpressConfigurationPreference(self, preference_id, default=None): """ Get Express configuration preference """ original_security_manager = _setSuperSecurityManager( self.getPortalObject()) portal_preferences = getToolByName(self, 'portal_preferences') preference_value = portal_preferences.getPreference( preference_id, default) setSecurityManager(original_security_manager) return preference_value
def getModuleItemList(self, user_name=_MARKER): """ Returns module items for a given user """ portal = self.getPortalObject() is_portal_manager = portal.portal_membership.checkPermission( Permissions.ManagePortal, self) downgrade_authenticated_user = user_name is not _MARKER and is_portal_manager if downgrade_authenticated_user: # downgrade to desired user original_security_manager = _setSuperSecurityManager(self, user_name) # call the method implementing it erp5_module_list = portal.ERP5Site_getModuleItemList() if downgrade_authenticated_user: # restore original Security Manager setSecurityManager(original_security_manager) return erp5_module_list
def ERP5Site_changeAuthoredDocumentListOwnership(self, old_owner, new_owner): """ Change owneship for all documents in the system belonging to an user (i.e. represented by user_name/reference). """ # Move import to here prevents the raise error when this External # Be imported during the upgrade. from Products.ERP5Type.Utils import _setSuperSecurityManager from AccessControl.SecurityManagement import setSecurityManager from Products.ERP5Security.ERP5UserManager import SUPER_USER result = [] orginal_security_manager = _setSuperSecurityManager(self, SUPER_USER) portal = self.getPortalObject() user_folder = portal.acl_users new_owner_as_user = user_folder.getUserById(new_owner).__of__(user_folder) document_list = portal.portal_catalog.unrestrictedSearchResults( owner=old_owner) for document in document_list: document = document.getObject() # change document ownership document.changeOwnership(new_owner_as_user) # fix local roles for item in document.get_local_roles(): user = item[0] role_list = item[1] if user == old_owner: # replace old Owner with new One document.manage_delLocalRoles((old_owner, )) document.manage_setLocalRoles(new_owner, role_list) result.append(document.getRelativeUrl()) # finally reindex document document.reindexObject() # restore security setSecurityManager(orginal_security_manager) return dict(old_owner = old_owner, \ new_owner = new_owner, \ changed_document_list = result)
def ERP5Site_changeAuthoredDocumentListOwnership(self, old_owner, new_owner): """ Change owneship for all documents in the system belonging to an user (i.e. represented by user_name/reference). """ # Move import to here prevents the raise error when this External # Be imported during the upgrade. from Products.ERP5Type.Utils import _setSuperSecurityManager from AccessControl.SecurityManagement import setSecurityManager from Products.ERP5Security.ERP5UserManager import SUPER_USER result = [] orginal_security_manager = _setSuperSecurityManager(self, SUPER_USER) portal = self.getPortalObject() user_folder = portal.acl_users new_owner_as_user = user_folder.getUserById(new_owner).__of__(user_folder) document_list = portal.portal_catalog.unrestrictedSearchResults(owner = old_owner) for document in document_list: document = document.getObject() # change document ownership document.changeOwnership(new_owner_as_user) # fix local roles for item in document.get_local_roles(): user = item[0] role_list = item[1] if user == old_owner: # replace old Owner with new One document.manage_delLocalRoles((old_owner,)) document.manage_setLocalRoles(new_owner, role_list) result.append(document.getRelativeUrl()) # finally reindex document document.reindexObject() # restore security setSecurityManager(orginal_security_manager) return dict(old_owner = old_owner, \ new_owner = new_owner, \ changed_document_list = result)
def installBT5FilesFromServer(self, server_response, execute_after_setup_script=True, install_standard_bt5=True, install_customer_bt5=True, use_super_manager=True): """ Install or update BT5 files which we get from remote server. """ # XXX-Luke: This methods makes very long transaction: # * download business templates # * install business templates # * run after script # It leads in real world to never ending process, as any other activity # in asynchronous system can lead to conflict error and transaction # restart, and again...forever. # # To solve: # * use activity system # * download, install and run after script in activities # * use proper tags to have sequence # * expose tag initialERP5Setup global installation_status if use_super_manager: # set current security manager to owner of site original_security_manager = _setSuperSecurityManager( self.getPortalObject()) portal = self.getPortalObject() bt5_files = server_response.get("filedata", []) server_buffer = server_response.get("server_buffer", None) if server_buffer is None: # server doesn't comform protocol which means a possible server error raise ValueError("Witch server configuration error") bt5_filenames = server_buffer.get("filenames", []) portal_templates = getToolByName(portal, 'portal_templates') counter = 0 LOG("Wizard", INFO, "Starting installation for %s" % ' '.join(bt5_filenames)) installation_status['bt5']['all'] = len(bt5_files) # execute_after_setup_script = install_standard_bt5 = # install_customer_bt5 = False # dev mode for bt5_id in bt5_filenames: if bt5_id.startswith('http://') or bt5_id.startswith('file://'): ## direct download of bt5 files available if install_standard_bt5: bt = portal_templates.download(bt5_id) bt.install() installation_status['bt5']['current'] = counter + 1 LOG( "Wizard", INFO, "[OK] standard bt5 installation (HTTP) from %s" % bt5_id) else: ## remote system supplied file content if install_customer_bt5: bt5_filedata = bt5_files[counter] self._importBT5FileData(bt5_id, bt5_filedata) installation_status['bt5']['current'] = counter + 1 LOG( "Wizard", INFO, "[OK] customized bt5 installation (XML-RPC) %s, %s bytes" % (bt5_id, len(bt5_filedata))) ## .. counter += 1 ## can we execute after setup script that will finish installation on ## client side? bt5_after_setup_script_id = server_response["server_buffer"].get( "after_setup_script_id", None) if bt5_after_setup_script_id is None and \ self.getExpressConfigurationPreference( 'preferred_express_configuration_status', False): ## we already have stored after setup script id bt5_after_setup_script_id = self.getExpressConfigurationPreference( 'preferred_express_after_setup_script_id', None) if execute_after_setup_script and bt5_after_setup_script_id is not None: ## Execute script provided (if) in customer specific business template. bt5_customer_template_id = server_response["server_buffer"][ 'filenames'][-1] bt5_customer_template_id = bt5_customer_template_id.replace( '.bt5', '') after_script = getattr(self, bt5_after_setup_script_id, None) if after_script is not None: after_script_result = after_script( customer_template_id=bt5_customer_template_id) LOG( "Wizard", INFO, "[OK] execution of after setup script %s (for bt5 " "%s)%s" % (after_script.getId(), bt5_customer_template_id, after_script_result)) ## mark this ERP5 instance as configured self.setExpressConfigurationPreference( 'preferred_express_configuration_status', 1) self.setExpressConfigurationPreference( 'preferred_express_after_setup_script_id', bt5_after_setup_script_id) # Make sure that the site status is reloaded. portal.portal_caches.clearAllCache() LOG("Wizard", INFO, "Completed installation for %s" % ' '.join(bt5_filenames)) if use_super_manager: setSecurityManager(original_security_manager)
def installBT5FilesFromServer(self, server_response, execute_after_setup_script=True, install_standard_bt5=True, install_customer_bt5=True, use_super_manager=True): """ Install or update BT5 files which we get from remote server. """ # XXX-Luke: This methods makes very long transaction: # * download business templates # * install business templates # * run after script # It leads in real world to never ending process, as any other activity # in asynchronous system can lead to conflict error and transaction # restart, and again...forever. # # To solve: # * use activity system # * download, install and run after script in activities # * use proper tags to have sequence # * expose tag initialERP5Setup global installation_status if use_super_manager: # set current security manager to owner of site original_security_manager = _setSuperSecurityManager( self.getPortalObject()) portal = self.getPortalObject() bt5_files = server_response.get("filedata", []) server_buffer = server_response.get("server_buffer", None) if server_buffer is None: # server doesn't comform protocol which means a possible server error raise ValueError("Witch server configuration error") bt5_filenames = server_buffer.get("filenames", []) portal_templates = getToolByName(portal, 'portal_templates') counter = 0 LOG("Wizard", INFO, "Starting installation for %s" %' '.join(bt5_filenames)) installation_status['bt5']['all'] = len(bt5_files) # execute_after_setup_script = install_standard_bt5 = # install_customer_bt5 = False # dev mode for bt5_id in bt5_filenames: if bt5_id.startswith('http://') or bt5_id.startswith('file://') : ## direct download of bt5 files available if install_standard_bt5: bt = portal_templates.download(bt5_id) bt.install() installation_status['bt5']['current'] = counter + 1 LOG("Wizard", INFO, "[OK] standard bt5 installation (HTTP) from %s" %bt5_id) else: ## remote system supplied file content if install_customer_bt5: bt5_filedata = bt5_files[counter] self._importBT5FileData(bt5_id, bt5_filedata) installation_status['bt5']['current'] = counter + 1 LOG("Wizard", INFO, "[OK] customized bt5 installation (XML-RPC) %s, %s bytes" % (bt5_id, len(bt5_filedata))) ## .. counter += 1 ## can we execute after setup script that will finish installation on ## client side? bt5_after_setup_script_id = server_response["server_buffer"].get( "after_setup_script_id", None) if bt5_after_setup_script_id is None and \ self.getExpressConfigurationPreference( 'preferred_express_configuration_status', False): ## we already have stored after setup script id bt5_after_setup_script_id = self.getExpressConfigurationPreference( 'preferred_express_after_setup_script_id', None) if execute_after_setup_script and bt5_after_setup_script_id is not None: ## Execute script provided (if) in customer specific business template. bt5_customer_template_id = server_response["server_buffer"]['filenames' ][-1] bt5_customer_template_id = bt5_customer_template_id.replace('.bt5', '') after_script = getattr(self, bt5_after_setup_script_id, None) if after_script is not None: after_script_result = after_script( customer_template_id = bt5_customer_template_id) LOG("Wizard", INFO,"[OK] execution of after setup script %s (for bt5 " "%s)%s" %(after_script.getId(), bt5_customer_template_id, after_script_result)) ## mark this ERP5 instance as configured self.setExpressConfigurationPreference( 'preferred_express_configuration_status', 1) self.setExpressConfigurationPreference( 'preferred_express_after_setup_script_id', bt5_after_setup_script_id) # Make sure that the site status is reloaded. portal.portal_caches.clearAllCache() LOG("Wizard", INFO, "Completed installation for %s" %' '.join(bt5_filenames)) if use_super_manager: setSecurityManager(original_security_manager)