49 lines
2.2 KiB
SQL
49 lines
2.2 KiB
SQL
-- ====================================================================
|
|
-- 0055_smtp_settings — SMTP-Konfiguration über die Admin-UI
|
|
-- ====================================================================
|
|
-- Bisher kam SMTP ausschließlich aus ENV-Variablen (lib/email.ts →
|
|
-- process.env.SMTP_*). Self-Host-Kunden mussten dafür die .env editieren +
|
|
-- Container neu starten. Jetzt pro Mandant in site_settings (Admin → Mail)
|
|
-- pflegbar — mit ENV-Fallback (bestehende ENV-Setups laufen unverändert).
|
|
--
|
|
-- Vorrang in lib/email.ts: ist smtp_host in der DB gesetzt → DB-Konfig,
|
|
-- sonst ENV. smtp_pass/-user sind Geheimnisse → NICHT für anon lesbar.
|
|
|
|
alter table public.site_settings
|
|
add column if not exists smtp_host text,
|
|
add column if not exists smtp_port integer,
|
|
add column if not exists smtp_secure boolean,
|
|
add column if not exists smtp_user text,
|
|
add column if not exists smtp_pass text,
|
|
add column if not exists smtp_from_email text,
|
|
add column if not exists smtp_from_name text;
|
|
|
|
-- anon-Spalten-Grant neu setzen (Muster aus 0043): anon Vollzugriff entziehen,
|
|
-- dann ALLE Spalten AUSSER der Geheimnis-/SMTP-Block-Liste freigeben.
|
|
-- WICHTIG: Block-Liste = die Original-Geheimnisse aus 0043 + alle smtp_*,
|
|
-- sonst würden die in 0043 geschützten Keys wieder anon-lesbar.
|
|
revoke all on public.site_settings from anon;
|
|
|
|
do $$
|
|
declare
|
|
v_cols text;
|
|
begin
|
|
select string_agg(quote_ident(column_name), ', ')
|
|
into v_cols
|
|
from information_schema.columns
|
|
where table_schema = 'public'
|
|
and table_name = 'site_settings'
|
|
and column_name not in (
|
|
-- Geheimnis-Spalten aus 0043 (weiter geschützt):
|
|
'ai_anthropic_key', 'ai_openai_key', 'ai_openrouter_key',
|
|
'apple_pass_cert_p12', 'apple_pass_passphrase', 'apple_pass_type_id',
|
|
'google_wallet_service_account_json',
|
|
'phone_api_token', 'phone_lookup_token', 'phone_webhook_secret',
|
|
'license_key',
|
|
-- neu: SMTP-Konfiguration (Zugangsdaten + Infrastruktur, kein anon-Bedarf):
|
|
'smtp_host', 'smtp_port', 'smtp_secure', 'smtp_user', 'smtp_pass',
|
|
'smtp_from_email', 'smtp_from_name'
|
|
);
|
|
execute 'grant select (' || v_cols || ') on public.site_settings to anon';
|
|
end $$;
|