forked from fahrPool/fahrPool
feat: Spalte firmen.app_icon_pfad fuer das PWA-App-Icon
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c2cd5802c6
commit
6bc029f22b
|
|
@ -0,0 +1,9 @@
|
|||
-- PWA-App-Icon pro Firma. Liegt im Bucket firmen-logos (Storage-RLS: Ordner = eigene
|
||||
-- Firma, Schreiben nur Admin). Der Pfad muss exakt dem Muster <firma-id>/app-icon-<zahl>.<endung>
|
||||
-- entsprechen (analog firmen_logo_pfad_eigener_ordner, kein ../ in fremde Ordner).
|
||||
alter table public.firmen
|
||||
add column app_icon_pfad text;
|
||||
|
||||
alter table public.firmen
|
||||
add constraint firmen_app_icon_pfad_eigener_ordner
|
||||
check (app_icon_pfad is null or app_icon_pfad ~ ('^' || id::text || '/app-icon-[0-9]+\.(png|jpg|svg)$'));
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
begin;
|
||||
select plan(7);
|
||||
|
||||
insert into public.firmen (id, name) values ('00000000-0000-0000-0000-00000000f002', 'Firma B');
|
||||
|
||||
insert into auth.users (id, email) values
|
||||
('a0000000-0000-0000-0000-0000000000a2', 'dispo-a@icon.test.local'),
|
||||
('b0000000-0000-0000-0000-0000000000b1', 'admin-b@icon.test.local'),
|
||||
('b0000000-0000-0000-0000-0000000000b2', 'dispo-b@icon.test.local');
|
||||
|
||||
update public.profiles set firma_id = '00000000-0000-0000-0000-00000000f001', role = 'disponent' where id = 'a0000000-0000-0000-0000-0000000000a2';
|
||||
update public.profiles set firma_id = '00000000-0000-0000-0000-00000000f002', role = 'admin' where id = 'b0000000-0000-0000-0000-0000000000b1';
|
||||
update public.profiles set firma_id = '00000000-0000-0000-0000-00000000f002', role = 'disponent' where id = 'b0000000-0000-0000-0000-0000000000b2';
|
||||
|
||||
-- ====================== Disponent B: darf die Firma nicht aendern
|
||||
set local role authenticated;
|
||||
set local request.jwt.claims to '{"sub": "b0000000-0000-0000-0000-0000000000b2", "role": "authenticated"}';
|
||||
|
||||
update public.firmen set app_icon_pfad = '00000000-0000-0000-0000-00000000f002/app-icon-1.png'
|
||||
where id = '00000000-0000-0000-0000-00000000f002';
|
||||
select is((select app_icon_pfad from public.firmen where id = '00000000-0000-0000-0000-00000000f002'), null,
|
||||
'Disponent kann app_icon_pfad nicht setzen');
|
||||
|
||||
-- ====================== Admin B
|
||||
set local request.jwt.claims to '{"sub": "b0000000-0000-0000-0000-0000000000b1", "role": "authenticated"}';
|
||||
|
||||
select lives_ok(
|
||||
$$ update public.firmen set app_icon_pfad = '00000000-0000-0000-0000-00000000f002/app-icon-1.png'
|
||||
where id = '00000000-0000-0000-0000-00000000f002' $$,
|
||||
'Admin setzt App-Icon-Pfad im eigenen Firmenordner'
|
||||
);
|
||||
|
||||
select throws_ok(
|
||||
$$ update public.firmen set app_icon_pfad = '00000000-0000-0000-0000-00000000f002/../00000000-0000-0000-0000-00000000f001/app-icon-1.png'
|
||||
where id = '00000000-0000-0000-0000-00000000f002' $$,
|
||||
'23514', null,
|
||||
'Pfad mit ../ in den Ordner einer fremden Firma wird abgelehnt'
|
||||
);
|
||||
|
||||
select throws_ok(
|
||||
$$ update public.firmen set app_icon_pfad = '00000000-0000-0000-0000-00000000f002/x.png'
|
||||
where id = '00000000-0000-0000-0000-00000000f002' $$,
|
||||
'23514', null,
|
||||
'Pfad im eigenen Ordner, aber nicht im Format app-icon-<zahl>.<endung>, wird abgelehnt'
|
||||
);
|
||||
|
||||
select throws_ok(
|
||||
$$ update public.firmen set app_icon_pfad = '00000000-0000-0000-0000-00000000f001/app-icon-1.png'
|
||||
where id = '00000000-0000-0000-0000-00000000f002' $$,
|
||||
'23514', null,
|
||||
'Pfad im Ordner einer fremden Firma wird abgelehnt'
|
||||
);
|
||||
|
||||
-- ====================== Nutzer A: sieht Firma B nicht
|
||||
set local request.jwt.claims to '{"sub": "a0000000-0000-0000-0000-0000000000a2", "role": "authenticated"}';
|
||||
|
||||
select is_empty(
|
||||
$$ select app_icon_pfad from public.firmen where id = '00000000-0000-0000-0000-00000000f002' $$,
|
||||
'Nutzer von Firma A liest app_icon_pfad von Firma B nicht'
|
||||
);
|
||||
|
||||
reset role;
|
||||
select is((select app_icon_pfad from public.firmen where id = '00000000-0000-0000-0000-00000000f002'),
|
||||
'00000000-0000-0000-0000-00000000f002/app-icon-1.png', 'Gueltiger Pfad ist gespeichert');
|
||||
|
||||
select * from finish();
|
||||
rollback;
|
||||
|
|
@ -6,12 +6,13 @@ export type Firma = {
|
|||
id: string;
|
||||
name: string;
|
||||
logo_pfad: string | null;
|
||||
app_icon_pfad: string | null;
|
||||
whatsapp_empfaenger: string | null;
|
||||
farbe_primaer: string | null;
|
||||
farbe_dunkel: string | null;
|
||||
};
|
||||
|
||||
const FIRMA_SELECT = "id, name, logo_pfad, whatsapp_empfaenger, farbe_primaer, farbe_dunkel";
|
||||
const FIRMA_SELECT = "id, name, logo_pfad, app_icon_pfad, whatsapp_empfaenger, farbe_primaer, farbe_dunkel";
|
||||
|
||||
// Mit dem Nutzer-Client liefert RLS nur die eigene, aktive Firma: null heisst
|
||||
// fremd, deaktiviert oder nicht vorhanden.
|
||||
|
|
|
|||
Loading…
Reference in New Issue