Skip to content

Commit

Permalink
Merge pull request #3922 from mathesar-foundation/fix_get_current_role
Browse files Browse the repository at this point in the history
Fix logic in `get_current_role`
  • Loading branch information
mathemancer authored Oct 7, 2024
2 parents fd47b3f + 95806ab commit 28cb864
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion db/sql/00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ SELECT jsonb_build_object(
'current_role', msar.get_role(current_role),
'parent_roles', COALESCE(array_remove(
array_agg(
CASE WHEN pg_has_role(role_data.name, current_role, 'USAGE')
CASE WHEN pg_has_role(current_role, role_data.name, 'USAGE')
THEN msar.get_role(role_data.name) END
), NULL
), ARRAY[]::jsonb[])
Expand Down
71 changes: 71 additions & 0 deletions db/sql/test_00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3466,6 +3466,77 @@ END;
$$ LANGUAGE plpgsql;


-- msar.get_current_role ---------------------------------------------------------------------------

CREATE OR REPLACE FUNCTION __setup_get_current_role() RETURNS SETOF TEXT AS $$
BEGIN
CREATE USER parent1;
CREATE ROLE parent2;
CREATE ROLE child_role;
GRANT parent1 TO child_role;
GRANT parent2 TO child_role;
GRANT USAGE ON SCHEMA msar, __msar TO child_role;
-- GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA msar, __msar TO intern_no_pkey;
END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION test_get_current_role() RETURNS SETOF TEXT AS $$
DECLARE
child_role_oid oid;
parent1_oid oid;
parent2_oid oid;
BEGIN
PERFORM __setup_get_current_role();
SET ROLE child_role;
child_role_oid := 'child_role'::regrole::oid;
parent1_oid := 'parent1'::regrole::oid;
parent2_oid := 'parent2'::regrole::oid;
RETURN NEXT is(
msar.get_current_role(),
format($j${
"current_role":{
"oid": %1$s,
"name": "child_role",
"login": false,
"super": false,
"members": null,
"inherits": true,
"create_db": false,
"create_role": false,
"description": null
},
"parent_roles": [
{
"oid": %2$s,
"name": "parent1",
"login": true,
"super": false,
"members": [{"oid": %1$s, "admin": false}],
"inherits": true,
"create_db": false,
"create_role": false,
"description": null
},
{
"oid": %3$s,
"name": "parent2",
"login": false,
"super": false,
"members": [{"oid": %1$s, "admin": false}],
"inherits": true,
"create_db": false,
"create_role": false,
"description": null
}
]
}
$j$, child_role_oid, parent1_oid, parent2_oid
)::jsonb
);
END;
$$ LANGUAGE plpgsql;

-- msar.build_order_by_expr ------------------------------------------------------------------------

CREATE OR REPLACE FUNCTION test_build_order_by_expr() RETURNS SETOF TEXT AS $$
Expand Down

0 comments on commit 28cb864

Please sign in to comment.