-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add computed column to application to display user's edit permis…
…sion
- Loading branch information
Showing
4 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
schema/deploy/computed_columns/application_current_user_can_edit.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,27 @@ | ||
-- Deploy ggircs-portal:computed_columns/application_current_user_can_edit to pg | ||
-- requires: tables/ciip_user_organisation | ||
-- requires: tables/application | ||
|
||
begin; | ||
|
||
create or replace function ggircs_portal.application_current_user_can_edit( | ||
app ggircs_portal.application | ||
) | ||
returns boolean | ||
as | ||
$body$ | ||
declare | ||
return_value boolean; | ||
current_user_id = (select id from ggircs_portal.ciip_user where uuid=(select sub from ggircs_portal.session)); | ||
org_id = (select organisation_id from app join ggircs_portal.facility f on app.facility_id = f.id); | ||
begin | ||
return (select exists(select * from ggircs_portal.ciip_user_organisation where user_id=current_user_id and organisation_id=org_id and status='approved')); | ||
end; | ||
$body$ | ||
language 'plpgsql' stable; | ||
|
||
grant execute on function ggircs_portal.application_current_user_can_edit to ciip_administrator, ciip_analyst, ciip_industry_user; | ||
|
||
comment on function ggircs_portal.application_current_user_can_edit is 'returns a boolean value based on whether the current user has edit permission on the application'; | ||
|
||
commit; |
7 changes: 7 additions & 0 deletions
7
schema/revert/computed_columns/application_current_user_can_edit.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,7 @@ | ||
-- Revert ggircs-portal:computed_columns/application_current_user_can_edit from pg | ||
|
||
begin; | ||
|
||
drop function ggircs_portal.application_current_user_can_edit; | ||
|
||
commit; |
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
7 changes: 7 additions & 0 deletions
7
schema/verify/computed_columns/application_current_user_can_edit.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,7 @@ | ||
-- Verify ggircs-portal:computed_columns/application_current_user_can_edit on pg | ||
|
||
begin; | ||
|
||
select pg_get_functiondef('ggircs_portal.application_current_user_can_edit(ggircs_portal.application)'::regprocedure); | ||
|
||
rollback; |