def create_one( self, user: User, workspace: Workspace, role_level: int, with_notif: bool, flush: bool=True ) -> UserRoleInWorkspace: # INFO - G.M - 2018-10-29 - Check if role already exist query = self._get_one_rsc(user.user_id, workspace.workspace_id) if query.count() > 0: raise RoleAlreadyExistError( 'Role already exist for user {} in workspace {}.'.format( user.user_id, workspace.workspace_id ) ) role = UserRoleInWorkspace() role.user_id = user.user_id role.workspace = workspace role.role = role_level role.do_notify = with_notif if flush: self._session.flush() return role
def update_role( self, role: UserRoleInWorkspace, role_level: int, with_notif: typing.Optional[bool] = None, save_now: bool = False, ): """ Update role of user in this workspace :param role: UserRoleInWorkspace object :param role_level: level of new role wanted :param with_notif: is user notification enabled in this workspace ? :param save_now: database flush :return: updated role """ role.role = role_level if with_notif is not None: role.do_notify = with_notif if save_now: self.save(role) return role
def update_role( self, role: UserRoleInWorkspace, role_level: int, with_notif: typing.Optional[bool] = None, save_now: bool=False, ): """ Update role of user in this workspace :param role: UserRoleInWorkspace object :param role_level: level of new role wanted :param with_notif: is user notification enabled in this workspace ? :param save_now: database flush :return: updated role """ role.role = role_level if with_notif is not None: role.do_notify = with_notif if save_now: self.save(role) return role