Kostenstelle umbenennen, in der Oberflaeche und im Import
rename_cost_center aendert nur die Bezeichnung; die Nummer bleibt, sie verbindet die Kostenstelle mit dem fuehrenden System und jeder Kontierung. Kein Stichtag, die bisherige Bezeichnung steht im Audit-Log. Positionen: Knopf "Kostenstelle umbenennen" mit Auswahl und neuer Bezeichnung. Blatt Kostenstellen: eine andere Bezeichnung bei vorhandener Nummer benennt um. Geprueft: Rauchtest Schritt 23 (Bezeichnung neu, Nummer und Kontierung bleiben, Protokoll) 35/35; Integrationstest Umbenennen per Import; alle Migrationen auf leerer Datenbank, zweiter Lauf leer; lint, tsc, types:check, 1014 Unit-Tests, Waechter.
This commit is contained in:
60
db/migrations/20261030100000_kostenstelle_umbenennen.sql
Normal file
60
db/migrations/20261030100000_kostenstelle_umbenennen.sql
Normal file
@@ -0,0 +1,60 @@
|
||||
-- Eine Kostenstelle umbenennen — nur die Bezeichnung.
|
||||
--
|
||||
-- Die Nummer bleibt: sie verbindet die Kostenstelle mit dem führenden System
|
||||
-- und mit jeder Kontierung. Eine Umbenennung hat keinen Stichtag, sie gilt
|
||||
-- auch rückwirkend für jede Anzeige. Die bisherige Bezeichnung steht im
|
||||
-- Protokoll.
|
||||
create or replace function public.rename_cost_center(payload jsonb)
|
||||
returns void
|
||||
language plpgsql
|
||||
set search_path = public, pg_temp
|
||||
as $$
|
||||
declare
|
||||
v_id uuid := (payload->>'cost_center_id')::uuid;
|
||||
v_name text := nullif(btrim(payload->>'name'), '');
|
||||
v_alt cost_centers%rowtype;
|
||||
begin
|
||||
perform require_hr_admin();
|
||||
|
||||
if v_name is null then
|
||||
raise exception 'Bitte eine Bezeichnung angeben.';
|
||||
end if;
|
||||
|
||||
select * into v_alt from cost_centers where id = v_id for update;
|
||||
if not found then
|
||||
raise exception 'Die Kostenstelle existiert nicht.';
|
||||
end if;
|
||||
if v_alt.name = v_name then
|
||||
raise exception 'Die Bezeichnung ist unverändert.';
|
||||
end if;
|
||||
|
||||
update cost_centers set name = v_name where id = v_id;
|
||||
|
||||
insert into audit_log (actor_user_id, actor_name, action, target_label, details)
|
||||
values (app_current_user_id(), current_actor_name(), 'Kostenstelle umbenannt',
|
||||
v_alt.code || ' · ' || v_name,
|
||||
'Bisherige Bezeichnung: ' || v_alt.name);
|
||||
end;
|
||||
$$;
|
||||
|
||||
grant execute on function public.rename_cost_center(jsonb) to alpenwerk_app;
|
||||
|
||||
do $pruefung$
|
||||
declare
|
||||
v_def text;
|
||||
begin
|
||||
select pg_get_functiondef(p.oid) into v_def
|
||||
from pg_proc p join pg_namespace n on n.oid = p.pronamespace
|
||||
where n.nspname = 'public' and p.prokind = 'f' and p.proname = 'rename_cost_center';
|
||||
if position(E'begin\n perform require_hr_admin();' in v_def) = 0
|
||||
or position('insert into audit_log' in v_def) = 0 then
|
||||
raise exception 'rename_cost_center prüft die Rechte nicht oder schreibt kein Protokoll.';
|
||||
end if;
|
||||
if position('set code' in v_def) > 0 then
|
||||
raise exception 'rename_cost_center darf die Nummer nicht ändern.';
|
||||
end if;
|
||||
if (select prosecdef from pg_proc where oid = 'public.rename_cost_center'::regproc) then
|
||||
raise exception 'rename_cost_center darf nicht SECURITY DEFINER sein.';
|
||||
end if;
|
||||
end
|
||||
$pruefung$;
|
||||
Reference in New Issue
Block a user