def remove(cls, user: User, scope: str, name: str): permission = cls.get(scope=scope, name=name) if permission in user.permissions: index = user.permissions.index(permission) user.permissions.pop(index) user.save()
def signup(cls, username: str, email: str, password: str) -> User: user = User(email=email, username=username, password=auth.hashpwd(password)) user.save() return user
def update_avatar(cls, user: User, file: File): if user.avatar is not None: FileService.destroy(user.avatar) user.avatar = file user.save() return user
def update(cls, user: User, **kwargs): user = update_document(user, kwargs) user.save()
def add(cls, user: User, scope: str, name: str): permission = cls.get(scope=scope, name=name) if permission not in user.permissions: user.permissions.append(permission) user.save()