- Add "Show in Legal" checkbox to content page editor UI - Update API schemas (ContentPageCreate, ContentPageUpdate, ContentPageResponse) - Add show_in_legal parameter to service methods (create_page, update_page, etc.) - Fix ContentPageNotFoundException to pass identifier correctly - Fix UnauthorizedContentPageAccessException to use correct AuthorizationException API - Add comprehensive unit tests for ContentPageService (35 tests) - Add content page fixtures for testing - Update CMS documentation with navigation categories diagram 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
89 lines
2.9 KiB
Python
89 lines
2.9 KiB
Python
# app/exceptions/content_page.py
|
|
"""
|
|
Content Page Domain Exceptions
|
|
|
|
These exceptions are raised by the content page service layer
|
|
and converted to HTTP responses by the global exception handler.
|
|
"""
|
|
|
|
from app.exceptions.base import (
|
|
AuthorizationException,
|
|
BusinessLogicException,
|
|
ConflictException,
|
|
ResourceNotFoundException,
|
|
ValidationException,
|
|
)
|
|
|
|
|
|
class ContentPageNotFoundException(ResourceNotFoundException):
|
|
"""Raised when a content page is not found."""
|
|
|
|
def __init__(self, identifier: str | int | None = None):
|
|
if identifier:
|
|
message = f"Content page not found: {identifier}"
|
|
else:
|
|
message = "Content page not found"
|
|
super().__init__(
|
|
message=message,
|
|
resource_type="content_page",
|
|
identifier=str(identifier) if identifier else "unknown",
|
|
)
|
|
|
|
|
|
class ContentPageAlreadyExistsException(ConflictException):
|
|
"""Raised when a content page with the same slug already exists."""
|
|
|
|
def __init__(self, slug: str, vendor_id: int | None = None):
|
|
if vendor_id:
|
|
message = f"Content page with slug '{slug}' already exists for this vendor"
|
|
else:
|
|
message = f"Platform content page with slug '{slug}' already exists"
|
|
super().__init__(message=message)
|
|
|
|
|
|
class ContentPageSlugReservedException(ValidationException):
|
|
"""Raised when trying to use a reserved slug."""
|
|
|
|
def __init__(self, slug: str):
|
|
super().__init__(
|
|
message=f"Content page slug '{slug}' is reserved",
|
|
field="slug",
|
|
value=slug,
|
|
)
|
|
|
|
|
|
class ContentPageNotPublishedException(BusinessLogicException):
|
|
"""Raised when trying to access an unpublished content page."""
|
|
|
|
def __init__(self, slug: str):
|
|
super().__init__(message=f"Content page '{slug}' is not published")
|
|
|
|
|
|
class UnauthorizedContentPageAccessException(AuthorizationException):
|
|
"""Raised when a user tries to access/modify a content page they don't own."""
|
|
|
|
def __init__(self, action: str = "access"):
|
|
super().__init__(
|
|
message=f"Cannot {action} content pages from other vendors",
|
|
error_code="CONTENT_PAGE_ACCESS_DENIED",
|
|
details={"required_permission": f"content_page:{action}"},
|
|
)
|
|
|
|
|
|
class VendorNotAssociatedException(AuthorizationException):
|
|
"""Raised when a user is not associated with a vendor."""
|
|
|
|
def __init__(self):
|
|
super().__init__(
|
|
message="User is not associated with a vendor",
|
|
error_code="VENDOR_NOT_ASSOCIATED",
|
|
details={"required_permission": "vendor:member"},
|
|
)
|
|
|
|
|
|
class ContentPageValidationException(ValidationException):
|
|
"""Raised when content page data validation fails."""
|
|
|
|
def __init__(self, field: str, message: str, value: str | None = None):
|
|
super().__init__(message=message, field=field, value=value)
|