def add_group(self, name, tool_id): """ Add user group to Tool :param name: :type name: :param tool_id: :type tool_id: :return: :rtype: """ # Validate inputs name = _get_str_or_err(name, 'name') tool_id = _get_id_or_err(tool_id, 'tool_id') # Get Objects tool = a_m.get_tool_by_id(self.ssn, tool_id) if tool is None: raise ex.NotExistsError('Tool', 'id', tool_id) existing = [ug for ug in tool.user_groups if ug.name == name] # TODO Check if existing is not None and isinstance(existing, list): raise ex.AlreadyExistsError('UserGroup', 'name', name) return self._add_user_group(self.ssn, name, tool)
def add_role(self, name, tool_id): """ Add role is correct :param name: :type name: :param tool_id: :type tool_id: :return: :rtype: """ # Validate inputs name = _get_str_or_err(name, 'name') #tool_id = _get_id_or_err(tool_id, 'tool_id') # Get Objects tool = a_m.get_tool_by_id(self.ssn, tool_id) if tool is None: raise ex.NotExistsError('Tool', 'id', tool_id) existing = [role for role in tool.roles if role.name == name] if existing is not None and len(existing) > 0: raise ex.AlreadyExistsError('Role', 'name', name) new_role = self._add_role(self.ssn, name) # a_m.add_role_to_tool(self.ssn, new_role, tool) tool.roles.append(new_role) return new_role
def add_permission(self, tool_id, node_type, name, parent_id=None): tool_id = _get_id_or_err(tool_id, 'tool_id') node_type = _get_str_or_err(node_type, 'node_type') # Defined string name = _get_str_or_err(name, 'name') tool = a_m.get_tool_by_id(self.ssn, tool_id) if tool is None: raise ex.NotExistsError('Tool', 'id', tool_id) parent = None if parent_id is not None: parent_id = _get_id_or_err(parent_id, 'parent_id') parent = a_m.get_perm_node_in_tool(self.ssn, parent_id, tool) if parent is None: raise ex.NotExistsError('PermNode', 'id', parent_id) return a_m.add_perm_node(self.ssn, tool, node_type, name, parent)
def get_tool(self, **kwargs): """ Args: **kwargs: id|email """ if 'id' in kwargs: tool_id = _get_id_or_err(kwargs['id'], 'id') return a_m.get_tool_by_id(self.ssn, tool_id) elif 'name' in kwargs: name = _get_str_or_err(kwargs['name'], 'name') return a_m.get_tool_by_name(self.ssn, name)
def get_user(self, **kwargs): """ Args: **kwargs: id|email """ if 'id' in kwargs: user_id = _get_id_or_err(kwargs['id'], 'id') return a_m.get_user_by_id(self.ssn, user_id) elif 'email' in kwargs: email = _get_str_or_err(kwargs['email'], 'email') return a_m.get_user_by_email(self.ssn, email)
def get_role(self, **kwargs): """ Args: **kwargs: id|name """ if 'id' in kwargs: role_id = _get_id_or_err(kwargs['id'], 'id') return a_m.get_role_by_id(self.ssn, role_id) elif 'name' in kwargs: name = _get_str_or_err(kwargs['name'], 'name') return a_m.get_role_by_name(self.ssn, name)
def get_feature(self, **kwargs): """ Args: **kwargs: id|name & tool_id """ if 'id' in kwargs: feature_id = _get_id_or_err(kwargs['id'], 'id') return a_m.get_feature_by_id(self.ssn, feature_id) elif 'name' in kwargs and 'tool_id' in kwargs: name = _get_str_or_err(kwargs['name'], 'name') tool_id = _get_id_or_err(kwargs['tool_id'], 'tool_id') tool = a_m.get_tool_by_id(self.ssn, tool_id) if tool is None: raise ex.NotExistsError('Tool', 'id', tool_id) return a_m.get_feature_by_name_in_tool(self.ssn, name, tool)
def add_tool(self, name, description): name = _get_str_or_err(name, 'name') existing = a_m.get_tool_by_name(self.ssn, name) if existing is not None: raise ex.AlreadyExistsError('Tool', 'name', name) return self._add_tool(self.ssn, name, description)