def check_permission(self,permission): """ Checks if this user has a specific Permission """ if self.get_id() == ROOT_USER_ID and self.get_name() == "root": return True return Permission.check_permission(permission,self)
def get_grantable_roles(self): """ get the roles that can be assigned to this user returns list of dict: {'name':string, 'granted':bool,'id':int } """ return Permission.get_grantable_roles(self)
def getRoles(self,params): session_user = Session.get_current_session_user() if session_user.check_permission('skarphed.roles.view'): ret = [] for role in Permission.get_roles(): ret.append({"id":role.get_id(), "name": role.get_name()}) return ret return False
def grant_permission(self, permission, ignore_check=False): """ grants a permission to the user """ db = Database() session_user = None if not ignore_check: session_user = self._core.get_session_manager().get_current_session_user() permission_id = Permission.get_id_for_permission(permission) if permission_id is None: raise UserException(UserException.get_msg(5, permission)) if not ignore_check and not session_user.check_permission(permission): raise UserException(UserException.get_msg(6)) stmnt = "UPDATE OR INSERT INTO USERRIGHTS VALUES (?,?) MATCHING (URI_USR_ID,URI_RIG_ID) ;" db.query(stmnt,(self._id,permission_id),commit=True) PokeManager().add_activity(ActivityType.USER)
def revoke_permission(self,permission, ignore_check=False): """ revokes a permission from the user """ db = Database() session_user = None if self.get_id() == ROOT_USER_ID and self.get_name() == "root": raise UserException(UserException.get_msg(16)) if not ignore_check: session_user = Session.get_current_session_user() permission_id = Permission.get_id_for_permission(permission) if permission_id is None: raise UserException(UserException.get_msg(5, permission)) if not ignore_check and not session_user.check_permission(permission): raise UserException(UserException.get_msg(8)) stmnt = "DELETE FROM USERRIGHTS WHERE URI_USR_ID = ? AND URI_RIG_ID = ? ;" db.query(stmnt,(self._id,permission_id),commit=True) PokeManager().add_activity(ActivityType.USER)
def get_grantable_permissions(self): """ get the permissions that can be assigned to this user returns list of strings """ return Permission.get_grantable_permissions(self)
def get_roles(self): """ returns roles this user is assigned to as list of strings """ return Permission.get_roles_for_user(self)
def get_permissions(self): """ returns the permissions of this user as list of strings """ return Permission.get_permissions_for_user(self)
def has_role(self, role): """ checks if this user has the given role """ return Permission.has_role_user(role,self)