init
This commit is contained in:
@@ -5,6 +5,7 @@ from pydantic import BaseModel
|
|||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
|
from sqlalchemy.orm import selectinload
|
||||||
|
|
||||||
from database.database import get_db_session
|
from database.database import get_db_session
|
||||||
from services.auth_service import (
|
from services.auth_service import (
|
||||||
@@ -190,9 +191,7 @@ async def list_users(
|
|||||||
):
|
):
|
||||||
check_admin(current_user)
|
check_admin(current_user)
|
||||||
result = await db_session.execute(
|
result = await db_session.execute(
|
||||||
select(User).options(
|
select(User).options(selectinload(User.user_roles).selectinload(UserRole.role))
|
||||||
select(User).options()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
users = result.scalars().all()
|
users = result.scalars().all()
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from sqlalchemy.orm import selectinload
|
|||||||
|
|
||||||
from config.settings import settings
|
from config.settings import settings
|
||||||
from database.database import get_db_session
|
from database.database import get_db_session
|
||||||
from models.database import User
|
from models.database import User, UserRole
|
||||||
|
|
||||||
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
|
||||||
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/auth/login", auto_error=False)
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/auth/login", auto_error=False)
|
||||||
@@ -56,7 +56,7 @@ async def get_current_user(
|
|||||||
raise credentials_exception
|
raise credentials_exception
|
||||||
|
|
||||||
result = await db_session.execute(
|
result = await db_session.execute(
|
||||||
select(User).where(User.username == username)
|
select(User).options(selectinload(User.user_roles).selectinload(UserRole.role)).where(User.username == username)
|
||||||
)
|
)
|
||||||
user = result.scalar_one_or_none()
|
user = result.scalar_one_or_none()
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@ async def get_current_admin_user(
|
|||||||
|
|
||||||
async def authenticate_user(db_session: AsyncSession, username: str, password: str) -> Optional[User]:
|
async def authenticate_user(db_session: AsyncSession, username: str, password: str) -> Optional[User]:
|
||||||
result = await db_session.execute(
|
result = await db_session.execute(
|
||||||
select(User).where(User.username == username)
|
select(User).options(selectinload(User.user_roles).selectinload(UserRole.role)).where(User.username == username)
|
||||||
)
|
)
|
||||||
user = result.scalar_one_or_none()
|
user = result.scalar_one_or_none()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user