diff --git a/backend/src/api/deps.py b/backend/src/api/deps.py index f8da3ce..0d789c9 100644 --- a/backend/src/api/deps.py +++ b/backend/src/api/deps.py @@ -11,7 +11,7 @@ from src.core import security from src.core.config import settings from src.core.db import engine -from src.models.user import TokenPayload, User, Permission, UserPermission +from src.models.user import TokenPayload, User reusable_oauth2 = OAuth2PasswordBearer( tokenUrl=f"{settings.API_STR}/login/access-token" diff --git a/backend/src/core/db.py b/backend/src/core/db.py index f1c259a..94b058f 100644 --- a/backend/src/core/db.py +++ b/backend/src/core/db.py @@ -3,8 +3,7 @@ from src import crud from src.core.config import settings -from src.models.user import User, UserCreate, Permission -from src.constants import PERMISSIONS +from src.models.user import User, UserCreate engine = create_engine(str(settings.SQLALCHEMY_DATABASE_URI)) @@ -36,24 +35,3 @@ def create_first_superuser(session: Session) -> None: is_superuser=True, ) user = crud.create_user(session=session, user_create=user_in) - - -def update_permissions(session: Session) -> None: - permissions_db = session.exec(select(Permission)).all() - permissions_names = [permission["name"] for permission in PERMISSIONS] - - for permission in permissions_db: - if permission.name not in permissions_names: - session.delete(permission) - - for permission in PERMISSIONS: - perm = session.exec( - select(Permission).where(Permission.name == permission["name"]) - ).first() - if not perm: - perm = Permission( - name=permission["name"], description=permission["description"] - ) - session.add(perm) - session.commit() - diff --git a/backend/src/crud.py b/backend/src/crud.py index 832c534..a1b3f52 100644 --- a/backend/src/crud.py +++ b/backend/src/crud.py @@ -2,7 +2,7 @@ from src.core.security import get_password_hash, verify_password -from src.models.user import User, UserCreate, Permission, UserUpdate +from src.models.user import User, UserCreate, UserUpdate def create_user(*, session: Session, user_create: UserCreate) -> User: @@ -44,9 +44,3 @@ def authenticate(*, session: Session, username: str, password: str) -> User | No if not verify_password(password, db_user.hashed_password): return None return db_user - - -def get_permission_by_name(*, session: Session, name: str) -> Permission | None: - statement = select(Permission).where(Permission.name == name) - permission = session.exec(statement).first() - return permission diff --git a/backend/src/initial_data.py b/backend/src/initial_data.py index 3319da5..5fa2fe9 100644 --- a/backend/src/initial_data.py +++ b/backend/src/initial_data.py @@ -2,7 +2,7 @@ from sqlmodel import Session -from src.core.db import engine, init_db, update_permissions, create_first_superuser +from src.core.db import engine, init_db, create_first_superuser logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) @@ -13,7 +13,6 @@ def init() -> None: with Session(engine) as session: create_first_superuser(session) - update_permissions(session) def main() -> None: