jaitaiwan
05/18/2022, 11:49 PMcreate or replace function public.user_orgs() returns uuid[] as $$
select array_agg(org_id) from users_orgs where user_id = auth.uid() limit 1;
$$ language sql stable;
And the RLS policy has a WITH CHECK
that I'm trying to make work like this:
"admin" in (select roles from users_orgs where user_id = auth.uid() and org_id = orgs.id)
If I use admin in "
quotes it interprets it as a column name and if I use '
quotes it has a malformed array error.tourdownunder
05/18/2022, 11:56 PMtourdownunder
05/19/2022, 12:00 AMuser_orgs
returns type uuid[]
how are you magically naming it roles
when you do call the function / rpc users_orgs.roles
jaitaiwan
05/19/2022, 12:06 AMusers_orgs
and the function is user_orgs
so that might be where there's some confusion. The roles
column in users_orgs
is text[]
. Single quotes cause: malformed array literal: "admin"
tourdownunder
05/19/2022, 12:17 AMjaitaiwan
05/19/2022, 12:18 AMjaitaiwan
05/19/2022, 12:18 AM'admin'
as an array and getting upset about it I assume?tourdownunder
05/19/2022, 12:18 AMjaitaiwan
05/19/2022, 12:19 AMroles
which is an arraytourdownunder
05/19/2022, 12:19 AMjaitaiwan
05/19/2022, 12:20 AMCREATE POLICY "Allow org modifications by admins" ON "public"."orgs"
AS PERMISSIVE FOR UPDATE
TO authenticated, service_role
USING ('admin' in (select roles from users_orgs where user_id = auth.uid() and org_id = orgs.id limit 1))
tourdownunder
05/19/2022, 12:21 AM'admin'
to within the where statement and remove the in all together.jaitaiwan
05/19/2022, 12:22 AMwhere roles = 'admin'
you mean? and it will automagically look into the array?tourdownunder
05/19/2022, 12:23 AMtourdownunder
05/19/2022, 12:23 AMin
tourdownunder
05/19/2022, 12:24 AMtourdownunder
05/19/2022, 12:25 AMtourdownunder
05/19/2022, 12:25 AM'admin'
as an array with the only 1 element to have some success.tourdownunder
05/19/2022, 12:27 AMjaitaiwan
05/19/2022, 12:27 AM