From f060cde5c106b23292588e3e09a55ed0bdee0343 Mon Sep 17 00:00:00 2001 From: Andrei Laas Date: Thu, 22 Oct 2026 20:14:25 +0200 Subject: [PATCH] Aufraeumen: Audit-Filter aus dem Protokoll, Reorganisation entfernt, toter Code - Audit-Log: die Auswahl der Aktionen kommt aus dem Protokoll selbst (distinct action) statt aus einer festen Liste, die vier tote Aktionen fuehrte und rund dreissig aktuelle nicht kannte. - "Reorganisation" nicht mehr als Ereignistyp in den Berichten (immer leer) und nicht im Import; Texte in Organigramm, Nachtlauf (nachtlauf.ps1) und Kommentaren ohne Reorg. Import kennt "Uebernahme", nicht mehr "Gehaltsanpassung". - adjust_karenz_return entfernt (Migration): sie setzte nur die Spalte und liess die vorgemerkte Rueckkehr stehen; rueckkehr_anpassen ist der Weg. lib/acting-manager.ts entfernt (die Berichtslinie rechnet om_reporting_lines in der Datenbank). - Export Mitarbeiter: "Auf wessen Wunsch" mit "Wunsch Dienstnehmer/ Dienstgeber" wie in der Oberflaeche. Geprueft: lint, tsc, types:check, Tests, Uebergabe-Waechter --- app/(app)/audit/page.tsx | 12 ++- app/api/cron/apply-pending-changes/route.ts | 2 +- app/api/export/employees/route.ts | 4 +- components/audit/AuditFilters.tsx | 39 +++----- components/orgchart/AsOfPicker.tsx | 2 +- components/orgchart/EmployeeTree.tsx | 2 +- components/ui/Lookup.tsx | 4 +- ...022120000_rueckkehrdatum_alt_entfernen.sql | 22 +++++ deploy/windows/nachtlauf.ps1 | 2 +- lib/acting-manager.ts | 62 ------------- lib/import/schema.ts | 3 +- lib/reports.ts | 4 +- lib/types.ts | 1 - tests/unit/acting-manager.test.ts | 93 ------------------- tests/unit/import-validate.test.ts | 4 +- 15 files changed, 57 insertions(+), 199 deletions(-) create mode 100644 db/migrations/20261022120000_rueckkehrdatum_alt_entfernen.sql delete mode 100644 lib/acting-manager.ts delete mode 100644 tests/unit/acting-manager.test.ts diff --git a/app/(app)/audit/page.tsx b/app/(app)/audit/page.tsx index 1fbb700..894fb81 100644 --- a/app/(app)/audit/page.tsx +++ b/app/(app)/audit/page.tsx @@ -38,7 +38,7 @@ export default async function AuditPage({ searchParams }: { searchParams: Promis const params = await searchParams; const page = Math.max(1, Number(params.page ?? "1") || 1); - const { entries, count } = await withUser(await currentUserId(), async (tx) => { + const { entries, count, aktionen } = await withUser(await currentUserId(), async (tx) => { const base = () => { let q = tx.selectFrom("audit_log"); if (params.action) q = q.where("action", "=", params.action); @@ -54,7 +54,7 @@ export default async function AuditPage({ searchParams }: { searchParams: Promis return q; }; - const [entries, total] = await Promise.all([ + const [entries, total, aktionen] = await Promise.all([ base() .select(["id", "occurred_at", "actor_name", "action", "target_label", "target_employee_id", "details", "changes"]) // Nach id als zweitem Kriterium: bei gleichem Zeitstempel wäre die @@ -68,8 +68,12 @@ export default async function AuditPage({ searchParams }: { searchParams: Promis base() .select(({ fn }) => fn.countAll().as("anzahl")) .executeTakeFirst(), + // Die Aktionen, die im Protokoll vorkommen — die Auswahl im Filter + // folgt damit dem, was geschrieben wird, statt einer Liste, die neben + // jeder neuen Funktion nachgezogen werden müsste. + tx.selectFrom("audit_log").select("action").distinct().orderBy("action").execute(), ]); - return { entries, count: Number(total?.anzahl ?? 0) }; + return { entries, count: Number(total?.anzahl ?? 0), aktionen: aktionen.map((a) => a.action) }; }); const totalPages = Math.max(1, Math.ceil(count / PAGE_SIZE)); @@ -78,7 +82,7 @@ export default async function AuditPage({ searchParams }: { searchParams: Promis
- +

{count} Einträge

diff --git a/app/api/cron/apply-pending-changes/route.ts b/app/api/cron/apply-pending-changes/route.ts index 33e16b3..14b7dbb 100644 --- a/app/api/cron/apply-pending-changes/route.ts +++ b/app/api/cron/apply-pending-changes/route.ts @@ -2,7 +2,7 @@ import { NextResponse, type NextRequest } from "next/server"; import { asSystem } from "@/lib/db"; import { callFunction } from "@/lib/db/rpc"; -// Applies effective-dated changes (Versetzung/Beförderung/Karenz/Reorg/Daten +// Applies effective-dated changes (Versetzung/Beförderung/Karenz/Daten // ändern with a future "Wirksam ab" date) once their date has arrived — see // apply_due_pending_changes() in db/migrations. // diff --git a/app/api/export/employees/route.ts b/app/api/export/employees/route.ts index 0c6df8e..fbd3d25 100644 --- a/app/api/export/employees/route.ts +++ b/app/api/export/employees/route.ts @@ -1,3 +1,4 @@ +import { AUSTRITTSART_LABELS, istAustrittsart } from "@/lib/beendigung"; import { NextResponse, type NextRequest } from "next/server"; import { statusLabel } from "@/lib/absence"; import { exportFilename, exportResponseHeaders, toCsv, toXlsx, type ExportColumn } from "@/lib/export"; @@ -124,7 +125,8 @@ function employeeExportColumns( { header: "Austrittsgrund", get: (e) => e.exit_reason }, // Eigene Spalte neben dem Grund: aus ihm folgt sie nicht. Leer heisst // „nicht erfasst" und nicht „weder noch". - { header: "Freiwillig/unfreiwillig", get: (e) => e.austrittsart ?? "" }, + // Wie in der Oberfläche: „Wunsch Dienstnehmer" / „Wunsch Dienstgeber" statt des gespeicherten Werts. + { header: "Auf wessen Wunsch", get: (e) => (istAustrittsart(e.austrittsart) ? AUSTRITTSART_LABELS[e.austrittsart] : "") }, { header: "Abwesenheit ab", get: (e) => e.karenz_start_date, kind: "date" }, { header: "Rückkehr geplant", get: (e) => e.karenz_return_date, kind: "date" }, { header: "Anzahl Angehörige", get: (e) => dependentsCounts.get(e.id) ?? 0 }, diff --git a/components/audit/AuditFilters.tsx b/components/audit/AuditFilters.tsx index bdfed8f..30e8da0 100644 --- a/components/audit/AuditFilters.tsx +++ b/components/audit/AuditFilters.tsx @@ -4,32 +4,15 @@ import { usePathname, useRouter, useSearchParams } from "next/navigation"; import { useEffect, useState } from "react"; import { FILTER_SELECT_CLASS } from "@/components/ui/Field"; import { SearchInput } from "@/components/ui/SearchInput"; +import { anzeige } from "@/lib/anzeige"; -// The value is the string stored in audit_log.action and must not change; -// only what the user reads does — 'Karenz' is displayed as -// "Langzeitabwesenheit" (see lib/absence.ts). -const ACTIONS: { value: string; label: string }[] = [ - { value: "Neueinstellung", label: "Neueinstellung" }, - { value: "Wiedereinstellung", label: "Wiedereinstellung" }, - { value: "Rückkehr", label: "Rückkehr aus Langzeitabwesenheit" }, - { value: "Austritt", label: "Austritt" }, - { value: "Versetzung", label: "Versetzung" }, - { value: "Ausschreibung", label: "Ausschreibung" }, - { value: "Interne Besetzung", label: "Interne Besetzung" }, - { value: "Beförderung", label: "Beförderung" }, - { value: "Reorganisation", label: "Reorganisation" }, - { value: "Reorganisation rückgängig", label: "Reorganisation rückgängig" }, - { value: "Karenz", label: "Langzeitabwesenheit" }, - { value: "Vertragsänderung", label: "Vertragsänderung" }, - { value: "Stammdatenänderung", label: "Stammdatenänderung" }, - // „Gehaltsanpassung" steht nicht zur Auswahl: das Gehalt gehört nicht zum - // Funktionsumfang (es wird in Loga geführt), keine Funktion schreibt diese - // Art, und ein Filter, der immer leer ausgeht, sieht aus wie ein Fehler. - // Der Wert bleibt im Aufzählungstyp, damit vorhandene Einträge dieser Art - // lesbar bleiben. -]; - -export function AuditFilters() { +// Der Wert ist der in audit_log.action gespeicherte Text und bleibt; nur die +// Anzeige weicht ab, wo die fachliche Bezeichnung eine andere ist. +const BESCHRIFTUNG: Record = { + Karenz: "Langzeitabwesenheit", + Rückkehr: "Rückkehr aus Langzeitabwesenheit", +}; +export function AuditFilters({ aktionen }: { aktionen: string[] }) { const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); @@ -66,9 +49,9 @@ export function AuditFilters() { className={FILTER_SELECT_CLASS} > - {ACTIONS.map((a) => ( - ))} diff --git a/components/orgchart/AsOfPicker.tsx b/components/orgchart/AsOfPicker.tsx index 851c45a..4e6e935 100644 --- a/components/orgchart/AsOfPicker.tsx +++ b/components/orgchart/AsOfPicker.tsx @@ -84,7 +84,7 @@ export function AsOfPicker({ asOf, today, projectedCount, historyStartsAt }: AsO {isFuture && (

Vorschau: {projectedCount > 0 - ? `${projectedCount} geplante Versetzung(en)/Reorganisation(en) sind eingerechnet.` + ? `${projectedCount} geplante Versetzung(en) oder Beförderung(en) sind eingerechnet.` : "Für diesen Zeitraum sind keine Versetzungen vorgemerkt."}{" "} Ein-/Austritte und Karenzen sind berücksichtigt.

diff --git a/components/orgchart/EmployeeTree.tsx b/components/orgchart/EmployeeTree.tsx index debf793..4185976 100644 --- a/components/orgchart/EmployeeTree.tsx +++ b/components/orgchart/EmployeeTree.tsx @@ -50,7 +50,7 @@ export function EmployeeTree({ employees, focusId = null }: { employees: OrgEmpl for (const list of byManager.values()) list.sort((a, b) => a.last_name.localeCompare(b.last_name)); // Nothing in the schema forbids a manager_id cycle (A reports to B - // reports to A), and a reorg that moves a lead under one of their own + // reports to A), and a transfer that moves a lead under one of their own // reports would create one. Every walk below is recursive, so an // unguarded cycle is an infinite recursion that hangs the tab rather // than a wrong number — hence the on-path set. diff --git a/components/ui/Lookup.tsx b/components/ui/Lookup.tsx index 21dc753..e1b24dc 100644 --- a/components/ui/Lookup.tsx +++ b/components/ui/Lookup.tsx @@ -20,8 +20,8 @@ type LookupProps = { "aria-invalid"?: true; }; -// Generic async search-select used by the position lookup (hire wizard), -// manager/superior lookup (create position), and the reorg workbench. +// Generic async search-select used by the Planstelle, Einheit and +// Kostenstelle pickers (components/positions). // // Implements the combobox contract rather than just looking like one: // without it a keyboard user could type but never reach a result, and a diff --git a/db/migrations/20261022120000_rueckkehrdatum_alt_entfernen.sql b/db/migrations/20261022120000_rueckkehrdatum_alt_entfernen.sql new file mode 100644 index 0000000..56a5692 --- /dev/null +++ b/db/migrations/20261022120000_rueckkehrdatum_alt_entfernen.sql @@ -0,0 +1,22 @@ +-- adjust_karenz_return entfällt. +-- +-- Das Rückkehrdatum einer laufenden Abwesenheit ändert rueckkehr_anpassen: +-- es verschiebt die vorgemerkte Rückkehr mit. adjust_karenz_return setzte nur +-- die Spalte an der Person und liesse die vorgemerkte Rückkehr auf dem alten +-- Tag stehen; die Anwendung ruft sie nicht auf. Bliebe sie aufrufbar, wäre +-- sie ein zweiter Weg zu genau dem Widerspruch, den rueckkehr_anpassen +-- vermeidet. +drop function if exists public.adjust_karenz_return(jsonb); + +do $pruefung$ +begin + if exists (select 1 from pg_proc p join pg_namespace n on n.oid = p.pronamespace + where n.nspname = 'public' and p.proname = 'adjust_karenz_return') then + raise exception 'adjust_karenz_return besteht noch.'; + end if; + if not exists (select 1 from pg_proc p join pg_namespace n on n.oid = p.pronamespace + where n.nspname = 'public' and p.proname = 'rueckkehr_anpassen') then + raise exception 'rueckkehr_anpassen fehlt — ohne sie liesse sich das Rückkehrdatum nicht mehr ändern.'; + end if; +end +$pruefung$; diff --git a/deploy/windows/nachtlauf.ps1 b/deploy/windows/nachtlauf.ps1 index 0341e35..c44cd4a 100644 --- a/deploy/windows/nachtlauf.ps1 +++ b/deploy/windows/nachtlauf.ps1 @@ -1,7 +1,7 @@ <# .SYNOPSIS Der naechtliche Lauf: uebernimmt faellig gewordene, zukunftsdatierte - Aenderungen (Versetzung, Befoerderung, Karenz, Reorganisation). + Aenderungen (Versetzung, Befoerderung, Langzeitabwesenheit, Daten aendern). .DESCRIPTION Ruft /api/cron/apply-pending-changes mit CRON_SECRET auf. Laeuft als diff --git a/lib/acting-manager.ts b/lib/acting-manager.ts deleted file mode 100644 index 3e60c01..0000000 --- a/lib/acting-manager.ts +++ /dev/null @@ -1,62 +0,0 @@ -// Who actually leads a team while its lead is on a long-term absence. -// -// The rule: reporting rolls up to the next management level, and keeps -// rolling up until it reaches somebody who is present. Someone on -// Langzeitabwesenheit stays formally in charge — nothing is written to -// employees.manager_id — so this is derived at read time and the stand-in is -// always shown as such rather than silently replacing the real manager. - -export type ChainNode = { - id: string; - /** The recorded manager, absent or not. */ - managerId: string | null; - absent: boolean; -}; - -export type ActingManagerResult = { - /** Who to report to in practice — the nearest present manager. */ - actingManagerId: string | null; - /** - * The recorded manager, when they differ from the acting one. Null when - * nobody is standing in, so the UI can show the arrangement only when - * there is one. - */ - coveredForId: string | null; -}; - -/** - * Walks up from `node`'s recorded manager until it finds one who is present. - * - * Falls back to the recorded manager when the whole chain above is absent - * (or leads nowhere): re-rooting a team to the top of the chart would be a - * bigger lie than showing the absent manager, and the absence is labelled - * either way. - */ -export function resolveActingManager(node: ChainNode, byId: Map): ActingManagerResult { - const formalId = node.managerId; - if (!formalId) return { actingManagerId: null, coveredForId: null }; - - const formal = byId.get(formalId); - if (!formal || !formal.absent) return { actingManagerId: formalId, coveredForId: null }; - - // Nothing in the schema forbids a manager_id cycle, so the walk has to - // terminate on its own rather than trusting the data. - const seen = new Set([node.id, formalId]); - let current: ChainNode | undefined = formal; - - while (current?.managerId && !seen.has(current.managerId)) { - seen.add(current.managerId); - const next = byId.get(current.managerId); - if (!next) break; - if (!next.absent) return { actingManagerId: next.id, coveredForId: formalId }; - current = next; - } - - return { actingManagerId: formalId, coveredForId: null }; -} - -/** Applies the walk to a whole set, returning one result per node id. */ -export function resolveActingManagers(nodes: ChainNode[]): Map { - const byId = new Map(nodes.map((n) => [n.id, n])); - return new Map(nodes.map((n) => [n.id, resolveActingManager(n, byId)])); -} diff --git a/lib/import/schema.ts b/lib/import/schema.ts index 55cf4cc..f480472 100644 --- a/lib/import/schema.ts +++ b/lib/import/schema.ts @@ -57,9 +57,8 @@ const EREIGNIS = [ "Stammdatenänderung", "Austritt", "Wiedereintritt", - "Reorganisation", - "Gehaltsanpassung", "Rückkehr", + "Übernahme", ] as const; export const BLATT_STANDORTE: BlattSchema = { diff --git a/lib/reports.ts b/lib/reports.ts index fba555f..efc821a 100644 --- a/lib/reports.ts +++ b/lib/reports.ts @@ -502,10 +502,12 @@ export const EVENT_TYPE_LABELS: Record = { // * „Stammdatenänderung" entsteht bei jeder geänderten Telefonnummer. // * „Gehaltsanpassung" ist ein totes Ereignis: das Gehalt liegt in Loga, // keine SQL-Funktion schreibt diesen Typ. +// * „Reorganisation" ebenso: eine Umorganisation gibt es als Vorgang +// nicht, der Wert steht nur im Aufzählungstyp. // // „Wiedereintritt" gehört dagegen hierher und bekommt in // lib/colors.ts dieselbe grüne Kategorie wie der Eintritt — es ist einer. -const NICHT_AUSWERTBAR: readonly HistoryEventType[] = ["Stammdatenänderung", "Gehaltsanpassung"]; +const NICHT_AUSWERTBAR: readonly HistoryEventType[] = ["Stammdatenänderung", "Gehaltsanpassung", "Reorganisation"]; export const EREIGNIS_AUSWAHL: readonly HistoryEventType[] = ( Object.keys(EVENT_TYPE_LABELS) as HistoryEventType[] diff --git a/lib/types.ts b/lib/types.ts index faf8e11..c3427ad 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -879,7 +879,6 @@ export type Database = { transfer_employee: { Args: { payload: Record }; Returns: void }; promote_employee: { Args: { payload: Record }; Returns: void }; start_karenz: { Args: { payload: Record }; Returns: void }; - adjust_karenz_return: { Args: { payload: Record }; Returns: void }; record_karenz_return: { Args: { payload: Record }; Returns: void }; rueckkehr_anpassen: { Args: { payload: Record }; Returns: void }; change_employee_data: { Args: { payload: Record }; Returns: void }; diff --git a/tests/unit/acting-manager.test.ts b/tests/unit/acting-manager.test.ts deleted file mode 100644 index a0c6ea9..0000000 --- a/tests/unit/acting-manager.test.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { resolveActingManager, resolveActingManagers, type ChainNode } from "@/lib/acting-manager"; - -// Nobody's manager_id is rewritten for an absence — the stand-in is derived -// here, at read time, so the absent person stays formally in charge and the -// arrangement can be shown as temporary. -function node(id: string, managerId: string | null, absent = false): ChainNode { - return { id, managerId, absent }; -} - -function chain(...nodes: ChainNode[]) { - return new Map(nodes.map((n) => [n.id, n])); -} - -describe("resolveActingManager", () => { - it("leaves a present manager alone", () => { - const ic = node("ic", "lead"); - const map = chain(ic, node("lead", "head")); - expect(resolveActingManager(ic, map)).toEqual({ actingManagerId: "lead", coveredForId: null }); - }); - - it("rolls up one level when the manager is absent", () => { - const ic = node("ic", "lead"); - const map = chain(ic, node("lead", "head", true), node("head", "ceo")); - expect(resolveActingManager(ic, map)).toEqual({ actingManagerId: "head", coveredForId: "lead" }); - }); - - it("keeps rolling up while each level is absent", () => { - const ic = node("ic", "lead"); - const map = chain(ic, node("lead", "head", true), node("head", "ceo", true), node("ceo", null)); - // coveredForId names the *recorded* manager, which is what the employee - // and the org chart know about — not the intermediate level skipped. - expect(resolveActingManager(ic, map)).toEqual({ actingManagerId: "ceo", coveredForId: "lead" }); - }); - - it("gives an absent lead the same stand-in as their own reports", () => { - // The deputy for an absent person is simply their own acting manager, - // which is why no separate deputy field is needed anywhere. - const lead = node("lead", "head", true); - const map = chain(node("ic", "lead"), lead, node("head", "ceo")); - expect(resolveActingManager(lead, map).actingManagerId).toBe("head"); - }); - - it("keeps the recorded manager when everyone above is absent", () => { - // Re-rooting the team to the top of the chart would be a bigger - // distortion than showing the absent manager, whose absence is labelled - // regardless. - const ic = node("ic", "lead"); - const map = chain(ic, node("lead", "ceo", true), node("ceo", null, true)); - expect(resolveActingManager(ic, map)).toEqual({ actingManagerId: "lead", coveredForId: null }); - }); - - it("returns nothing for somebody at the top", () => { - const ceo = node("ceo", null); - expect(resolveActingManager(ceo, chain(ceo))).toEqual({ actingManagerId: null, coveredForId: null }); - }); - - it("keeps the recorded manager when they are not in the visible set", () => { - // A manager who had already left or has not started yet; the snapshot's - // own re-rooting deals with that case. - const ic = node("ic", "gone"); - expect(resolveActingManager(ic, chain(ic))).toEqual({ actingManagerId: "gone", coveredForId: null }); - }); - - it("terminates on a manager cycle instead of looping forever", () => { - // Nothing in the schema forbids A -> B -> A. - const ic = node("ic", "a"); - const map = chain(ic, node("a", "b", true), node("b", "a", true)); - expect(() => resolveActingManager(ic, map)).not.toThrow(); - expect(resolveActingManager(ic, map)).toEqual({ actingManagerId: "a", coveredForId: null }); - }); - - it("terminates when somebody is their own manager", () => { - const ic = node("ic", "self"); - const map = chain(ic, node("self", "self", true)); - expect(resolveActingManager(ic, map).actingManagerId).toBe("self"); - }); -}); - -describe("resolveActingManagers", () => { - it("moves a whole team up together", () => { - const results = resolveActingManagers([ - node("ic1", "lead"), - node("ic2", "lead"), - node("lead", "head", true), - node("head", null), - ]); - expect(results.get("ic1")).toEqual({ actingManagerId: "head", coveredForId: "lead" }); - expect(results.get("ic2")).toEqual({ actingManagerId: "head", coveredForId: "lead" }); - // The absent lead stays under their own manager rather than vanishing. - expect(results.get("lead")?.actingManagerId).toBe("head"); - }); -}); diff --git a/tests/unit/import-validate.test.ts b/tests/unit/import-validate.test.ts index b8e2c47..b39605b 100644 --- a/tests/unit/import-validate.test.ts +++ b/tests/unit/import-validate.test.ts @@ -281,7 +281,9 @@ describe("Historie", () => { ); const m = meldungen(r.fehler).join(" "); expect(m).toContain("Unbekannter Wert"); - expect(m).toContain("Gehaltsanpassung"); + // Die erlaubten Typen werden genannt; tote wie „Gehaltsanpassung" nicht mehr. + expect(m).toContain("Übernahme"); + expect(m).not.toContain("Gehaltsanpassung"); }); });