Passwort-Anmeldung: Provider, Formulare, drei Zustaende der Shell
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { sql } from "kysely";
|
||||
import type { Tx } from "./db";
|
||||
import { jsonArrayFrom, jsonObjectFrom, zeitstempel } from "./db/json";
|
||||
import { todayIso } from "./format";
|
||||
@@ -30,14 +31,27 @@ export type ShellData = {
|
||||
};
|
||||
|
||||
/**
|
||||
* `null` heisst: angemeldet, aber nicht als HR freigeschaltet.
|
||||
* Drei Ausgänge, nicht zwei.
|
||||
*
|
||||
* Seit es die Anmeldung mit Passwort gibt, ist „darf nicht hinein" nicht mehr
|
||||
* dasselbe wie „hat keinen Zugang": wer sein Startpasswort noch nicht
|
||||
* gewechselt hat, hat einen Zugang und kommt trotzdem an keine Zeile, weil
|
||||
* is_hr_user() das mitprüft (Migration 20260908120000). Unterschieden werden
|
||||
* muss es, weil die beiden Fälle verschiedene Auswege haben — der eine wartet
|
||||
* auf HR, der andere ist in einer Minute erledigt.
|
||||
*/
|
||||
export type ShellErgebnis =
|
||||
| { status: "kein_zugang" }
|
||||
| { status: "passwort_wechseln" }
|
||||
| { status: "ok"; daten: ShellData };
|
||||
|
||||
/**
|
||||
* Die Zugangsprüfung fragt gleichzeitig mit dem Rest statt davor. Das liest
|
||||
* ein paar Zeilen mehr, als eine gesperrte Person sehen dürfte, wirft sie aber
|
||||
* weg, ohne sie je auszuliefern — und die eigentliche Grenze ist ohnehin RLS,
|
||||
* nicht die Reihenfolge hier.
|
||||
*/
|
||||
export async function loadShellData(tx: Tx, userId: string): Promise<ShellData | null> {
|
||||
export async function loadShellData(tx: Tx, userId: string): Promise<ShellErgebnis> {
|
||||
const asOf = todayIso();
|
||||
|
||||
const gelesen = await tx
|
||||
@@ -45,6 +59,10 @@ export async function loadShellData(tx: Tx, userId: string): Promise<ShellData |
|
||||
jsonObjectFrom(
|
||||
eb.selectFrom("profiles").select(["full_name", "email", "role", "is_active"]).where("id", "=", userId)
|
||||
).as("profile"),
|
||||
// Eine Spalte mehr in derselben Abfrage, keine zusätzliche Rundreise.
|
||||
// Direkt aus app_passwoerter zu lesen ginge nicht: die Tabelle ist für
|
||||
// die Anwendungsrolle gesperrt, an sie kommt nur diese Funktion.
|
||||
sql<boolean>`app_muss_passwort_wechseln()`.as("passwortWechseln"),
|
||||
...orgMapsAbfragen(eb),
|
||||
jsonArrayFrom(offeneStellenAbfrage(eb, asOf)).as("open"),
|
||||
jsonArrayFrom(offeneNotizenAbfrage(eb)).as("notes"),
|
||||
@@ -60,17 +78,28 @@ export async function loadShellData(tx: Tx, userId: string): Promise<ShellData |
|
||||
.executeTakeFirstOrThrow();
|
||||
|
||||
const profile = gelesen.profile;
|
||||
if (profile?.role !== "hr" || profile?.is_active !== true) return null;
|
||||
|
||||
// Der Passwortwechsel steht **vor** der HR-Prüfung, obwohl er der seltenere
|
||||
// Fall ist: er ist der einzige, den die betroffene Person selbst beheben
|
||||
// kann. Wer beides hat — offener Wechsel und keine Freischaltung — bekommt
|
||||
// danach immer noch „Kein HR-Zugriff", aber wenigstens in dieser Reihenfolge
|
||||
// und nicht als Sackgasse.
|
||||
if (gelesen.passwortWechseln) return { status: "passwort_wechseln" };
|
||||
|
||||
if (profile?.role !== "hr" || profile?.is_active !== true) return { status: "kein_zugang" };
|
||||
|
||||
const orgMaps = buildOrgMaps(gelesen.units as never, gelesen.locations as never);
|
||||
|
||||
return {
|
||||
profile,
|
||||
// Die zweite Rundreise: was sie fragt, hängt davon ab, welche Stellen
|
||||
// offen sind — das lässt sich nicht in die erste ziehen.
|
||||
openPositions: await resolveOpenPositions(tx, orgMaps, gelesen.open as OffeneStelle[], asOf),
|
||||
locations: gelesen.locations as Location[],
|
||||
drafts: gelesen.drafts as ShellData["drafts"],
|
||||
openNotes: baueOffeneNotizen(gelesen.notes as NotizZeile[]),
|
||||
status: "ok",
|
||||
daten: {
|
||||
profile,
|
||||
// Die zweite Rundreise: was sie fragt, hängt davon ab, welche Stellen
|
||||
// offen sind — das lässt sich nicht in die erste ziehen.
|
||||
openPositions: await resolveOpenPositions(tx, orgMaps, gelesen.open as OffeneStelle[], asOf),
|
||||
locations: gelesen.locations as Location[],
|
||||
drafts: gelesen.drafts as ShellData["drafts"],
|
||||
openNotes: baueOffeneNotizen(gelesen.notes as NotizZeile[]),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user