Skip to content

Commit

Permalink
Merge branch 'main' into feat/core
Browse files Browse the repository at this point in the history
  • Loading branch information
caio-felipee committed Jan 20, 2025
1 parent 4e6fdef commit b784a22
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 33 deletions.
2 changes: 1 addition & 1 deletion backend/src/api/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 1 addition & 23 deletions backend/src/core/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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()

8 changes: 1 addition & 7 deletions backend/src/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
3 changes: 1 addition & 2 deletions backend/src/initial_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -13,7 +13,6 @@ def init() -> None:

with Session(engine) as session:
create_first_superuser(session)
update_permissions(session)


def main() -> None:
Expand Down

0 comments on commit b784a22

Please sign in to comment.