def setup_dashboard_panels_visibility_registry(section_name): """ Initializes the values for panels visibility in registry_records. By default, only users with LabManager or Manager roles can see the panels. :param section_name: :return: An string like: "role1,yes,role2,no,rol3,no" """ registry_info = get_dashboard_registry_record() role_permissions_list = [] # Getting roles defined in the system roles = [] acl_users = get_tool("acl_users") roles_tree = acl_users.portal_role_manager.listRoleIds() for role in roles_tree: roles.append(role) # Set view permissions to each role as 'yes': # "role1,yes,role2,no,rol3,no" for role in roles: role_permissions_list.append(role) visible = 'no' if role in ['LabManager', 'Manager']: visible = 'yes' role_permissions_list.append(visible) role_permissions = ','.join(role_permissions_list) # Set permissions string into dict registry_info[get_unicode(section_name)] = get_unicode(role_permissions) # Set new values to registry record set_dashboard_registry_record(registry_info) return registry_info
def __call__(self): protect.CheckAuthenticator(self.request) # Getting values from post section_name = self.request.get('section_name', None) if section_name is None: return None role_id = self.request.get('role_id', None) if role_id is None: return None check_state = self.request.get('check_state', None) if check_state is None: return None elif check_state == 'false': check_state = 'no' else: check_state = 'yes' # Update registry registry_info = get_dashboard_registry_record() pairs = get_dashboard_panels_visibility_by_section(section_name) role_permissions = list() for pair in pairs: visibility = pair[1] if pair[0] == role_id: visibility = check_state value = '{0},{1}'.format(pair[0], visibility) role_permissions.append(value) role_permissions = ','.join(role_permissions) # Set permissions string into dict registry_info[section_name] = get_unicode(role_permissions) set_dashboard_registry_record(registry_info) return True