summaryrefslogtreecommitdiff
path: root/sql/functions/auth.superuser_p.sql
blob: f6865ec3747815cc31fcc9d5c4fa542b4f12854e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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;