Skip to content

Commit

Permalink
Merge pull request #3931 from mathesar-foundation/bugfix_role_grant_q…
Browse files Browse the repository at this point in the history
…uoting

fix quoting for role grant/revoke expressions
  • Loading branch information
Anish9901 authored Oct 7, 2024
2 parents 28cb864 + fe3806c commit 9ac0ca5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions db/sql/00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ CREATE OR REPLACE FUNCTION
msar.build_grant_membership_expr(parent_rol_id regrole, g_roles oid[]) RETURNS TEXT AS $$
SELECT string_agg(
format(
'GRANT %1$s TO %2$s',
'GRANT %1$I TO %2$I',
msar.get_role_name(parent_rol_id),
msar.get_role_name(rol_id)
),
Expand All @@ -1210,7 +1210,7 @@ CREATE OR REPLACE FUNCTION
msar.build_revoke_membership_expr(parent_rol_id regrole, r_roles oid[]) RETURNS TEXT AS $$
SELECT string_agg(
format(
'REVOKE %1$s FROM %2$s',
'REVOKE %1$I FROM %2$I',
msar.get_role_name(parent_rol_id),
msar.get_role_name(rol_id)
),
Expand Down
30 changes: 30 additions & 0 deletions db/sql/test_00_msar.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5440,3 +5440,33 @@ BEGIN
);
END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION test_build_grant_revoke_membership_expr() RETURNS SETOF TEXT AS $$
BEGIN
CREATE USER "Alice";
CREATE USER "Bob";
CREATE USER carol;
RETURN NEXT is(
msar.build_grant_membership_expr('"Alice"'::regrole::oid, ARRAY['"Bob"'::regrole::oid]),
E'GRANT "Alice" TO "Bob";\n'
);
RETURN NEXT is(
msar.build_grant_membership_expr(
'"Alice"'::regrole::oid, ARRAY['"Bob"'::regrole::oid, 'carol'::regrole::oid]
),
E'GRANT "Alice" TO "Bob";\nGRANT "Alice" TO carol;\n'
);

RETURN NEXT is(
msar.build_revoke_membership_expr('"Alice"'::regrole::oid, ARRAY['"Bob"'::regrole::oid]),
E'REVOKE "Alice" FROM "Bob";\n'
);
RETURN NEXT is(
msar.build_revoke_membership_expr(
'"Alice"'::regrole::oid, ARRAY['"Bob"'::regrole::oid, 'carol'::regrole::oid]
),
E'REVOKE "Alice" FROM "Bob";\nREVOKE "Alice" FROM carol;\n'
);
END;
$$ LANGUAGE plpgsql;

0 comments on commit 9ac0ca5

Please sign in to comment.