Skip to content

Commit

Permalink
fix: implement redirect in ApplicationWizard for users with no edit p…
Browse files Browse the repository at this point in the history
…ermission (certifier)
  • Loading branch information
dleard committed Jul 31, 2020
1 parent 91b23a3 commit 3251091
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
14 changes: 14 additions & 0 deletions app/containers/Applications/ApplicationWizard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ const ApplicationWizard = ({query}) => {
const {formResultId} = router.query;
const confirmationPage = Boolean(router.query.confirmationPage);
const orderedFormResults = application.orderedFormResults.edges;

// Redirect a certifier given a bad link to the certify page for the application
if (!application.currentUserCanEdit) {
router.push({
pathname: '/certifier/certify',
query: {
applicationId: application.id,
version: router.query.version
}
});
return null;
}

if (!confirmationPage && !formResultId) {
setRouterQueryParam(
router,
Expand Down Expand Up @@ -96,6 +109,7 @@ export default createFragmentContainer(ApplicationWizard, {
) {
application(id: $applicationId) {
id
currentUserCanEdit
orderedFormResults(versionNumberInput: $version) {
edges {
node {
Expand Down
1 change: 1 addition & 0 deletions app/pages/reporter/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Application extends Component<Props> {
query {
application(id: $applicationId) {
id
currentUserCanEdit
latestDraftRevision {
versionNumber
legalDisclaimerAccepted
Expand Down
5 changes: 5 additions & 0 deletions app/server/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ type Application implements Node {
orderBy: [CertificationUrlsOrderBy!] = [PRIMARY_KEY_ASC]
): CertificationUrlsConnection!

"""
returns a boolean value based on whether the current user has edit permission on the application
"""
currentUserCanEdit: Boolean

"""Reads a single `Facility` that is related to this `Application`."""
facilityByFacilityId: Facility

Expand Down
12 changes: 12 additions & 0 deletions app/server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5795,6 +5795,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "currentUserCanEdit",
"description": "returns a boolean value based on whether the current user has edit permission on the application",
"args": [],
"type": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "facilityByFacilityId",
"description": "Reads a single `Facility` that is related to this `Application`.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ begin;
$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);
current_user_id int;
org_id int;
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'));
current_user_id:= (select id from ggircs_portal.ciip_user where uuid=(select sub from ggircs_portal.session()));
org_id:= (select organisation_id from ggircs_portal.application a join ggircs_portal.facility f on a.facility_id = f.id and a.id=app.id);
if (select exists(select * from ggircs_portal.ciip_user_organisation where user_id=current_user_id and organisation_id=org_id and status='approved')) then
return true;
end if;
return false;
end;
$body$
language 'plpgsql' stable;
Expand Down

0 comments on commit 3251091

Please sign in to comment.