fix idp on started
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export type SystemSettingFieldType = 'text' | 'number' | 'boolean';
|
||||
export type SystemSettingFieldType = 'text' | 'number' | 'boolean' | 'select';
|
||||
|
||||
export interface SystemSettingMeta {
|
||||
key: string;
|
||||
@@ -7,6 +7,8 @@ export interface SystemSettingMeta {
|
||||
type: SystemSettingFieldType;
|
||||
unit?: string;
|
||||
hint?: string;
|
||||
options?: Array<{ value: string; label: string }>;
|
||||
showWhen?: { key: string; equals: string };
|
||||
}
|
||||
|
||||
export const SYSTEM_SETTING_GROUPS: Record<string, string> = {
|
||||
@@ -14,6 +16,7 @@ export const SYSTEM_SETTING_GROUPS: Record<string, string> = {
|
||||
pin: 'PIN-код и блокировка сессии',
|
||||
auth: 'Аутентификация и регистрация',
|
||||
ldap: 'LDAP / Active Directory',
|
||||
messaging: 'Email и SMS',
|
||||
limits: 'Лимиты и ограничения',
|
||||
media: 'Медиа и файлы'
|
||||
};
|
||||
@@ -47,6 +50,42 @@ export const SYSTEM_SETTING_CATALOG: SystemSettingMeta[] = [
|
||||
{ key: 'LDAP_USERNAME_ATTR', label: 'Атрибут логина', group: 'ldap', type: 'text' },
|
||||
{ key: 'LDAP_EMAIL_ATTR', label: 'Атрибут почты', group: 'ldap', type: 'text' },
|
||||
{ key: 'LDAP_DISPLAY_NAME_ATTR', label: 'Атрибут имени', group: 'ldap', type: 'text' },
|
||||
{ key: 'EMAIL_ENABLED', label: 'Email включён', group: 'messaging', type: 'boolean', hint: 'Отправка OTP-кодов на почту через SMTP' },
|
||||
{
|
||||
key: 'EMAIL_PROVIDER',
|
||||
label: 'Email-провайдер',
|
||||
group: 'messaging',
|
||||
type: 'select',
|
||||
options: [
|
||||
{ value: 'smtp', label: 'SMTP (Yandex, Gmail, Mail.ru и др.)' },
|
||||
{ value: 'console', label: 'Только лог (отладка)' }
|
||||
],
|
||||
showWhen: { key: 'EMAIL_ENABLED', equals: 'true' }
|
||||
},
|
||||
{ key: 'EMAIL_SMTP_HOST', label: 'SMTP-хост', group: 'messaging', type: 'text', hint: 'smtp.yandex.ru, smtp.gmail.com', showWhen: { key: 'EMAIL_ENABLED', equals: 'true' } },
|
||||
{ key: 'EMAIL_SMTP_PORT', label: 'SMTP-порт', group: 'messaging', type: 'number', unit: 'порт', showWhen: { key: 'EMAIL_ENABLED', equals: 'true' } },
|
||||
{ key: 'EMAIL_SMTP_SECURE', label: 'SMTP SSL/TLS', group: 'messaging', type: 'boolean', hint: 'Включите для порта 465', showWhen: { key: 'EMAIL_ENABLED', equals: 'true' } },
|
||||
{ key: 'EMAIL_SMTP_USER', label: 'SMTP-логин', group: 'messaging', type: 'text', showWhen: { key: 'EMAIL_ENABLED', equals: 'true' } },
|
||||
{ key: 'EMAIL_SMTP_PASSWORD', label: 'SMTP-пароль', group: 'messaging', type: 'text', hint: 'App-password для Gmail/Yandex', showWhen: { key: 'EMAIL_ENABLED', equals: 'true' } },
|
||||
{ key: 'EMAIL_FROM_ADDRESS', label: 'Email отправителя', group: 'messaging', type: 'text', hint: 'noreply@yourdomain.ru', showWhen: { key: 'EMAIL_ENABLED', equals: 'true' } },
|
||||
{ key: 'EMAIL_FROM_NAME', label: 'Имя отправителя', group: 'messaging', type: 'text', showWhen: { key: 'EMAIL_ENABLED', equals: 'true' } },
|
||||
{ key: 'SMS_ENABLED', label: 'SMS включён', group: 'messaging', type: 'boolean', hint: 'Отправка OTP-кодов по SMS' },
|
||||
{
|
||||
key: 'SMS_PROVIDER',
|
||||
label: 'SMS-провайдер',
|
||||
group: 'messaging',
|
||||
type: 'select',
|
||||
options: [
|
||||
{ value: 'smsru', label: 'sms.ru' },
|
||||
{ value: 'smsc', label: 'smsc.ru' },
|
||||
{ value: 'console', label: 'Только лог (отладка)' }
|
||||
],
|
||||
showWhen: { key: 'SMS_ENABLED', equals: 'true' }
|
||||
},
|
||||
{ key: 'SMS_API_KEY', label: 'API-ключ sms.ru', group: 'messaging', type: 'text', hint: 'api_id из личного кабинета sms.ru', showWhen: { key: 'SMS_ENABLED', equals: 'true' } },
|
||||
{ key: 'SMS_LOGIN', label: 'Логин smsc.ru', group: 'messaging', type: 'text', showWhen: { key: 'SMS_ENABLED', equals: 'true' } },
|
||||
{ key: 'SMS_PASSWORD', label: 'Пароль smsc.ru', group: 'messaging', type: 'text', showWhen: { key: 'SMS_ENABLED', equals: 'true' } },
|
||||
{ key: 'SMS_SENDER', label: 'Имя отправителя SMS', group: 'messaging', type: 'text', hint: 'Опционально, если одобрено провайдером', showWhen: { key: 'SMS_ENABLED', equals: 'true' } },
|
||||
{ key: 'MAX_FAMILY_MEMBERS', label: 'Макс. участников семьи', group: 'limits', type: 'number' },
|
||||
{ key: 'MAX_ACTIVE_SESSIONS', label: 'Макс. активных сессий', group: 'limits', type: 'number' },
|
||||
{ key: 'AVATAR_URL_TTL_MINUTES', label: 'TTL ссылки на аватар', group: 'media', type: 'number', unit: 'мин' }
|
||||
@@ -56,6 +95,20 @@ export function getSettingMeta(key: string) {
|
||||
return SYSTEM_SETTING_CATALOG.find((item) => item.key === key);
|
||||
}
|
||||
|
||||
export function isSettingVisible(setting: { key: string; value: string }, allSettings: Array<{ key: string; value: string }>) {
|
||||
const meta = getSettingMeta(setting.key);
|
||||
if (!meta?.showWhen) return true;
|
||||
const parent = allSettings.find((item) => item.key === meta.showWhen!.key);
|
||||
const parentValue = parent?.value ?? 'false';
|
||||
return parseBooleanValue(parentValue) === parseBooleanValue(meta.showWhen.equals);
|
||||
}
|
||||
|
||||
function parseBooleanValue(value: string) {
|
||||
return ['true', '1', 'yes'].includes(value.trim().toLowerCase());
|
||||
}
|
||||
|
||||
export const MESSAGING_SETTING_KEYS = SYSTEM_SETTING_CATALOG.filter((item) => item.group === 'messaging').map((item) => item.key);
|
||||
|
||||
export function sortSettingsByCatalog<T extends { key: string }>(settings: T[]) {
|
||||
const order = new Map(SYSTEM_SETTING_CATALOG.map((item, index) => [item.key, index]));
|
||||
return [...settings].sort((a, b) => (order.get(a.key) ?? 999) - (order.get(b.key) ?? 999));
|
||||
|
||||
Reference in New Issue
Block a user