from sqlalchemy.orm import Session from passlib.context import CryptContext from . import models, schemas def get_user(db: Session, name: str): return (db .query(models.User) .filter(models.User.name == name).first()) def create_user( db: Session, user: schemas.UserCreate, capabilities: list[str], crypt_context: CryptContext, ): db_user = models.User( name=user.name, password=crypt_context.hash(user.password), capabilities=[ models.UserCapability(capability=capability) for capability in capabilities ] ) db.add(db_user) db.commit() db.refresh(db_user) return db_user