- Implemented role-based access control for project and scenario routes. - Added authorization checks to ensure users have appropriate roles for viewing and managing projects and scenarios. - Introduced utility functions for ensuring project and scenario access based on user roles. - Refactored project and scenario routes to utilize new authorization helpers. - Created initial data seeding script to set up default roles and an admin user. - Added tests for authorization helpers and initial data seeding functionality. - Updated exception handling to include authorization errors.
29 lines
782 B
Python
29 lines
782 B
Python
"""Domain-level exceptions for service and repository layers."""
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Sequence
|
|
|
|
|
|
class EntityNotFoundError(Exception):
|
|
"""Raised when a requested entity cannot be located."""
|
|
|
|
|
|
class EntityConflictError(Exception):
|
|
"""Raised when attempting to create or update an entity that violates uniqueness."""
|
|
|
|
|
|
class AuthorizationError(Exception):
|
|
"""Raised when a user lacks permission to perform an action."""
|
|
|
|
|
|
@dataclass(eq=False)
|
|
class ScenarioValidationError(Exception):
|
|
"""Raised when scenarios fail comparison validation rules."""
|
|
|
|
code: str
|
|
message: str
|
|
scenario_ids: Sequence[int] | None = None
|
|
|
|
def __str__(self) -> str: # pragma: no cover - mirrors message for logging
|
|
return self.message
|