def update_role(self, user_role=None): """Updates the provided UserRole object. The name of a role can only contain alphanumeric and underscore characters while the description can me human readable.Throws NotFound exception if an existing version of UserRole is not found. Throws Conflict if the provided UserRole object is not based on the latest persisted version of the object. @param user_role UserRole @retval success bool @throws BadRequest if object does not have _id or _rev attribute @throws NotFound object with specified id does not exist @throws Conflict object not based on latest persisted object version """ if not user_role: raise BadRequest("The user_role parameter is missing") # If this governance identifier is not set, then set to a safe version of the policy name. if not user_role.governance_name: user_role.governance_name = create_basic_identifier(user_role.name) if not is_basic_identifier(user_role.governance_name): raise BadRequest( "The governance_name field '%s' can only contain alphanumeric and underscore characters" % user_role.governance_name ) self.clients.resource_registry.update(user_role)
def create_org(self, org=None): """Creates an Org based on the provided object. The id string returned is the internal id by which Org will be identified in the data store. """ # Only allow one root ION Org in the system self._validate_resource_obj("org", org, RT.Org, checks="noid,name,unique") # If this governance identifier is not set, then set to a safe version of the org name. if not org.org_governance_name: org.org_governance_name = create_basic_identifier(org.name) if not is_basic_identifier(org.org_governance_name): raise BadRequest( "The Org org_governance_name '%s' contains invalid characters" % org.org_governance_name) org_id, _ = self.rr.create(org) # Instantiate a Directory for this Org directory = Directory(orgname=org.name) # Instantiate initial set of User Roles for this Org self._create_org_roles(org_id) return org_id
def create_role(self, user_role=None): """Persists the provided UserRole object. The name of a role can only contain alphanumeric and underscore characters while the description can me human readable. The id string returned is the internal id by which a UserRole will be indentified in the data store. @param user_role UserRole @retval user_role_id str @throws BadRequest if object passed has _id or _rev attribute """ if not user_role: raise BadRequest("The user_role parameter is missing") # If this governance identifier is not set, then set to a safe version of the policy name. if not user_role.governance_name: user_role.governance_name = create_basic_identifier(user_role.name) if not is_basic_identifier(user_role.governance_name): raise BadRequest( "The governance_name field '%s' can only contain alphanumeric and underscore characters" % user_role.governance_name ) user_role_id, version = self.clients.resource_registry.create(user_role) return user_role_id
def update_role(self, user_role=None): """Updates the provided UserRole object. The name of a role can only contain alphanumeric and underscore characters while the description can me human readable.Throws NotFound exception if an existing version of UserRole is not found. Throws Conflict if the provided UserRole object is not based on the latest persisted version of the object. @param user_role UserRole @retval success bool @throws BadRequest if object does not have _id or _rev attribute @throws NotFound object with specified id does not exist @throws Conflict object not based on latest persisted object version """ if not user_role: raise BadRequest("The user_role parameter is missing") #If this governance identifier is not set, then set to a safe version of the policy name. if not user_role.governance_name: user_role.governance_name = create_basic_identifier(user_role.name) if not is_basic_identifier(user_role.governance_name): raise BadRequest( "The governance_name field '%s' can only contain alphanumeric and underscore characters" % user_role.governance_name) self.clients.resource_registry.update(user_role)
def create_role(self, user_role=None): """Persists the provided UserRole object. The name of a role can only contain alphanumeric and underscore characters while the description can me human readable. The id string returned is the internal id by which a UserRole will be indentified in the data store. @param user_role UserRole @retval user_role_id str @throws BadRequest if object passed has _id or _rev attribute """ if not user_role: raise BadRequest("The user_role parameter is missing") #If this governance identifier is not set, then set to a safe version of the policy name. if not user_role.governance_name: user_role.governance_name = create_basic_identifier(user_role.name) if not is_basic_identifier(user_role.governance_name): raise BadRequest( "The governance_name field '%s' can only contain alphanumeric and underscore characters" % user_role.governance_name) user_role_id, version = self.clients.resource_registry.create( user_role) return user_role_id
def update_org(self, org=None): """Updates the Org based on provided object. @param org Org @throws BadRequest if object does not have _id or _rev attribute @throws NotFound object with specified id does not exist @throws Conflict object not based on latest persisted object version """ if not org: raise BadRequest("The org parameter is missing") #If this governance identifier is not set, then set to a safe version of the org name. if not org.org_governance_name: org.org_governance_name = create_basic_identifier(org.name) if not is_basic_identifier(org.org_governance_name): raise BadRequest("The Org org_governance_name '%s' can only contain alphanumeric and underscore characters" % org.org_governance_name) self.clients.resource_registry.update(org)
def create_org(self, org=None): """Creates an Org based on the provided object. The id string returned is the internal id by which Org will be identified in the data store. @param org Org @retval org_id str @throws BadRequest if object passed has _id or _rev attribute """ if not org: raise BadRequest("The org parameter is missing") #Only allow one root ION Org in the system if org.name == self._get_root_org_name(): res_list,_ = self.clients.resource_registry.find_resources(restype=RT.Org, name=self._get_root_org_name()) if len(res_list) > 0: raise BadRequest('There can only be one Org named %s' % self._get_root_org_name()) #If this governance identifier is not set, then set to a safe version of the org name. if not org.org_governance_name: org.org_governance_name = create_basic_identifier(org.name) if not is_basic_identifier(org.org_governance_name): raise BadRequest("The Org org_governance_name '%s' can only contain alphanumeric and underscore characters" % org.org_governance_name) org_id, org_rev = self.clients.resource_registry.create(org) org._id = org_id org._rev = org_rev #Instantiate a Directory for this Org directory = Directory(orgname=org.name) #Instantiate initial set of User Roles for this Org manager_role = IonObject(RT.UserRole, name='Facility Administrator', governance_name=ORG_MANAGER_ROLE, description='Change Facility Information, assign Roles, post Facility events') self.add_user_role(org_id, manager_role) member_role = IonObject(RT.UserRole, name='Facility Member', governance_name=ORG_MEMBER_ROLE, description='Subscribe to events, set personal preferences') self.add_user_role(org_id, member_role) return org_id
def create_org(self, org=None): """Creates an Org based on the provided object. The id string returned is the internal id by which Org will be identified in the data store. """ # Only allow one root ION Org in the system self._validate_resource_obj("org", org, RT.Org, checks="noid,name,unique") # If this governance identifier is not set, then set to a safe version of the org name. if not org.org_governance_name: org.org_governance_name = create_basic_identifier(org.name) if not is_basic_identifier(org.org_governance_name): raise BadRequest("The Org org_governance_name '%s' contains invalid characters" % org.org_governance_name) org_id, _ = self.rr.create(org) # Instantiate a Directory for this Org directory = Directory(orgname=org.name) # Instantiate initial set of User Roles for this Org self._create_org_roles(org_id) return org_id