功能:完善自定义主题与独立登录会话
This commit is contained in:
1 parent
3779bb69ef
commit
f1e53ef5c0
23 files changed
+1742
-196
No files matched your search
@@ -14,8 +14,10 @@ from app.gateway.auth.password import hash_password_async
|
||||
from app.gateway.deps import get_optional_user_from_request
|
||||
from deerflow.config import get_app_config
|
||||
from deerflow.config.system_settings import (
|
||||
BUILTIN_THEME_IDS,
|
||||
AppearanceRouteParam,
|
||||
CompactShortcutButton,
|
||||
CustomThemePreset,
|
||||
LeaderboardSettings,
|
||||
ModelConcurrencySettings,
|
||||
PluginDomainAgentMapping,
|
||||
@@ -24,7 +26,6 @@ from deerflow.config.system_settings import (
|
||||
PublishSquare,
|
||||
PublishSquaresSettings,
|
||||
SkillCompressionSettings,
|
||||
SystemSettings,
|
||||
get_module_tag_ids,
|
||||
list_publish_squares,
|
||||
load_system_settings,
|
||||
@@ -173,9 +174,7 @@ async def get_plugin_management() -> PluginManagementResponse:
|
||||
|
||||
|
||||
@router.put("/plugin-management", response_model=PluginManagementResponse)
|
||||
async def update_plugin_management(
|
||||
body: PluginManagementUpdateRequest, request: Request
|
||||
) -> PluginManagementResponse:
|
||||
async def update_plugin_management(body: PluginManagementUpdateRequest, request: Request) -> PluginManagementResponse:
|
||||
"""Replace the iframe plugin domain -> agent mappings. Admin only."""
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -201,12 +200,8 @@ async def update_plugin_management(
|
||||
)
|
||||
)
|
||||
|
||||
updated = current.plugin_management.model_copy(
|
||||
update={"domain_agent_mappings": mappings}
|
||||
)
|
||||
saved = save_system_settings(
|
||||
current.model_copy(update={"plugin_management": updated})
|
||||
)
|
||||
updated = current.plugin_management.model_copy(update={"domain_agent_mappings": mappings})
|
||||
saved = save_system_settings(current.model_copy(update={"plugin_management": updated}))
|
||||
return _plugin_management_to_response(saved.plugin_management)
|
||||
|
||||
|
||||
@@ -395,15 +390,9 @@ async def update_citation_display(
|
||||
await _require_admin(request)
|
||||
|
||||
current = load_system_settings()
|
||||
words = [
|
||||
str(item).strip()
|
||||
for item in (body.cleanup_words or [])
|
||||
if str(item).strip()
|
||||
]
|
||||
words = [str(item).strip() for item in (body.cleanup_words or []) if str(item).strip()]
|
||||
updated = current.citation_display.model_copy(update={"cleanup_words": words})
|
||||
saved = save_system_settings(
|
||||
current.model_copy(update={"citation_display": updated})
|
||||
)
|
||||
saved = save_system_settings(current.model_copy(update={"citation_display": updated}))
|
||||
return CitationDisplayResponse(cleanup_words=saved.citation_display.cleanup_words)
|
||||
|
||||
|
||||
@@ -536,21 +525,21 @@ async def update_publish_squares(body: PublishSquaresUpdateRequest, request: Req
|
||||
class AppearanceResponse(BaseModel):
|
||||
"""Effective system-wide appearance defaults."""
|
||||
|
||||
default_theme: Literal["light", "dark", "lightblue", "lightgreen", "iceblue", "lightyellow"] = Field(
|
||||
..., description="System default theme — light, dark, lightblue, lightgreen, iceblue or lightyellow"
|
||||
)
|
||||
default_theme: str = Field(..., description="System default theme — built-in id or enabled custom-theme-* id")
|
||||
default_skill_view: Literal["card", "list"] = Field(..., description="System default skill list display mode — card or list")
|
||||
default_agent_view: Literal["card", "list"] = Field(..., description="System default agent list display mode — card or list")
|
||||
default_layout_mode: Literal["full", "compact"] = Field(..., description="System default interface layout — full (sidebar + header) or compact (hidden)")
|
||||
compact_shortcut_buttons: list[CompactShortcutButton] = Field(default_factory=list, description="Shortcut buttons rendered in top bars")
|
||||
custom_themes: list[CustomThemePreset] = Field(default_factory=list, description="Administrator-managed runtime theme presets")
|
||||
|
||||
|
||||
class AppearanceUpdateRequest(BaseModel):
|
||||
default_theme: Literal["light", "dark", "lightblue", "lightgreen", "iceblue", "lightyellow"] | None = Field(default=None)
|
||||
default_theme: str | None = Field(default=None)
|
||||
default_skill_view: Literal["card", "list"] | None = Field(default=None)
|
||||
default_agent_view: Literal["card", "list"] | None = Field(default=None)
|
||||
default_layout_mode: Literal["full", "compact"] | None = Field(default=None)
|
||||
compact_shortcut_buttons: list[CompactShortcutButton] | None = Field(default=None)
|
||||
custom_themes: list[CustomThemePreset] | None = Field(default=None)
|
||||
|
||||
|
||||
def _normalize_compact_shortcut_buttons(
|
||||
@@ -576,8 +565,7 @@ def _normalize_compact_shortcut_buttons(
|
||||
AppearanceRouteParam(
|
||||
key=key,
|
||||
paramType="theme",
|
||||
themeValue=(param.themeValue or "").strip()
|
||||
or "red=red;green=green;blue=blue;dark-blue=dark-blue",
|
||||
themeValue=(param.themeValue or "").strip() or "red=red;green=green;blue=blue;dark-blue=dark-blue",
|
||||
)
|
||||
)
|
||||
continue
|
||||
@@ -588,9 +576,7 @@ def _normalize_compact_shortcut_buttons(
|
||||
key=key,
|
||||
paramType="login",
|
||||
source=source,
|
||||
customValue=(param.customValue or "").strip()
|
||||
if source == "other"
|
||||
else None,
|
||||
customValue=(param.customValue or "").strip() if source == "other" else None,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -617,9 +603,46 @@ def _appearance_response(appearance) -> AppearanceResponse:
|
||||
appearance.compact_shortcut_buttons,
|
||||
key=lambda item: item.sort_order,
|
||||
),
|
||||
custom_themes=sorted(appearance.custom_themes, key=lambda item: item.sort_order),
|
||||
)
|
||||
|
||||
|
||||
_MAX_CUSTOM_THEMES = 12
|
||||
|
||||
|
||||
def _normalize_custom_themes(themes: list[CustomThemePreset] | None) -> list[CustomThemePreset]:
|
||||
"""Reject unsafe/ambiguous theme rows and assign a deterministic order."""
|
||||
|
||||
source = themes or []
|
||||
if len(source) > _MAX_CUSTOM_THEMES:
|
||||
raise HTTPException(status_code=422, detail=f"At most {_MAX_CUSTOM_THEMES} custom themes are allowed")
|
||||
|
||||
normalized: list[CustomThemePreset] = []
|
||||
seen_ids: set[str] = set()
|
||||
seen_names: set[str] = set()
|
||||
for index, item in enumerate(source):
|
||||
if item.id in seen_ids:
|
||||
raise HTTPException(status_code=422, detail="Custom theme ids must be unique")
|
||||
name_key = item.name.casefold()
|
||||
if name_key in seen_names:
|
||||
raise HTTPException(status_code=422, detail="Custom theme names must be unique")
|
||||
seen_ids.add(item.id)
|
||||
seen_names.add(name_key)
|
||||
normalized.append(item.model_copy(update={"sort_order": index}))
|
||||
return normalized
|
||||
|
||||
|
||||
def _resolve_default_theme(theme_id: str | None, custom_themes: list[CustomThemePreset]) -> str:
|
||||
"""Keep defaults valid if an administrator disables or removes a preset."""
|
||||
|
||||
normalized = (theme_id or "").strip().lower()
|
||||
if normalized in BUILTIN_THEME_IDS:
|
||||
return normalized
|
||||
if any(item.id == normalized and item.enabled for item in custom_themes):
|
||||
return normalized
|
||||
return "light"
|
||||
|
||||
|
||||
@router.get("/appearance", response_model=AppearanceResponse)
|
||||
async def get_appearance_settings() -> AppearanceResponse:
|
||||
"""Return the global appearance defaults. Any logged-in user may read this."""
|
||||
@@ -627,27 +650,26 @@ async def get_appearance_settings() -> AppearanceResponse:
|
||||
|
||||
|
||||
@router.put("/appearance", response_model=AppearanceResponse)
|
||||
async def update_appearance_settings(
|
||||
body: AppearanceUpdateRequest, request: Request
|
||||
) -> AppearanceResponse:
|
||||
async def update_appearance_settings(body: AppearanceUpdateRequest, request: Request) -> AppearanceResponse:
|
||||
"""Update the global appearance defaults. Admin only."""
|
||||
await _require_admin(request)
|
||||
|
||||
current = load_system_settings()
|
||||
fields = body.model_dump(exclude_unset=True)
|
||||
update: dict[str, object] = {}
|
||||
for key in ("default_theme", "default_skill_view", "default_agent_view", "default_layout_mode"):
|
||||
for key in ("default_skill_view", "default_agent_view", "default_layout_mode"):
|
||||
if key in fields and fields[key] is not None:
|
||||
update[key] = fields[key]
|
||||
if "compact_shortcut_buttons" in fields and body.compact_shortcut_buttons is not None:
|
||||
update["compact_shortcut_buttons"] = _normalize_compact_shortcut_buttons(
|
||||
body.compact_shortcut_buttons
|
||||
)
|
||||
update["compact_shortcut_buttons"] = _normalize_compact_shortcut_buttons(body.compact_shortcut_buttons)
|
||||
custom_themes = _normalize_custom_themes(body.custom_themes) if "custom_themes" in fields and body.custom_themes is not None else list(current.appearance.custom_themes)
|
||||
if "custom_themes" in fields and body.custom_themes is not None:
|
||||
update["custom_themes"] = custom_themes
|
||||
requested_default = body.default_theme if "default_theme" in fields else current.appearance.default_theme
|
||||
update["default_theme"] = _resolve_default_theme(requested_default, custom_themes)
|
||||
if update:
|
||||
updated_appearance = current.appearance.model_copy(update=update)
|
||||
saved = save_system_settings(
|
||||
current.model_copy(update={"appearance": updated_appearance})
|
||||
)
|
||||
saved = save_system_settings(current.model_copy(update={"appearance": updated_appearance}))
|
||||
else:
|
||||
saved = current
|
||||
return _appearance_response(saved.appearance)
|
||||
@@ -723,9 +745,7 @@ async def get_agent_module_config(key: str) -> AgentModuleConfigResponse:
|
||||
|
||||
|
||||
@router.put("/agent-modules/{key}", response_model=AgentModuleConfigResponse)
|
||||
async def update_agent_module_config(
|
||||
key: str, body: AgentModuleConfigUpdateRequest, request: Request
|
||||
) -> AgentModuleConfigResponse:
|
||||
async def update_agent_module_config(key: str, body: AgentModuleConfigUpdateRequest, request: Request) -> AgentModuleConfigResponse:
|
||||
"""Replace the agent tag ids configured for ``key``. Admin only."""
|
||||
await _require_admin(request)
|
||||
|
||||
|
||||
Reference in new issue
Block a user