MED-109: add doctor role and basic view (#45)

* MED-109: add doctor role and basic view

* add role to accounts

* remove old super admin and doctor sql
This commit is contained in:
Helena
2025-08-13 12:28:50 +03:00
committed by GitHub
parent ce7b04fda8
commit 3c6c86c7c8
32 changed files with 562 additions and 35 deletions

View File

@@ -0,0 +1,37 @@
create type "medreport"."application_role" as enum ('user', 'doctor', 'super_admin');
ALTER TABLE medreport.accounts
ADD COLUMN "application_role" medreport.application_role NOT NULL DEFAULT 'user';
CREATE OR REPLACE FUNCTION medreport.is_doctor()
RETURNS BOOLEAN
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
BEGIN
RETURN medreport.is_aal2() AND (EXISTS (
SELECT 1
FROM medreport.accounts
WHERE primary_owner_user_id = auth.uid()
AND application_role = 'doctor'
));
END;
$$;
grant execute on function medreport.is_doctor() to authenticated;
CREATE OR REPLACE FUNCTION medreport.is_super_admin()
RETURNS BOOLEAN
LANGUAGE plpgsql
SECURITY DEFINER
AS $$
BEGIN
RETURN medreport.is_aal2() AND (EXISTS (
SELECT 1
FROM medreport.accounts
WHERE primary_owner_user_id = auth.uid()
AND application_role = 'super_admin'
));
END;
$$;
grant execute on function medreport.is_super_admin() to authenticated;

View File

@@ -1,2 +0,0 @@
-- Update your user role to Super Admin
update auth.users set raw_app_meta_data='{"provider": "email", "providers": ["email"], "role": "super-admin" }' where email='test2@test.ee';