Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
d677007
fix: user.role as str -> UserRole (enum)
HardMax71 Feb 9, 2026
14afff2
fix: removed try-catch from endpoint, conflict error is thrown by use…
HardMax71 Feb 9, 2026
b816cb8
fix: removed /verify-token - now all the stuff goes through /me in th…
HardMax71 Feb 9, 2026
b1ab356
fix: dlq/stats endpoint - removed; stats are exported out of dlq mana…
HardMax71 Feb 9, 2026
7250669
fix: e2e/conftest: - passing role as UserRole, not str
HardMax71 Feb 9, 2026
615f350
fix: dlq - only for admins, also one-liner for policy request -> retr…
HardMax71 Feb 9, 2026
b95e9ea
fix: events - model_validate instead of manual fields assignment; als…
HardMax71 Feb 9, 2026
b0aed8d
fix: exeuctions - ExecutionStatus enum instead of bare str
HardMax71 Feb 9, 2026
10f1640
fix: executions - moved business logic from endpoints to exec service…
HardMax71 Feb 10, 2026
01c3c23
fix: removed alert processing from backend side (set up stuff directl…
HardMax71 Feb 10, 2026
adc60f8
fix: health - removed ready endpoint (not used)
HardMax71 Feb 10, 2026
5b15068
fix: health - removed health objs (not used)
HardMax71 Feb 10, 2026
de1d4f6
fix: notifications - funcs returning bool now are void (cause they re…
HardMax71 Feb 10, 2026
4b1a224
fix: replay - model_validate + from_attrs=True
HardMax71 Feb 10, 2026
24717d5
fix: saga - current user through DI, not calling user service on site
HardMax71 Feb 10, 2026
cea8a65
fix: saved scripts - passing current user through DI
HardMax71 Feb 10, 2026
785fd12
fix: sse - current_user via DI and correct schemas in responses
HardMax71 Feb 10, 2026
79c5c0b
fix: user settings - better converting
HardMax71 Feb 10, 2026
64cf5c6
fix: detected issues
HardMax71 Feb 10, 2026
86fe4c3
fix: detected issues
HardMax71 Feb 10, 2026
77a0755
fix: reverted sse changes
HardMax71 Feb 10, 2026
baebf74
fix: sse response_class
HardMax71 Feb 10, 2026
920b025
fix: tests
HardMax71 Feb 10, 2026
c2343c1
fix: from+attr removed from endpoints (to schema defintions), update …
HardMax71 Feb 10, 2026
67e7d5c
fix: schema issue
HardMax71 Feb 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 13 additions & 33 deletions backend/app/api/routes/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
from dishka.integrations.fastapi import DishkaRoute
from fastapi import APIRouter, Depends, HTTPException, Request, Response
from fastapi.security import OAuth2PasswordRequestForm
from pymongo.errors import DuplicateKeyError

from app.core.security import SecurityService
from app.core.utils import get_client_ip
from app.db.repositories import UserRepository
from app.domain.exceptions import ConflictError
from app.domain.user import DomainUserCreate
from app.schemas_pydantic.common import ErrorResponse
from app.schemas_pydantic.user import (
Expand Down Expand Up @@ -124,7 +122,7 @@ async def login(
return LoginResponse(
message="Login successful",
username=user.username,
role="admin" if user.is_superuser else "user",
role=user.role,
csrf_token=csrf_token,
)

Expand Down Expand Up @@ -167,26 +165,16 @@ async def register(
)
raise HTTPException(status_code=400, detail="Username already registered")

try:
hashed_password = security_service.get_password_hash(user.password)
create_data = DomainUserCreate(
username=user.username,
email=str(user.email),
hashed_password=hashed_password,
role=user.role,
is_active=True,
is_superuser=False,
)
created_user = await user_repo.create_user(create_data)
except DuplicateKeyError as e:
logger.warning(
"Registration failed - duplicate email",
extra={
"username": user.username,
"client_ip": get_client_ip(request),
},
)
raise ConflictError("Email already registered") from e
hashed_password = security_service.get_password_hash(user.password)
create_data = DomainUserCreate(
username=user.username,
email=user.email,
hashed_password=hashed_password,
role=user.role,
is_active=True,
is_superuser=False,
)
Comment thread
HardMax71 marked this conversation as resolved.
created_user = await user_repo.create_user(create_data)

logger.info(
"Registration successful",
Expand All @@ -197,15 +185,7 @@ async def register(
},
)

return UserResponse(
user_id=created_user.user_id,
username=created_user.username,
email=created_user.email,
role=created_user.role,
is_superuser=created_user.is_superuser,
created_at=created_user.created_at,
updated_at=created_user.updated_at,
)
return UserResponse.model_validate(created_user, from_attributes=True)


@router.get("/me", response_model=UserResponse)
Expand Down Expand Up @@ -269,7 +249,7 @@ async def verify_token(
return TokenValidationResponse(
valid=True,
username=current_user.username,
role="admin" if current_user.is_superuser else "user",
role=current_user.role,
csrf_token=csrf_token,
)

Expand Down
7 changes: 6 additions & 1 deletion backend/app/db/repositories/user_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

from beanie.odm.operators.find import BaseFindOperator
from beanie.operators import Eq, Or, RegEx
from pymongo.errors import DuplicateKeyError

from app.db.docs import UserDocument
from app.domain.enums import UserRole
from app.domain.exceptions import ConflictError
from app.domain.user import DomainUserCreate, DomainUserUpdate, User, UserListResult


Expand All @@ -16,7 +18,10 @@ async def get_user(self, username: str) -> User | None:

async def create_user(self, create_data: DomainUserCreate) -> User:
doc = UserDocument(**create_data.model_dump())
await doc.insert()
try:
await doc.insert()
except DuplicateKeyError as e:
raise ConflictError("Email already registered") from e
Comment thread
HardMax71 marked this conversation as resolved.
Outdated
Comment thread
HardMax71 marked this conversation as resolved.
Outdated
return User.model_validate(doc, from_attributes=True)

async def get_user_by_id(self, user_id: str) -> User | None:
Expand Down
4 changes: 2 additions & 2 deletions backend/app/schemas_pydantic/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class LoginResponse(BaseModel):

message: str
username: str
role: str
role: UserRole
csrf_token: str

model_config = ConfigDict(from_attributes=True)
Expand All @@ -128,7 +128,7 @@ class TokenValidationResponse(BaseModel):

valid: bool
username: str
role: str
role: UserRole
csrf_token: str

model_config = ConfigDict(from_attributes=True)
Expand Down
Loading