Skip to content

Commit

Permalink
fix: add computed column to application to display user's edit permis…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
dleard committed Jul 31, 2020
1 parent 9052993 commit 91b23a3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
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;
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;
1 change: 1 addition & 0 deletions schema/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,4 @@ trigger_functions/request_for_organisation_access [trigger_functions/request_for
@v1.3.0 2020-07-29T20:54:44Z Matthieu Foucault <matthieu@button.is> # release v1.3.0
tables/application_revision_001 [tables/application_revision] 2020-07-22T23:13:57Z Dylan Leard <dylan@button.is> # Migration: add override column to application_revision
database_functions/read_only_user_policies [schema_ggircs_portal schema_ggircs_portal_private] 2020-07-30T18:10:31Z Dylan Leard <dylan@button.is> # function adds RLS policies for the read_only_user (metabase)
computed_columns/application_current_user_can_edit [tables/ciip_user_organisation tables/application] 2020-07-30T23:55:55Z Dylan Leard <dylan@button.is> # computed column returns a boolean value: whether the current user has edit permission on the application
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;

0 comments on commit 91b23a3

Please sign in to comment.