refac
This commit is contained in:
@@ -1704,12 +1704,12 @@ DEFAULT_MODEL_PARAMS = default_model_params
|
||||
|
||||
|
||||
try:
|
||||
default_ui_settings = JSONCodec.loads(os.getenv('DEFAULT_UI_SETTINGS', '{}'))
|
||||
default_interface_settings = JSONCodec.loads(os.getenv('DEFAULT_INTERFACE_SETTINGS', '{}'))
|
||||
except Exception as e:
|
||||
log.exception(f'Error loading DEFAULT_UI_SETTINGS: {e}')
|
||||
default_ui_settings = {}
|
||||
log.exception(f'Error loading DEFAULT_INTERFACE_SETTINGS: {e}')
|
||||
default_interface_settings = {}
|
||||
|
||||
DEFAULT_UI_SETTINGS = default_ui_settings if isinstance(default_ui_settings, dict) else {}
|
||||
DEFAULT_INTERFACE_SETTINGS = default_interface_settings if isinstance(default_interface_settings, dict) else {}
|
||||
|
||||
DEFAULT_USER_ROLE = os.getenv('DEFAULT_USER_ROLE', 'pending')
|
||||
|
||||
@@ -3064,7 +3064,7 @@ DEFAULT_CONFIG = {
|
||||
'ui.default_locale': DEFAULT_LOCALE,
|
||||
'ui.default_models': DEFAULT_MODELS,
|
||||
'ui.default_pinned_models': DEFAULT_PINNED_MODELS,
|
||||
'ui.default_settings': DEFAULT_UI_SETTINGS,
|
||||
'ui.default_interface_settings': DEFAULT_INTERFACE_SETTINGS,
|
||||
'ui.prompt_suggestions': DEFAULT_PROMPT_SUGGESTIONS,
|
||||
'ui.model_order_list': MODEL_ORDER_LIST,
|
||||
'models.default_metadata': DEFAULT_MODEL_METADATA,
|
||||
|
||||
@@ -2142,7 +2142,7 @@ async def get_app_config(request: Request):
|
||||
'memories.enable',
|
||||
'ui.default_models',
|
||||
'ui.default_pinned_models',
|
||||
'ui.default_settings',
|
||||
'ui.default_interface_settings',
|
||||
'ui.prompt_suggestions',
|
||||
'code_execution.engine',
|
||||
'code_interpreter.engine',
|
||||
@@ -2273,7 +2273,7 @@ async def get_app_config(request: Request):
|
||||
'sharepoint_tenant_id': ONEDRIVE_SHAREPOINT_TENANT_ID,
|
||||
},
|
||||
'ui': {
|
||||
'default_settings': config.get('ui.default_settings'),
|
||||
'default_interface_settings': config.get('ui.default_interface_settings'),
|
||||
'pending_user_overlay_title': config.get('ui.pending_user_overlay_title'),
|
||||
'pending_user_overlay_content': config.get('ui.pending_user_overlay_content'),
|
||||
'response_watermark': config.get('ui.watermark'),
|
||||
|
||||
@@ -32,7 +32,7 @@ DICT_CONFIG_KEY_ALIASES = {
|
||||
'audio.tts.openai.params': ('AUDIO_TTS_OPENAI_PARAMS',),
|
||||
'models.default_metadata': ('DEFAULT_MODEL_METADATA',),
|
||||
'models.default_params': ('DEFAULT_MODEL_PARAMS',),
|
||||
'ui.default_settings': ('DEFAULT_UI_SETTINGS',),
|
||||
'ui.default_interface_settings': ('DEFAULT_INTERFACE_SETTINGS',),
|
||||
'user.permissions': ('USER_PERMISSIONS',),
|
||||
}
|
||||
DICT_CONFIG_KEYS = tuple(DICT_CONFIG_KEY_ALIASES)
|
||||
|
||||
@@ -111,7 +111,7 @@ ADMIN_CONFIG_KEYS = {
|
||||
'API_KEYS_ALLOWED_ENDPOINTS': 'auth.api_key.allowed_endpoints',
|
||||
'DEFAULT_USER_ROLE': 'ui.default_user_role',
|
||||
'DEFAULT_GROUP_ID': 'ui.default_group_id',
|
||||
'DEFAULT_UI_SETTINGS': 'ui.default_settings',
|
||||
'DEFAULT_INTERFACE_SETTINGS': 'ui.default_interface_settings',
|
||||
'JWT_EXPIRES_IN': 'auth.jwt_expiry',
|
||||
'ENABLE_COMMUNITY_SHARING': 'ui.enable_community_sharing',
|
||||
'ENABLE_MESSAGE_RATING': 'ui.enable_message_rating',
|
||||
@@ -1197,7 +1197,7 @@ class AdminConfig(BaseModel):
|
||||
API_KEYS_ALLOWED_ENDPOINTS: str
|
||||
DEFAULT_USER_ROLE: str
|
||||
DEFAULT_GROUP_ID: str
|
||||
DEFAULT_UI_SETTINGS: dict | None = None
|
||||
DEFAULT_INTERFACE_SETTINGS: dict | None = None
|
||||
JWT_EXPIRES_IN: str
|
||||
ENABLE_COMMUNITY_SHARING: bool
|
||||
ENABLE_MESSAGE_RATING: bool
|
||||
@@ -1222,7 +1222,7 @@ class AdminConfig(BaseModel):
|
||||
@router.post('/admin/config')
|
||||
async def update_admin_config(request: Request, form_data: AdminConfig, user=Depends(get_admin_user)):
|
||||
updates = config_updates(form_data.model_dump(), ADMIN_CONFIG_KEYS)
|
||||
updates['ui.default_settings'] = form_data.DEFAULT_UI_SETTINGS or {}
|
||||
updates['ui.default_interface_settings'] = form_data.DEFAULT_INTERFACE_SETTINGS or {}
|
||||
updates['folders.max_file_count'] = int(form_data.FOLDER_MAX_FILE_COUNT) if form_data.FOLDER_MAX_FILE_COUNT else ''
|
||||
updates['automations.max_count'] = int(form_data.AUTOMATION_MAX_COUNT) if form_data.AUTOMATION_MAX_COUNT else ''
|
||||
updates['automations.min_interval'] = (
|
||||
|
||||
@@ -68,7 +68,7 @@ def merge_user_ui_settings(defaults: dict, settings: dict) -> dict:
|
||||
return merged
|
||||
|
||||
|
||||
def strip_default_ui_settings(defaults: dict, settings: dict) -> dict:
|
||||
def strip_default_interface_settings(defaults: dict, settings: dict) -> dict:
|
||||
stripped = {}
|
||||
for key, value in settings.items():
|
||||
if value is None:
|
||||
@@ -76,7 +76,7 @@ def strip_default_ui_settings(defaults: dict, settings: dict) -> dict:
|
||||
|
||||
default_value = defaults.get(key)
|
||||
if isinstance(default_value, dict) and isinstance(value, dict):
|
||||
nested = strip_default_ui_settings(default_value, value)
|
||||
nested = strip_default_interface_settings(default_value, value)
|
||||
if nested:
|
||||
stripped[key] = nested
|
||||
elif value != default_value:
|
||||
@@ -472,13 +472,13 @@ async def get_user_settings_by_session_user(
|
||||
user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session)
|
||||
):
|
||||
# user already fetched by get_verified_user — no need to refetch
|
||||
default_ui_settings = await Config.get('ui.default_settings')
|
||||
if not isinstance(default_ui_settings, dict) or not default_ui_settings:
|
||||
default_interface_settings = await Config.get('ui.default_interface_settings')
|
||||
if not isinstance(default_interface_settings, dict) or not default_interface_settings:
|
||||
return user.settings
|
||||
|
||||
user_settings = user.settings.model_dump() if isinstance(user.settings, UserSettings) else dict(user.settings or {})
|
||||
ui_settings = user_settings.get('ui') if isinstance(user_settings.get('ui'), dict) else {}
|
||||
user_settings['ui'] = merge_user_ui_settings(default_ui_settings, ui_settings)
|
||||
user_settings['ui'] = merge_user_ui_settings(default_interface_settings, ui_settings)
|
||||
|
||||
return UserSettings.model_validate(user_settings)
|
||||
|
||||
@@ -535,10 +535,10 @@ async def update_user_settings_by_session_user(
|
||||
if isinstance(ui_notifications, dict):
|
||||
ui_notifications.pop('webhook_url', None)
|
||||
|
||||
default_ui_settings = await Config.get('ui.default_settings')
|
||||
default_interface_settings = await Config.get('ui.default_interface_settings')
|
||||
ui_settings = updated_user_settings.get('ui')
|
||||
if isinstance(default_ui_settings, dict) and isinstance(ui_settings, dict):
|
||||
updated_user_settings['ui'] = strip_default_ui_settings(default_ui_settings, ui_settings)
|
||||
if isinstance(default_interface_settings, dict) and isinstance(ui_settings, dict):
|
||||
updated_user_settings['ui'] = strip_default_interface_settings(default_interface_settings, ui_settings)
|
||||
|
||||
user = await Users.update_user_settings_by_id(user.id, updated_user_settings, db=db)
|
||||
if user:
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
};
|
||||
|
||||
let adminConfig: any = null;
|
||||
let defaultUserUiSettings: Record<string, any> = {};
|
||||
let defaultInterfaceSettings: Record<string, any> = {};
|
||||
let showUserUiDefaults = false;
|
||||
|
||||
let banners: Banner[] = [];
|
||||
@@ -61,17 +61,17 @@
|
||||
_banners.set(await setBanners(localStorage.token, banners));
|
||||
};
|
||||
|
||||
const saveDefaultUserUiSettings = (updated: Record<string, any>) => {
|
||||
defaultUserUiSettings = { ...defaultUserUiSettings, ...updated };
|
||||
const saveDefaultInterfaceSettings = (updated: Record<string, any>) => {
|
||||
defaultInterfaceSettings = { ...defaultInterfaceSettings, ...updated };
|
||||
};
|
||||
|
||||
const getDefaultUserUiSettings = () => {
|
||||
const value = adminConfig?.DEFAULT_UI_SETTINGS;
|
||||
const getDefaultInterfaceSettings = () => {
|
||||
const value = adminConfig?.DEFAULT_INTERFACE_SETTINGS;
|
||||
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
||||
};
|
||||
|
||||
const updateHandler = async () => {
|
||||
adminConfig.DEFAULT_UI_SETTINGS = defaultUserUiSettings;
|
||||
adminConfig.DEFAULT_INTERFACE_SETTINGS = defaultInterfaceSettings;
|
||||
|
||||
const res = await updateAdminConfig(localStorage.token, adminConfig);
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
|
||||
onMount(async () => {
|
||||
adminConfig = await getAdminConfig(localStorage.token);
|
||||
defaultUserUiSettings = getDefaultUserUiSettings();
|
||||
defaultInterfaceSettings = getDefaultInterfaceSettings();
|
||||
|
||||
banners = [...$_banners];
|
||||
});
|
||||
@@ -416,15 +416,15 @@
|
||||
<div class="mt-0.5 space-y-2">
|
||||
<div class="flex items-center justify-between gap-4 py-0.5">
|
||||
<div class="text-[0.6875rem] text-gray-400 dark:text-gray-600">
|
||||
{Object.keys(defaultUserUiSettings).length} {$i18n.t('settings configured')}
|
||||
{Object.keys(defaultInterfaceSettings).length} {$i18n.t('settings configured')}
|
||||
</div>
|
||||
|
||||
{#if Object.keys(defaultUserUiSettings).length > 0}
|
||||
{#if Object.keys(defaultInterfaceSettings).length > 0}
|
||||
<button
|
||||
class="shrink-0 text-[0.6875rem] text-gray-400 transition hover:text-gray-700 dark:text-gray-600 dark:hover:text-gray-300"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
defaultUserUiSettings = {};
|
||||
defaultInterfaceSettings = {};
|
||||
}}
|
||||
>
|
||||
{$i18n.t('Clear')}
|
||||
@@ -434,8 +434,8 @@
|
||||
|
||||
<div class="max-h-[28rem] overflow-y-auto pb-2 pr-1 scrollbar-hover">
|
||||
<InterfaceSettings
|
||||
settingsValue={defaultUserUiSettings}
|
||||
saveSettings={saveDefaultUserUiSettings}
|
||||
settingsValue={defaultInterfaceSettings}
|
||||
saveSettings={saveDefaultInterfaceSettings}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
$: currentSettings = (settingsValue ?? $settings ?? {}) as Record<string, any>;
|
||||
$: externalSettings = settingsValue !== null;
|
||||
$: defaultSettings = ($config?.ui?.default_settings ?? {}) as Record<string, any>;
|
||||
$: defaultSettings = ($config?.ui?.default_interface_settings ?? {}) as Record<string, any>;
|
||||
|
||||
let backgroundImageUrl: string | null = null;
|
||||
let inputFiles: FileList | null = null;
|
||||
|
||||
@@ -342,7 +342,7 @@ type Config = {
|
||||
auto_redirect?: boolean;
|
||||
};
|
||||
ui?: {
|
||||
default_settings?: Record<string, unknown>;
|
||||
default_interface_settings?: Record<string, unknown>;
|
||||
pending_user_overlay_title?: string;
|
||||
pending_user_overlay_content?: string;
|
||||
response_watermark?: string;
|
||||
|
||||
Reference in New Issue
Block a user