update: overhauled firmware ui. Added public flash page.
This commit is contained in:
10
backend/settings/public_features_models.py
Normal file
10
backend/settings/public_features_models.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class PublicFeaturesSettings(BaseModel):
|
||||
cloudflash_enabled: bool = False
|
||||
|
||||
|
||||
class PublicFeaturesSettingsUpdate(BaseModel):
|
||||
cloudflash_enabled: Optional[bool] = None
|
||||
31
backend/settings/public_features_service.py
Normal file
31
backend/settings/public_features_service.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from shared.firebase import get_db
|
||||
from settings.public_features_models import PublicFeaturesSettings, PublicFeaturesSettingsUpdate
|
||||
|
||||
COLLECTION = "admin_settings"
|
||||
DOC_ID = "public_features"
|
||||
|
||||
|
||||
def get_public_features() -> PublicFeaturesSettings:
|
||||
"""Get public features settings from Firestore. Creates defaults if not found."""
|
||||
db = get_db()
|
||||
doc = db.collection(COLLECTION).document(DOC_ID).get()
|
||||
if doc.exists:
|
||||
return PublicFeaturesSettings(**doc.to_dict())
|
||||
defaults = PublicFeaturesSettings()
|
||||
db.collection(COLLECTION).document(DOC_ID).set(defaults.model_dump())
|
||||
return defaults
|
||||
|
||||
|
||||
def update_public_features(data: PublicFeaturesSettingsUpdate) -> PublicFeaturesSettings:
|
||||
"""Update public features settings. Only provided fields are updated."""
|
||||
db = get_db()
|
||||
doc_ref = db.collection(COLLECTION).document(DOC_ID)
|
||||
doc = doc_ref.get()
|
||||
|
||||
existing = doc.to_dict() if doc.exists else PublicFeaturesSettings().model_dump()
|
||||
update_data = data.model_dump(exclude_none=True)
|
||||
existing.update(update_data)
|
||||
|
||||
normalized = PublicFeaturesSettings(**existing)
|
||||
doc_ref.set(normalized.model_dump())
|
||||
return normalized
|
||||
@@ -1,8 +1,11 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from auth.models import TokenPayload
|
||||
from auth.dependencies import require_permission
|
||||
from auth.dependencies import require_permission, require_roles
|
||||
from auth.models import Role
|
||||
from settings.models import MelodySettings, MelodySettingsUpdate
|
||||
from settings.public_features_models import PublicFeaturesSettings, PublicFeaturesSettingsUpdate
|
||||
from settings import service
|
||||
from settings import public_features_service
|
||||
|
||||
router = APIRouter(prefix="/api/settings", tags=["settings"])
|
||||
|
||||
@@ -20,3 +23,20 @@ async def update_melody_settings(
|
||||
_user: TokenPayload = Depends(require_permission("melodies", "edit")),
|
||||
):
|
||||
return service.update_melody_settings(body)
|
||||
|
||||
|
||||
# ── Public Features Settings (sysadmin / admin only) ─────────────────────────
|
||||
|
||||
@router.get("/public-features", response_model=PublicFeaturesSettings)
|
||||
async def get_public_features(
|
||||
_user: TokenPayload = Depends(require_roles(Role.sysadmin, Role.admin)),
|
||||
):
|
||||
return public_features_service.get_public_features()
|
||||
|
||||
|
||||
@router.put("/public-features", response_model=PublicFeaturesSettings)
|
||||
async def update_public_features(
|
||||
body: PublicFeaturesSettingsUpdate,
|
||||
_user: TokenPayload = Depends(require_roles(Role.sysadmin, Role.admin)),
|
||||
):
|
||||
return public_features_service.update_public_features(body)
|
||||
|
||||
Reference in New Issue
Block a user