-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avniproject/avni-webapp#1304 - function to grant permission only on t…
…able
- Loading branch information
1 parent
9917dd4
commit e9f4e21
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
avni-server-api/src/main/resources/db/migration/V1_339_6__GrantPermissionOnNewOrgTables.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
CREATE OR REPLACE FUNCTION grant_all_on_table(rolename text, tablename text) | ||
RETURNS text AS | ||
$body$ | ||
BEGIN | ||
EXECUTE ( | ||
SELECT 'GRANT ALL ON TABLE ' | ||
|| tablename | ||
|| ' TO ' || quote_ident(rolename) | ||
); | ||
|
||
EXECUTE ( | ||
SELECT 'GRANT SELECT ON ' | ||
|| tablename | ||
|| ' TO ' || quote_ident(rolename) | ||
); | ||
|
||
EXECUTE 'GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO ' || quote_ident(rolename) || ''; | ||
RETURN 'ALL PERMISSIONS GRANTED TO ' || quote_ident(rolename); | ||
END; | ||
$body$ LANGUAGE plpgsql; | ||
|
||
SELECT grant_all_on_table(a.rolname, 'organisation_category') FROM pg_roles a WHERE pg_has_role('openchs', a.oid, 'member'); | ||
SELECT grant_all_on_table(a.rolname, 'organisation_status') FROM pg_roles a WHERE pg_has_role('openchs', a.oid, 'member'); |