Add 'use main stack settings' toggle for third-party integration credentials
Each of Newbook, Resos, SambaPOS, SMTP, and Nextcloud now has a checkbox at the top of its credentials block. When enabled, the app reads auth credentials from the central stack settings service (SETTINGS_URL + STACK_INTERNAL_SECRET) and the local auth fields are grayed out. App-specific fields (base path, GL codes, keywords, sync intervals, etc.) remain editable regardless. Backend: new use_global_* columns on kitchen_settings, migration, global_settings_service with apply_global_overrides() for in-memory credential injection, GET /api/settings/global-status endpoint, and apply_global_overrides() called in test-connection endpoints and FileArchivalService. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
62417d59de
commit
d7898ba897
10 changed files with 356 additions and 34 deletions
|
|
@ -45,6 +45,7 @@ class NewbookSettingsResponse(BaseModel):
|
|||
newbook_dinner_gl_codes: str | None
|
||||
newbook_breakfast_vat_rate: Decimal | None
|
||||
newbook_dinner_vat_rate: Decimal | None
|
||||
use_global_newbook: bool = False
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
|
@ -63,6 +64,7 @@ class NewbookSettingsUpdate(BaseModel):
|
|||
newbook_dinner_gl_codes: str | None = None
|
||||
newbook_breakfast_vat_rate: Decimal | None = None
|
||||
newbook_dinner_vat_rate: Decimal | None = None
|
||||
use_global_newbook: bool | None = None
|
||||
|
||||
|
||||
class GLAccountResponse(BaseModel):
|
||||
|
|
@ -232,7 +234,8 @@ async def get_newbook_settings(
|
|||
newbook_breakfast_gl_codes=settings.newbook_breakfast_gl_codes,
|
||||
newbook_dinner_gl_codes=settings.newbook_dinner_gl_codes,
|
||||
newbook_breakfast_vat_rate=settings.newbook_breakfast_vat_rate,
|
||||
newbook_dinner_vat_rate=settings.newbook_dinner_vat_rate
|
||||
newbook_dinner_vat_rate=settings.newbook_dinner_vat_rate,
|
||||
use_global_newbook=settings.use_global_newbook,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -285,7 +288,8 @@ async def update_newbook_settings(
|
|||
newbook_breakfast_gl_codes=settings.newbook_breakfast_gl_codes,
|
||||
newbook_dinner_gl_codes=settings.newbook_dinner_gl_codes,
|
||||
newbook_breakfast_vat_rate=settings.newbook_breakfast_vat_rate,
|
||||
newbook_dinner_vat_rate=settings.newbook_dinner_vat_rate
|
||||
newbook_dinner_vat_rate=settings.newbook_dinner_vat_rate,
|
||||
use_global_newbook=settings.use_global_newbook,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -334,6 +338,9 @@ async def test_newbook_connection(
|
|||
if not settings:
|
||||
raise HTTPException(status_code=404, detail="Settings not found")
|
||||
|
||||
from services.global_settings_service import apply_global_overrides
|
||||
await apply_global_overrides(settings)
|
||||
|
||||
if not all([
|
||||
settings.newbook_api_username,
|
||||
settings.newbook_api_password,
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class ResosSettingsResponse(BaseModel):
|
|||
resos_arrival_widget_service_filter: str | None # Service type: breakfast/lunch/dinner/other
|
||||
sambapos_food_gl_codes: str | None # Phase 8.1
|
||||
sambapos_beverage_gl_codes: str | None # Phase 8.1
|
||||
use_global_resos: bool = False
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
|
@ -67,6 +68,7 @@ class ResosSettingsUpdate(BaseModel):
|
|||
resos_arrival_widget_service_filter: str | None = None # Opening hour ID for arrivals widget filter
|
||||
sambapos_food_gl_codes: str | None = None # Phase 8.1
|
||||
sambapos_beverage_gl_codes: str | None = None # Phase 8.1
|
||||
use_global_resos: bool | None = None
|
||||
|
||||
|
||||
class DailyStatsResponse(BaseModel):
|
||||
|
|
@ -149,7 +151,8 @@ async def get_resos_settings(
|
|||
resos_flag_icon_mapping=settings.resos_flag_icon_mapping,
|
||||
resos_arrival_widget_service_filter=settings.resos_arrival_widget_service_filter,
|
||||
sambapos_food_gl_codes=settings.sambapos_food_gl_codes, # Phase 8.1
|
||||
sambapos_beverage_gl_codes=settings.sambapos_beverage_gl_codes # Phase 8.1
|
||||
sambapos_beverage_gl_codes=settings.sambapos_beverage_gl_codes, # Phase 8.1
|
||||
use_global_resos=settings.use_global_resos or False,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -203,6 +206,8 @@ async def update_resos_settings(
|
|||
settings.sambapos_food_gl_codes = update.sambapos_food_gl_codes
|
||||
if update.sambapos_beverage_gl_codes is not None:
|
||||
settings.sambapos_beverage_gl_codes = update.sambapos_beverage_gl_codes
|
||||
if update.use_global_resos is not None:
|
||||
settings.use_global_resos = update.use_global_resos
|
||||
|
||||
await db.commit()
|
||||
logger.info(f"[Resos PATCH] After commit - upcoming_sync_enabled={settings.resos_upcoming_sync_enabled}")
|
||||
|
|
@ -220,6 +225,9 @@ async def test_resos_connection(
|
|||
)
|
||||
settings = result.scalar_one()
|
||||
|
||||
from services.global_settings_service import apply_global_overrides
|
||||
await apply_global_overrides(settings)
|
||||
|
||||
if not settings.resos_api_key:
|
||||
raise HTTPException(status_code=400, detail="Resos API key not configured")
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ class SambaPOSSettingsResponse(BaseModel):
|
|||
sambapos_db_password_set: bool
|
||||
sambapos_tracked_categories: list[str]
|
||||
sambapos_excluded_items: list[str]
|
||||
use_global_sambapos: bool = False
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
|
@ -38,6 +39,7 @@ class SambaPOSSettingsUpdate(BaseModel):
|
|||
sambapos_db_name: str | None = None
|
||||
sambapos_db_username: str | None = None
|
||||
sambapos_db_password: str | None = None
|
||||
use_global_sambapos: bool | None = None
|
||||
|
||||
|
||||
class CategoryResponse(BaseModel):
|
||||
|
|
@ -91,7 +93,8 @@ async def get_sambapos_settings(
|
|||
sambapos_db_username=settings.sambapos_db_username,
|
||||
sambapos_db_password_set=bool(settings.sambapos_db_password),
|
||||
sambapos_tracked_categories=tracked_categories,
|
||||
sambapos_excluded_items=excluded_items
|
||||
sambapos_excluded_items=excluded_items,
|
||||
use_global_sambapos=settings.use_global_sambapos or False,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -136,7 +139,8 @@ async def update_sambapos_settings(
|
|||
sambapos_db_username=settings.sambapos_db_username,
|
||||
sambapos_db_password_set=bool(settings.sambapos_db_password),
|
||||
sambapos_tracked_categories=tracked_categories,
|
||||
sambapos_excluded_items=excluded_items
|
||||
sambapos_excluded_items=excluded_items,
|
||||
use_global_sambapos=settings.use_global_sambapos or False,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -154,6 +158,9 @@ async def test_sambapos_connection(
|
|||
if not settings:
|
||||
raise HTTPException(status_code=404, detail="Settings not found")
|
||||
|
||||
from services.global_settings_service import apply_global_overrides
|
||||
await apply_global_overrides(settings)
|
||||
|
||||
if not all([
|
||||
settings.sambapos_db_host,
|
||||
settings.sambapos_db_name,
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ class SettingsResponse(BaseModel):
|
|||
llm_confidence_threshold: float | None = None
|
||||
llm_monthly_token_limit: int = 500000
|
||||
llm_features_enabled: dict | None = None
|
||||
# Global stack settings delegation
|
||||
use_global_smtp: bool = False
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
|
@ -92,6 +94,8 @@ class SettingsUpdate(BaseModel):
|
|||
llm_confidence_threshold: float | None = None
|
||||
llm_monthly_token_limit: int | None = None
|
||||
llm_features_enabled: dict | None = None
|
||||
# Global stack settings delegation
|
||||
use_global_smtp: bool | None = None
|
||||
|
||||
|
||||
@router.get("/", response_model=SettingsResponse)
|
||||
|
|
@ -158,6 +162,7 @@ def _build_settings_response(settings: KitchenSettings) -> SettingsResponse:
|
|||
llm_confidence_threshold=float(settings.llm_confidence_threshold) if settings.llm_confidence_threshold else None,
|
||||
llm_monthly_token_limit=settings.llm_monthly_token_limit,
|
||||
llm_features_enabled=settings.llm_features_enabled,
|
||||
use_global_smtp=settings.use_global_smtp,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -237,7 +242,13 @@ async def test_smtp_connection(
|
|||
)
|
||||
settings = result.scalar_one_or_none()
|
||||
|
||||
if not settings or not settings.smtp_host or not settings.smtp_from_email:
|
||||
if not settings:
|
||||
raise HTTPException(status_code=400, detail="SMTP not configured")
|
||||
|
||||
from services.global_settings_service import apply_global_overrides
|
||||
await apply_global_overrides(settings)
|
||||
|
||||
if not settings.smtp_host or not settings.smtp_from_email:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="SMTP not fully configured. Please set SMTP host and from email."
|
||||
|
|
@ -404,6 +415,7 @@ class NextcloudSettingsResponse(BaseModel):
|
|||
nextcloud_base_path: str | None
|
||||
nextcloud_enabled: bool
|
||||
nextcloud_delete_local: bool
|
||||
use_global_nextcloud: bool = False
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
|
@ -416,6 +428,7 @@ class NextcloudSettingsUpdate(BaseModel):
|
|||
nextcloud_base_path: str | None = None
|
||||
nextcloud_enabled: bool | None = None
|
||||
nextcloud_delete_local: bool | None = None
|
||||
use_global_nextcloud: bool | None = None
|
||||
|
||||
|
||||
class NextcloudStatsResponse(BaseModel):
|
||||
|
|
@ -450,7 +463,8 @@ async def get_nextcloud_settings(
|
|||
nextcloud_password_set=False,
|
||||
nextcloud_base_path="/Kitchen Invoices",
|
||||
nextcloud_enabled=False,
|
||||
nextcloud_delete_local=False
|
||||
nextcloud_delete_local=False,
|
||||
use_global_nextcloud=False,
|
||||
)
|
||||
|
||||
return NextcloudSettingsResponse(
|
||||
|
|
@ -459,7 +473,8 @@ async def get_nextcloud_settings(
|
|||
nextcloud_password_set=bool(settings.nextcloud_password),
|
||||
nextcloud_base_path=settings.nextcloud_base_path,
|
||||
nextcloud_enabled=settings.nextcloud_enabled,
|
||||
nextcloud_delete_local=settings.nextcloud_delete_local
|
||||
nextcloud_delete_local=settings.nextcloud_delete_local,
|
||||
use_global_nextcloud=settings.use_global_nextcloud,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -499,10 +514,20 @@ async def update_nextcloud_settings(
|
|||
nextcloud_password_set=bool(settings.nextcloud_password),
|
||||
nextcloud_base_path=settings.nextcloud_base_path,
|
||||
nextcloud_enabled=settings.nextcloud_enabled,
|
||||
nextcloud_delete_local=settings.nextcloud_delete_local
|
||||
nextcloud_delete_local=settings.nextcloud_delete_local,
|
||||
use_global_nextcloud=settings.use_global_nextcloud,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/global-status")
|
||||
async def get_global_status(
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Check which integrations are configured in the central stack settings service."""
|
||||
from services.global_settings_service import check_global_status
|
||||
return await check_global_status()
|
||||
|
||||
|
||||
@router.post("/nextcloud/test")
|
||||
async def test_nextcloud_connection(
|
||||
current_user: User = Depends(get_current_user),
|
||||
|
|
@ -516,7 +541,13 @@ async def test_nextcloud_connection(
|
|||
)
|
||||
settings = result.scalar_one_or_none()
|
||||
|
||||
if not settings or not all([settings.nextcloud_host, settings.nextcloud_username, settings.nextcloud_password]):
|
||||
if not settings:
|
||||
raise HTTPException(status_code=400, detail="Nextcloud not fully configured")
|
||||
|
||||
from services.global_settings_service import apply_global_overrides
|
||||
await apply_global_overrides(settings)
|
||||
|
||||
if not all([settings.nextcloud_host, settings.nextcloud_username, settings.nextcloud_password]):
|
||||
raise HTTPException(status_code=400, detail="Nextcloud not fully configured")
|
||||
|
||||
nc = NextcloudService(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue