Aufraeumen: Audit-Filter aus dem Protokoll, Reorganisation entfernt, toter Code
All checks were successful
CI / Lint, Typen, Tests, Build (push) Successful in 12m15s
CI / Migrationen auf leerer Datenbank (push) Successful in 10m39s
CI / Ausrollen (push) Successful in 6s

- 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
This commit is contained in:
2026-10-22 20:14:25 +02:00
parent 555510ab7d
commit f060cde5c1
15 changed files with 57 additions and 199 deletions

View File

@@ -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<string>().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
<div className="flex flex-col gap-4">
<AuditTabs />
<Suspense>
<AuditFilters />
<AuditFilters aktionen={aktionen} />
</Suspense>
<p className="text-sm text-ink-muted">{count} Einträge</p>

View File

@@ -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.
//

View File

@@ -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 },

View File

@@ -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<string, string> = {
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}
>
<option value="">Alle Aktionen</option>
{ACTIONS.map((a) => (
<option key={a.value} value={a.value}>
{a.label}
{aktionen.map((a) => (
<option key={a} value={a}>
{BESCHRIFTUNG[a] ?? anzeige(a)}
</option>
))}
</select>

View File

@@ -84,7 +84,7 @@ export function AsOfPicker({ asOf, today, projectedCount, historyStartsAt }: AsO
{isFuture && (
<p className="mt-2 rounded bg-info-bg px-3 py-2 text-xs text-info-text">
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.
</p>

View File

@@ -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.

View File

@@ -20,8 +20,8 @@ type LookupProps<T> = {
"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

View File

@@ -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$;

View File

@@ -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

View File

@@ -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<string, ChainNode>): 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<string>([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<string, ActingManagerResult> {
const byId = new Map(nodes.map((n) => [n.id, n]));
return new Map(nodes.map((n) => [n.id, resolveActingManager(n, byId)]));
}

View File

@@ -57,9 +57,8 @@ const EREIGNIS = [
"Stammdatenänderung",
"Austritt",
"Wiedereintritt",
"Reorganisation",
"Gehaltsanpassung",
"Rückkehr",
"Übernahme",
] as const;
export const BLATT_STANDORTE: BlattSchema = {

View File

@@ -502,10 +502,12 @@ export const EVENT_TYPE_LABELS: Record<HistoryEventType, string> = {
// * „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[]

View File

@@ -879,7 +879,6 @@ export type Database = {
transfer_employee: { Args: { payload: Record<string, unknown> }; Returns: void };
promote_employee: { Args: { payload: Record<string, unknown> }; Returns: void };
start_karenz: { Args: { payload: Record<string, unknown> }; Returns: void };
adjust_karenz_return: { Args: { payload: Record<string, unknown> }; Returns: void };
record_karenz_return: { Args: { payload: Record<string, unknown> }; Returns: void };
rueckkehr_anpassen: { Args: { payload: Record<string, unknown> }; Returns: void };
change_employee_data: { Args: { payload: Record<string, unknown> }; Returns: void };

View File

@@ -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");
});
});

View File

@@ -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");
});
});