generated from hmcts/expressjs-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PRL-6778 * PRL-6778 * 6778 * 6784 * 6782+5898 * lint * 6810 * 6782 * 6782 * feat(6783): Add access control for AWP (#1723) * PRL-6812 * PRL-6812 --------- Co-authored-by: vivek-sekhar <111058132+vivek-sekhar@users.noreply.github.com>
- Loading branch information
1 parent
6d3f60d
commit a754dee
Showing
34 changed files
with
234 additions
and
182 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
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
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
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
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
25 changes: 25 additions & 0 deletions
25
src/main/steps/application-within-proceedings/routeGuard.ts
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,25 @@ | ||
import { NextFunction, Response } from 'express'; | ||
|
||
import { AppRequest } from '../../app/controller/AppRequest'; | ||
import { isRepresentedBySolicotor } from '../../steps/common/task-list/utils'; | ||
import { applyParms } from '../../steps/common/url-parser'; | ||
import { DASHBOARD_URL, FETCH_CASE_DETAILS } from '../../steps/urls'; | ||
|
||
export const routeGuard = { | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
get: async (req: AppRequest, res: Response, next: NextFunction) => { | ||
try { | ||
if (!req.session?.userCase?.id) { | ||
return res.redirect(DASHBOARD_URL); | ||
} | ||
|
||
if (isRepresentedBySolicotor(req.session.userCase, req.session.user.id)) { | ||
return res.redirect(applyParms(FETCH_CASE_DETAILS, { caseId: req.session.userCase.id })); | ||
} | ||
|
||
next(); | ||
} catch (error) { | ||
return res.redirect('/error'); | ||
} | ||
}, | ||
}; |
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
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
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
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
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
42 changes: 42 additions & 0 deletions
42
...n/contact-preference/choose-a-contact-preference/ReviewContactPreferencePostController.ts
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,42 @@ | ||
import autobind from 'autobind-decorator'; | ||
import type { Response } from 'express'; | ||
|
||
import { AppRequest } from '../../../../app/controller/AppRequest'; | ||
import { AnyObject, PostController } from '../../../../app/controller/PostController'; | ||
import { Form, FormFields, FormFieldsFn } from '../../../../app/form/Form'; | ||
import { applyParms } from '../../../../steps/common/url-parser'; | ||
import { getCasePartyType } from '../../../../steps/prl-cases/dashboard/utils'; | ||
import { getPartyDetails } from '../../../../steps/tasklistresponse/utils'; | ||
import { PageLink, REVIEW_CONTACT_PREFERENCE } from '../../../../steps/urls'; | ||
import { saveAndRedirectContactDetailsAndPreference } from '../../confirm-contact-details/checkanswers/ConfirmContactDetailsPostController'; | ||
|
||
@autobind | ||
export default class ReviewContactPreferencePostController extends PostController<AnyObject> { | ||
constructor(protected readonly fields: FormFields | FormFieldsFn) { | ||
super(fields); | ||
} | ||
|
||
public async post(req: AppRequest<AnyObject>, res: Response): Promise<void> { | ||
const fields = typeof this.fields === 'function' ? this.fields(req.session.userCase, req) : this.fields; | ||
const form = new Form(fields); | ||
const { _csrf, ...formData } = form.getParsedBody(req.body); | ||
const { user, userCase } = req.session; | ||
Object.assign(userCase, formData); | ||
req.session.applicationSettings = { ...req.session.applicationSettings, navFromContactPreferences: true }; | ||
const partyType = getCasePartyType(userCase, user.id); | ||
const partyDetailsContactPreference = getPartyDetails(userCase, user.id)?.contactPreferences; | ||
if (userCase.partyContactPreference !== partyDetailsContactPreference) { | ||
try { | ||
await saveAndRedirectContactDetailsAndPreference(req, res); | ||
} catch (error) { | ||
throw new Error( | ||
'ReviewContactPreferencePostController - error when saving contact preferences and redirecting' | ||
); | ||
} | ||
} else { | ||
req.session.save(() => { | ||
res.redirect(applyParms(REVIEW_CONTACT_PREFERENCE, { partyType }) as PageLink); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.