diff options
| author | ckonstanski <carlos.konstanski@olo.com> | 2024-05-25 18:03:25 -0600 |
|---|---|---|
| committer | ckonstanski <carlos.konstanski@olo.com> | 2024-05-25 18:03:25 -0600 |
| commit | b8423f4d05c75094b7b9d09c6f0bb353acc9be1c (patch) | |
| tree | 3732f71f84191b26f038130c2220fb502d738251 /sql/functions/auth.superuser_p.sql | |
initial commit
Diffstat (limited to 'sql/functions/auth.superuser_p.sql')
| -rw-r--r-- | sql/functions/auth.superuser_p.sql | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/sql/functions/auth.superuser_p.sql b/sql/functions/auth.superuser_p.sql new file mode 100644 index 0000000..f6865ec --- /dev/null +++ b/sql/functions/auth.superuser_p.sql @@ -0,0 +1,34 @@ +drop function auth.superuser_p ( + p_user_id bigint +); + +create or replace function auth.superuser_p ( + p_user_id bigint +) +returns bool +as $$ +declare + l_user_id bigint; +begin + with roles as ( + select urg.user_id, + rg.id as role_group_id, + rg.name + from auth.users_role_groups urg + inner join auth.role_groups_roles rgr + on urg.role_group_id = rgr.role_group_id + inner join auth.role_groups rg + on rgr.role_group_id = rg.id + where urg.user_id = p_user_id + and rg.name = 'superuser' + ) + select user_id into l_user_id + from roles; + + if(l_user_id is null) then + return false::bool; + else + return true::bool; + end if; +end; +$$ language plpgsql; |
