Files
karim 27b1057cd4 Release 0.8.0: Cloud-Variante (Supabase, Multi-Studio, Realtime, Web-Deploy)
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>
2026-05-23 19:08:00 +02:00

62 lines
2.1 KiB
PL/PgSQL

-- ============================================================================
-- RAPPORT — Mitarbeiter einladen (Admin-Aktion)
-- ============================================================================
-- Two-Step-Flow (vom Frontend orchestriert):
-- 1. Admin ruft `supabase.auth.signUp(email, tempPassword)` mit einem
-- temporären Client (ohne Session-persist), damit Admin-Session nicht
-- "übernommen" wird. → liefert neue user_id.
-- 2. Admin ruft `attach_user_to_studio(user_id, studio_id, role, username, name)`
-- mit seinem eigenen Auth-Token. RPC prüft, dass Caller Admin im
-- Ziel-Studio ist, und legt Profil + Membership an.
--
-- Sicherheit: nur Admins eines Studios können dort Mitglieder hinzufügen.
-- `attach` ist idempotent (ON CONFLICT update), damit der Flow re-runnable ist.
-- ============================================================================
create or replace function attach_user_to_studio(
p_user_id uuid,
p_studio_id uuid,
p_app_role_id text,
p_username text,
p_display_name text
)
returns void
language plpgsql
security definer
as $$
declare
v_caller_id uuid := auth.uid();
begin
if v_caller_id is null then
raise exception 'Authentication required';
end if;
-- Caller muss Admin in Ziel-Studio sein
if not exists (
select 1 from studio_members
where user_id = v_caller_id
and studio_id = p_studio_id
and app_role_id = 'r-admin'
and active = true
) then
raise exception 'Only admins of the studio can invite members';
end if;
-- Profile
insert into profiles (id, username, display_name)
values (p_user_id, p_username, p_display_name)
on conflict (id) do update set
username = excluded.username,
display_name = excluded.display_name;
-- Membership (idempotent)
insert into studio_members (studio_id, user_id, app_role_id)
values (p_studio_id, p_user_id, p_app_role_id)
on conflict (studio_id, user_id) do update set
app_role_id = excluded.app_role_id,
active = true;
end;
$$;
grant execute on function attach_user_to_studio(uuid, uuid, text, text, text) to authenticated;