mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-29 13:25:50 +02:00
Support svg navigation items (#2542)
* Support SVG nav items * Handle specifying custom SVGs for navbar * Add comment * More comment * More comment
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from typing import Any
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel
|
||||
@@ -6,8 +7,20 @@ from pydantic import Field
|
||||
|
||||
class NavigationItem(BaseModel):
|
||||
link: str
|
||||
icon: str
|
||||
title: str
|
||||
# Right now must be one of the FA icons
|
||||
icon: str | None = None
|
||||
# NOTE: SVG must not have a width / height specified
|
||||
# This is the actual SVG as a string. Done this way to reduce
|
||||
# complexity / having to store additional "logos" in Postgres
|
||||
svg_logo: str | None = None
|
||||
|
||||
@classmethod
|
||||
def model_validate(cls, *args: Any, **kwargs: Any) -> "NavigationItem":
|
||||
instance = super().model_validate(*args, **kwargs)
|
||||
if bool(instance.icon) == bool(instance.svg_logo):
|
||||
raise ValueError("Exactly one of fa_icon or svg_logo must be specified")
|
||||
return instance
|
||||
|
||||
|
||||
class EnterpriseSettings(BaseModel):
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import json
|
||||
import os
|
||||
from copy import deepcopy
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
|
||||
@@ -22,6 +23,7 @@ from ee.danswer.db.standard_answer import (
|
||||
)
|
||||
from ee.danswer.server.enterprise_settings.models import AnalyticsScriptUpload
|
||||
from ee.danswer.server.enterprise_settings.models import EnterpriseSettings
|
||||
from ee.danswer.server.enterprise_settings.models import NavigationItem
|
||||
from ee.danswer.server.enterprise_settings.store import store_analytics_script
|
||||
from ee.danswer.server.enterprise_settings.store import (
|
||||
store_settings as store_ee_settings,
|
||||
@@ -44,6 +46,13 @@ logger = setup_logger()
|
||||
_SEED_CONFIG_ENV_VAR_NAME = "ENV_SEED_CONFIGURATION"
|
||||
|
||||
|
||||
class NavigationItemSeed(BaseModel):
|
||||
link: str
|
||||
title: str
|
||||
# NOTE: SVG at this path must not have a width / height specified
|
||||
svg_path: str
|
||||
|
||||
|
||||
class SeedConfiguration(BaseModel):
|
||||
llms: list[LLMProviderUpsertRequest] | None = None
|
||||
admin_user_emails: list[str] | None = None
|
||||
@@ -51,6 +60,10 @@ class SeedConfiguration(BaseModel):
|
||||
personas: list[CreatePersonaRequest] | None = None
|
||||
settings: Settings | None = None
|
||||
enterprise_settings: EnterpriseSettings | None = None
|
||||
|
||||
# allows for specifying custom navigation items that have your own custom SVG logos
|
||||
nav_item_overrides: list[NavigationItemSeed] | None = None
|
||||
|
||||
# Use existing `CUSTOM_ANALYTICS_SECRET_KEY` for reference
|
||||
analytics_script_path: str | None = None
|
||||
custom_tools: List[CustomToolSeed] | None = None
|
||||
@@ -60,7 +73,7 @@ def _parse_env() -> SeedConfiguration | None:
|
||||
seed_config_str = os.getenv(_SEED_CONFIG_ENV_VAR_NAME)
|
||||
if not seed_config_str:
|
||||
return None
|
||||
seed_config = SeedConfiguration.parse_raw(seed_config_str)
|
||||
seed_config = SeedConfiguration.model_validate_json(seed_config_str)
|
||||
return seed_config
|
||||
|
||||
|
||||
@@ -152,9 +165,35 @@ def _seed_settings(settings: Settings) -> None:
|
||||
|
||||
|
||||
def _seed_enterprise_settings(seed_config: SeedConfiguration) -> None:
|
||||
if seed_config.enterprise_settings is not None:
|
||||
if (
|
||||
seed_config.enterprise_settings is not None
|
||||
or seed_config.nav_item_overrides is not None
|
||||
):
|
||||
final_enterprise_settings = (
|
||||
deepcopy(seed_config.enterprise_settings)
|
||||
if seed_config.enterprise_settings
|
||||
else EnterpriseSettings()
|
||||
)
|
||||
|
||||
final_nav_items = final_enterprise_settings.custom_nav_items
|
||||
if seed_config.nav_item_overrides is not None:
|
||||
final_nav_items = []
|
||||
for item in seed_config.nav_item_overrides:
|
||||
with open(item.svg_path, "r") as file:
|
||||
svg_content = file.read().strip()
|
||||
|
||||
final_nav_items.append(
|
||||
NavigationItem(
|
||||
link=item.link,
|
||||
title=item.title,
|
||||
svg_logo=svg_content,
|
||||
)
|
||||
)
|
||||
|
||||
final_enterprise_settings.custom_nav_items = final_nav_items
|
||||
|
||||
logger.notice("Seeding enterprise settings")
|
||||
store_ee_settings(seed_config.enterprise_settings)
|
||||
store_ee_settings(final_enterprise_settings)
|
||||
|
||||
|
||||
def _seed_logo(db_session: Session, logo_path: str | None) -> None:
|
||||
|
Reference in New Issue
Block a user