23 lines
525 B
PL/PgSQL
23 lines
525 B
PL/PgSQL
create or replace function public.is_company_admin(account_slug text)
|
|
returns boolean
|
|
set search_path = ''
|
|
language plpgsql
|
|
as $$
|
|
declare
|
|
is_owner boolean;
|
|
begin
|
|
select exists (
|
|
select 1
|
|
from public.accounts_memberships am
|
|
join public.accounts a on a.id = am.account_id
|
|
where am.user_id = auth.uid()
|
|
and am.account_role = 'owner'
|
|
and a.slug = account_slug
|
|
) into is_owner;
|
|
|
|
return is_owner;
|
|
end;
|
|
$$;
|
|
|
|
grant execute on function public.is_company_admin(text) to authenticated, service_role;
|