- Introduced application-wide constants for file uploads, image processing, pagination, and authentication in `constants.py`. - Implemented synchronous and asynchronous board ownership verification functions in `ownership.py`. - Created a base repository class with common CRUD operations in `repository.py`. - Added standard response utilities for error and success messages in `responses.py`. - Refactored image validation to utilize constants for file size and MIME types. - Enhanced frontend components with consistent styling and validation utilities for forms. - Established global styles for buttons, forms, loading indicators, and messages to ensure a cohesive UI experience.
70 lines
1.7 KiB
Python
70 lines
1.7 KiB
Python
"""Ownership verification utilities."""
|
|
|
|
from uuid import UUID
|
|
|
|
from fastapi import HTTPException, status
|
|
from sqlalchemy import select
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.database.models.board import Board
|
|
|
|
|
|
def verify_board_ownership_sync(db: Session, board_id: UUID, user_id: UUID) -> Board:
|
|
"""
|
|
Verify board ownership (synchronous).
|
|
|
|
Args:
|
|
db: Database session
|
|
board_id: Board UUID
|
|
user_id: User UUID
|
|
|
|
Returns:
|
|
Board instance if owned by user
|
|
|
|
Raises:
|
|
HTTPException: 404 if board not found or not owned by user
|
|
"""
|
|
stmt = select(Board).where(
|
|
Board.id == board_id,
|
|
Board.user_id == user_id,
|
|
Board.is_deleted == False, # noqa: E712
|
|
)
|
|
|
|
board = db.execute(stmt).scalar_one_or_none()
|
|
|
|
if not board:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Board {board_id} not found")
|
|
|
|
return board
|
|
|
|
|
|
async def verify_board_ownership_async(db: AsyncSession, board_id: UUID, user_id: UUID) -> Board:
|
|
"""
|
|
Verify board ownership (asynchronous).
|
|
|
|
Args:
|
|
db: Async database session
|
|
board_id: Board UUID
|
|
user_id: User UUID
|
|
|
|
Returns:
|
|
Board instance if owned by user
|
|
|
|
Raises:
|
|
HTTPException: 404 if board not found or not owned by user
|
|
"""
|
|
stmt = select(Board).where(
|
|
Board.id == board_id,
|
|
Board.user_id == user_id,
|
|
Board.is_deleted == False, # noqa: E712
|
|
)
|
|
|
|
result = await db.execute(stmt)
|
|
board = result.scalar_one_or_none()
|
|
|
|
if not board:
|
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail=f"Board {board_id} not found")
|
|
|
|
return board
|