27b1057cd4
Rapport ist jetzt dual: lokal (wie bisher) ODER Cloud auf eigenem Supabase-Server. Beide Modi haben dieselben Funktionen, Cloud zusätzlich Multi-User + Live-Sync. Storage-Architektur - src/storage/adapter.js: einheitliche Promise-API, LocalStorage- und SupabaseAdapter - src/storage/migrations.js: applyMigrations als reine Funktion, für beide Backends - Konfig-driven: VITE_SUPABASE_URL im Production-Build → automatisch Cloud-Modus Postgres-Schema (supabase/migrations/0001–0010) - 29 Tabellen, multi-tenant via studio_id + Row-Level-Security - Audit-Spalten (created_by/updated_by/at) + Trigger - Seed-Trigger pro neuem Studio (Rollen, Templates, Absenz-Typen) - Realtime-Publication für Live-Sync - RPCs: ensure_profile, create_studio_with_admin (mit Personen-Sharing), list_studios, load_persons_for_studio, attach_user_to_studio Cloud-Features (App) - BackendChoice.jsx als Erst-Screen «Lokal oder Cloud» - CloudSetup.jsx: 3-Schritt-Wizard für Erst-Einrichtung - Login.jsx: Modus-Switcher + Server-URL + Studio-Dropdown + Passwort-Vergessen - ResetPassword.jsx: empfängt Mail-Link-Klick via PASSWORD_RECOVERY-Event - Realtime: Änderungen zwischen Browsern ohne Reload sichtbar - Settings → System: Cloud-Verbindung, Studio-Switcher, weiteres Studio anlegen - Settings → Team: Mitarbeiter via Email einladen (Admin-Aktion) - Personen-Sharing: bei neuem Studio Personen aus anderen Studios übernehmen - Reload-Resume: studio_id in sessionStorage, kein erneuter Login nötig Web-Deploy - deploy/docker-compose.yml + nginx.conf: dist/ via nginx-Container, Port 8080 - .env.production.example: Build-time Cloud-URL - DEPLOY.md: Anleitung für LAN-only und extern via Nginx Proxy Manager Doku - README.md: Cloud-Variante prominent erklärt - ARCHITECTURE.md: Storage-Adapter, Migrations, neue Views in Risiko-Tabelle - DEPLOY.md: Schritt-für-Schritt für Mac Mini + NPM Version-Bump auf 0.8.0 in package.json, src-tauri/tauri.conf.json, Cargo.toml. Changelog-Entry im App.jsx-Modal (Karim sieht ihn beim ersten Start). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
84 lines
3.1 KiB
PL/PgSQL
84 lines
3.1 KiB
PL/PgSQL
-- ============================================================================
|
|
-- RAPPORT — Personen-Sharing beim Studio-Anlegen
|
|
-- ============================================================================
|
|
-- Erweitert `create_studio_with_admin` um einen optionalen dritten Parameter:
|
|
-- eine Liste von Quell-Studio-IDs, deren Personen ins neue Studio übernommen
|
|
-- werden sollen.
|
|
--
|
|
-- Mechanik (siehe 0001 — Persons mit nullable studio_id + person_studio_links):
|
|
-- 1. Lokale Personen aus Quell-Studio werden globalisiert (studio_id = NULL)
|
|
-- und bekommen einen Link an das Quell-Studio (Sichtbarkeit bleibt erhalten).
|
|
-- 2. Alle Personen, die im Quell-Studio sichtbar sind, bekommen zusätzlich
|
|
-- einen Link an das neue Studio.
|
|
--
|
|
-- Security: User muss in allen Quell-Studios Member sein, sonst Exception.
|
|
-- ============================================================================
|
|
|
|
drop function if exists create_studio_with_admin(text, text);
|
|
|
|
create function create_studio_with_admin(
|
|
p_name text,
|
|
p_slug text,
|
|
p_share_persons_from uuid[] default '{}'
|
|
)
|
|
returns uuid
|
|
language plpgsql
|
|
security definer
|
|
as $$
|
|
declare
|
|
v_studio_id uuid;
|
|
v_user_id uuid := auth.uid();
|
|
v_source_id uuid;
|
|
begin
|
|
if v_user_id is null then
|
|
raise exception 'Authentication required';
|
|
end if;
|
|
|
|
-- Sicherheits-Check: User muss in allen Quell-Studios aktiver Member sein
|
|
if array_length(p_share_persons_from, 1) > 0 then
|
|
if exists (
|
|
select 1 from unnest(p_share_persons_from) src
|
|
where not exists (
|
|
select 1 from studio_members sm
|
|
where sm.user_id = v_user_id
|
|
and sm.studio_id = src
|
|
and sm.active = true
|
|
)
|
|
) then
|
|
raise exception 'You are not a member of all source studios';
|
|
end if;
|
|
end if;
|
|
|
|
-- Studio + Admin-Membership anlegen (seed_studio_defaults-Trigger feuert)
|
|
insert into studios (name, slug) values (p_name, p_slug) returning id into v_studio_id;
|
|
insert into studio_members (studio_id, user_id, app_role_id)
|
|
values (v_studio_id, v_user_id, 'r-admin');
|
|
|
|
-- Personen-Sharing pro Quell-Studio
|
|
if array_length(p_share_persons_from, 1) > 0 then
|
|
foreach v_source_id in array p_share_persons_from loop
|
|
-- Schritt 1: Lokale Personen des Quell-Studios globalisieren.
|
|
-- a) Link an Quell-Studio anlegen (primary_studio = true, weil sie dort ursprünglich entstanden)
|
|
insert into person_studio_links (person_id, studio_id, primary_studio)
|
|
select id, v_source_id, true
|
|
from persons
|
|
where studio_id = v_source_id
|
|
on conflict (person_id, studio_id) do nothing;
|
|
-- b) Personen globalisieren (studio_id auf NULL)
|
|
update persons set studio_id = NULL where studio_id = v_source_id;
|
|
|
|
-- Schritt 2: alle im Quell-Studio sichtbaren Personen auch dem neuen Studio zuordnen
|
|
insert into person_studio_links (person_id, studio_id)
|
|
select person_id, v_studio_id
|
|
from person_studio_links
|
|
where studio_id = v_source_id
|
|
on conflict (person_id, studio_id) do nothing;
|
|
end loop;
|
|
end if;
|
|
|
|
return v_studio_id;
|
|
end;
|
|
$$;
|
|
|
|
grant execute on function create_studio_with_admin(text, text, uuid[]) to authenticated;
|