SurfSense/surfsense_backend/app/schemas/site_configuration.py
Ojārs Kapteinis b8bb74ec3e Add disable_registration toggle to site configuration
Implemented comprehensive registration control system that allows administrators to disable new user registrations through the admin panel. This provides better control over user access and supports closed registration scenarios.

Backend changes:
- Added disable_registration field to SiteConfiguration model (db.py)
- Created migration #39 to add disable_registration column with default false
- Updated SiteConfigurationBase, Update, and Read schemas
- Enhanced registration_allowed() dependency to check database toggle
- Returns 403 with clear message when registration is disabled

Frontend changes:
- Added disable_registration to SiteConfig interface and default config
- Updated LocalLoginForm to conditionally hide "Sign up" link when disabled
- Added RouteGuard support for "registration" route key
- Protected /register page with RouteGuard (shows 404 when disabled)
- Added "Registration Control" section to admin site-settings page

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-18 14:28:16 +02:00

62 lines
1.9 KiB
Python

from pydantic import BaseModel, Field
class SiteConfigurationBase(BaseModel):
# Header/Navbar toggles
show_pricing_link: bool = False
show_docs_link: bool = False
show_github_link: bool = False
show_sign_in: bool = True
# Homepage toggles
show_get_started_button: bool = False
show_talk_to_us_button: bool = False
# Footer toggles
show_pages_section: bool = False
show_legal_section: bool = False
show_register_section: bool = False
# Route disabling
disable_pricing_route: bool = True
disable_docs_route: bool = True
disable_contact_route: bool = True
disable_terms_route: bool = True
disable_privacy_route: bool = True
# Registration control
disable_registration: bool = False
# Custom text
custom_copyright: str | None = Field(default="SurfSense 2025", max_length=200)
class SiteConfigurationUpdate(SiteConfigurationBase):
"""Schema for updating site configuration (all fields optional)"""
show_pricing_link: bool | None = None
show_docs_link: bool | None = None
show_github_link: bool | None = None
show_sign_in: bool | None = None
show_get_started_button: bool | None = None
show_talk_to_us_button: bool | None = None
show_pages_section: bool | None = None
show_legal_section: bool | None = None
show_register_section: bool | None = None
disable_pricing_route: bool | None = None
disable_docs_route: bool | None = None
disable_contact_route: bool | None = None
disable_terms_route: bool | None = None
disable_privacy_route: bool | None = None
disable_registration: bool | None = None
custom_copyright: str | None = None
class SiteConfigurationRead(SiteConfigurationBase):
id: int
model_config = {"from_attributes": True}
class SiteConfigurationPublic(SiteConfigurationBase):
"""Public-facing schema (same as base, but explicitly named for clarity)"""
pass