Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
CREATE OR REPLACE FUNCTION public.my_user_accounts() RETURNS SETOF UUID
STABLE SECURITY DEFINER
SET search_path = ''
LANGUAGE sql
AS $$
SELECT auth.uid() WHERE auth.uid() IS NOT NULL UNION
SELECT '00000000-0000-0000-0000-000000000000'::uuid UNION
SELECT group_id FROM public.group_membership
WHERE member_id = auth.uid();
$$;


CREATE OR REPLACE FUNCTION public.can_access_account(account_uid UUID) RETURNS boolean
STABLE SECURITY DEFINER
SET search_path = ''
LANGUAGE sql
AS $$
SELECT account_uid = auth.uid() OR account_uid = '00000000-0000-0000-0000-000000000000'::uuid OR EXISTS (
SELECT 1 FROM public.group_membership
WHERE member_id = auth.uid() AND group_id=account_uid
LIMIT 1
);
$$;

GRANT SELECT ON TABLE public."ResourceAccess" TO anon;
GRANT SELECT ON TABLE public."Document" TO anon;
GRANT SELECT ON TABLE public."Content" TO anon;
GRANT SELECT ON TABLE public."Concept" TO anon;
Comment thread
maparent marked this conversation as resolved.

INSERT INTO auth.users (instance_id, id, aud, role, created_at, updated_at, is_super_admin, is_anonymous)
VALUES ('00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000', 'anon', 'anon', now(), now(), false, true);
7 changes: 6 additions & 1 deletion packages/database/supabase/schemas/account.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-- Anonymous pseudo-user
INSERT INTO auth.users (instance_id, id, aud, role, created_at, updated_at, is_super_admin, is_anonymous)
VALUES ('00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000', 'anon', 'anon', now(), now(), false, true);

CREATE TYPE public."AgentType" AS ENUM (
'person',
'organization',
Expand Down Expand Up @@ -204,7 +208,7 @@ STABLE SECURITY DEFINER
SET search_path = ''
LANGUAGE sql
AS $$
SELECT account_uid = auth.uid() OR EXISTS (
SELECT account_uid = auth.uid() OR account_uid = '00000000-0000-0000-0000-000000000000'::uuid OR EXISTS (
SELECT 1 FROM public.group_membership
WHERE member_id = auth.uid() AND group_id=account_uid
LIMIT 1
Expand All @@ -219,6 +223,7 @@ SET search_path = ''
LANGUAGE sql
AS $$
SELECT auth.uid() WHERE auth.uid() IS NOT NULL UNION
SELECT '00000000-0000-0000-0000-000000000000'::uuid UNION
SELECT group_id FROM public.group_membership
WHERE member_id = auth.uid();
$$;
Expand Down
1 change: 1 addition & 0 deletions packages/database/supabase/schemas/concept.sql
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ ADD CONSTRAINT "Concept_space_id_fkey" FOREIGN KEY (


REVOKE ALL ON TABLE public."Concept" FROM anon;
GRANT SELECT ON TABLE public."Concept" TO anon;
GRANT ALL ON TABLE public."Concept" TO authenticated;
GRANT ALL ON TABLE public."Concept" TO service_role;

Expand Down
3 changes: 3 additions & 0 deletions packages/database/supabase/schemas/content.sql
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,15 @@ CREATE INDEX resource_access_content_local_id_idx ON public."ResourceAccess" (so
GRANT ALL ON TABLE public."ResourceAccess" TO authenticated;
GRANT ALL ON TABLE public."ResourceAccess" TO service_role;
REVOKE ALL ON TABLE public."ResourceAccess" FROM anon;
GRANT SELECT ON TABLE public."ResourceAccess" TO anon;

REVOKE ALL ON TABLE public."Document" FROM anon;
GRANT SELECT ON TABLE public."Document" TO anon;
GRANT ALL ON TABLE public."Document" TO authenticated;
GRANT ALL ON TABLE public."Document" TO service_role;

REVOKE ALL ON TABLE public."Content" FROM anon;
GRANT SELECT ON TABLE public."Content" TO anon;
GRANT ALL ON TABLE public."Content" TO authenticated;
GRANT ALL ON TABLE public."Content" TO service_role;

Expand Down
Loading