-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into lwj/read-only-layer-support
- Loading branch information
Showing
16 changed files
with
354 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
CREATE | ||
OR REPLACE FUNCTION public.anonymize_profile() | ||
RETURNS trigger | ||
LANGUAGE plpgsql | ||
SECURITY DEFINER | ||
AS | ||
$$ | ||
BEGIN | ||
UPDATE public.profiles | ||
SET first_name = '', last_name = '', nickname = '', email = '', avatar_url = '' | ||
WHERE id = OLD.id; | ||
RETURN new; | ||
END; | ||
$$ | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CREATE OR REPLACE FUNCTION change_org_group_membership(_user_id uuid, _new_group_id uuid) RETURNS BOOLEAN | ||
AS $body$ | ||
BEGIN | ||
|
||
IF public.is_admin_organization(auth.uid()) THEN | ||
UPDATE public.group_users SET type_id = _new_group_id WHERE user_id = _user_id AND group_type = 'organization'; | ||
RETURN TRUE; | ||
END IF; | ||
|
||
RETURN FALSE; | ||
END; | ||
$body$ LANGUAGE plpgsql SECURITY DEFINER; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CREATE OR REPLACE FUNCTION delete_user(_user_id uuid) RETURNS BOOLEAN AS $$ | ||
BEGIN | ||
IF is_admin_organization(auth.uid()) THEN | ||
DELETE FROM auth.users WHERE auth.users.id = _user_id; | ||
UPDATE public.profiles | ||
SET first_name = '', last_name = '', nickname = '', email = '', avatar_url = '' | ||
WHERE id = _user_id; | ||
RETURN TRUE; | ||
END IF; | ||
RETURN FALSE; | ||
END $$ LANGUAGE 'plpgsql' SECURITY DEFINER; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
CREATE OR REPLACE FUNCTION get_profiles_extended() RETURNS TABLE ( id uuid, | ||
nickname VARCHAR, | ||
first_name VARCHAR, | ||
last_name VARCHAR, | ||
avatar_url VARCHAR, | ||
email_address VARCHAR, | ||
last_sign_in_at timestamptz, | ||
org_group_id uuid, | ||
org_group_name VARCHAR ) | ||
AS $body$ | ||
BEGIN | ||
|
||
IF public.is_admin_organization(auth.uid()) THEN | ||
RETURN QUERY | ||
SELECT p.id, | ||
p.nickname, | ||
p.first_name, | ||
p.last_name, | ||
p.avatar_url, | ||
u.email, | ||
u.last_sign_in_at, | ||
og.id, | ||
og.name | ||
FROM public.profiles p | ||
INNER JOIN public.group_users gu ON p.id = gu.user_id | ||
AND gu.group_type = 'organization' | ||
INNER JOIN public.organization_groups og ON og.id = gu.type_id | ||
INNER JOIN auth.users u ON u.id = p.id; | ||
END IF; | ||
END; | ||
$body$ LANGUAGE plpgsql SECURITY DEFINER; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
DROP POLICY IF EXISTS "Users with correct policies can SELECT on installed_plugins" ON public.installed_plugins; | ||
|
||
CREATE POLICY "Users with correct policies can SELECT on installed_plugins" ON public.installed_plugins FOR SELECT TO authenticated | ||
USING ( | ||
(public.check_action_policy_organization(auth.uid(), 'installed_plugins', 'SELECT') OR | ||
public.check_action_policy_project(auth.uid(), 'installed_plugins', 'SELECT', project_id)) | ||
); | ||
|
||
DROP POLICY IF EXISTS "Users with correct policies can INSERT on installed_plugins" ON public.installed_plugins; | ||
|
||
CREATE POLICY "Users with correct policies can INSERT on installed_plugins" ON public.installed_plugins FOR INSERT TO authenticated | ||
WITH CHECK (public.check_action_policy_organization(auth.uid(), 'installed_plugins', 'INSERT') OR | ||
public.check_action_policy_project(auth.uid(), 'installed_plugins', 'INSERT', project_id)); | ||
|
||
DROP POLICY IF EXISTS "Users with correct policies can UPDATE on installed_plugins" ON public.installed_plugins; | ||
|
||
CREATE POLICY "Users with correct policies can UPDATE on installed_plugins" ON public.installed_plugins FOR UPDATE TO authenticated | ||
USING ( | ||
public.check_action_policy_organization(auth.uid(), 'installed_plugins', 'UPDATE') OR | ||
public.check_action_policy_project(auth.uid(), 'installed_plugins', 'UPDATE', project_id) | ||
) | ||
WITH CHECK (public.check_action_policy_organization(auth.uid(), 'installed_plugins', 'UPDATE') OR | ||
public.check_action_policy_project(auth.uid(), 'installed_plugins', 'UPDATE', project_id)); | ||
|
||
DROP POLICY IF EXISTS "Users with correct policies can DELETE on installed_plugins" ON public.installed_plugins; | ||
|
||
CREATE POLICY "Users with correct policies can DELETE on installed_plugins" ON public.installed_plugins FOR DELETE TO authenticated | ||
USING (public.check_action_policy_organization(auth.uid(), 'installed_plugins', 'DELETE') OR | ||
public.check_action_policy_project(auth.uid(), 'installed_plugins', 'DELETE', project_id)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
CREATE TABLE installed_plugins | ||
( | ||
id uuid NOT NULL DEFAULT uuid_generate_v4() PRIMARY KEY, | ||
created_at timestamp WITH TIME ZONE DEFAULT NOW(), | ||
created_by uuid REFERENCES public.profiles, | ||
updated_at timestamptz, | ||
updated_by uuid REFERENCES public.profiles, | ||
project_id uuid REFERENCES public.projects NOT NULL, | ||
plugin_name VARCHAR NOT NULL, | ||
plugin_id uuid NOT NULL, | ||
plugin_settings json | ||
) | ||
|
5 changes: 5 additions & 0 deletions
5
SQL Scripts/triggers/installed_plugins/on_installed_plugin_created.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
DROP TRIGGER IF EXISTS on_installed_plugin_updated | ||
ON public.installed_plugins; | ||
CREATE TRIGGER on_installed_plugin_updated | ||
BEFORE INSERT ON public.installed_plugins | ||
FOR EACH ROW EXECUTE PROCEDURE create_dates_and_user(); |
5 changes: 5 additions & 0 deletions
5
SQL Scripts/triggers/installed_plugins/on_installed_plugin_updated.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
DROP TRIGGER IF EXISTS on_installed_plugin_updated | ||
ON public.installed_plugins; | ||
CREATE TRIGGER on_installed_plugin_updated | ||
BEFORE UPDATE ON public.installed_plugins | ||
FOR EACH ROW EXECUTE PROCEDURE update_dates_and_user(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DROP TRIGGER IF EXISTS on_auth_user_deleted ON auth.users; | ||
|
||
CREATE TRIGGER on_auth_user_deleted AFTER DELETE ON auth.users FOR EACH ROW EXECUTE FUNCTION anonymize_profile (); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
supabase/migrations/20240212134500_user_management_support.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
set check_function_bodies = off; | ||
|
||
CREATE OR REPLACE FUNCTION public.anonymize_profile() | ||
RETURNS trigger | ||
LANGUAGE plpgsql | ||
SECURITY DEFINER | ||
AS $function$ | ||
BEGIN | ||
UPDATE public.profiles | ||
SET first_name = '', last_name = '', nickname = '', email = '', avatar_url = '' | ||
WHERE id = OLD.id; | ||
RETURN new; | ||
END; | ||
$function$ | ||
; | ||
|
||
CREATE OR REPLACE FUNCTION public.change_org_group_membership(_user_id uuid, _new_group_id uuid) | ||
RETURNS boolean | ||
LANGUAGE plpgsql | ||
SECURITY DEFINER | ||
AS $function$ | ||
BEGIN | ||
|
||
IF public.is_admin_organization(auth.uid()) THEN | ||
UPDATE public.group_users SET type_id = _new_group_id WHERE user_id = _user_id AND group_type = 'organization'; | ||
RETURN TRUE; | ||
END IF; | ||
|
||
RETURN FALSE; | ||
END; | ||
$function$ | ||
; | ||
|
||
CREATE OR REPLACE FUNCTION public.delete_user(_user_id uuid) | ||
RETURNS boolean | ||
LANGUAGE plpgsql | ||
SECURITY DEFINER | ||
AS $function$ | ||
BEGIN | ||
IF is_admin_organization(auth.uid()) THEN | ||
DELETE FROM auth.users WHERE auth.users.id = _user_id; | ||
UPDATE public.profiles | ||
SET first_name = '', last_name = '', nickname = '', email = '', avatar_url = '' | ||
WHERE id = _user_id; | ||
RETURN TRUE; | ||
END IF; | ||
RETURN FALSE; | ||
END $function$ | ||
; | ||
|
||
CREATE OR REPLACE FUNCTION public.get_profiles_extended() | ||
RETURNS TABLE(id uuid, nickname character varying, first_name character varying, last_name character varying, avatar_url character varying, email_address character varying, last_sign_in_at timestamp with time zone, org_group_id uuid, org_group_name character varying) | ||
LANGUAGE plpgsql | ||
SECURITY DEFINER | ||
AS $function$ | ||
BEGIN | ||
|
||
IF public.is_admin_organization(auth.uid()) THEN | ||
RETURN QUERY | ||
SELECT p.id, | ||
p.nickname, | ||
p.first_name, | ||
p.last_name, | ||
p.avatar_url, | ||
u.email, | ||
u.last_sign_in_at, | ||
og.id, | ||
og.name | ||
FROM public.profiles p | ||
INNER JOIN public.group_users gu ON p.id = gu.user_id | ||
AND gu.group_type = 'organization' | ||
INNER JOIN public.organization_groups og ON og.id = gu.type_id | ||
INNER JOIN auth.users u ON u.id = p.id; | ||
END IF; | ||
END; | ||
$function$ | ||
; | ||
|
||
|
Oops, something went wrong.