Skip to content

Commit 7107f0b

Browse files
authored
move document urls outside the feature disable pages toggle. (#3717)
* move document urls outside the feature disable pages toggle. * fix importing folder * update yarn-audit-known-issues * clean up importing document paths + move tests * clean up * clean up (2) * clean up * sonar ignore
1 parent ea4f091 commit 7107f0b

File tree

19 files changed

+150
-89
lines changed

19 files changed

+150
-89
lines changed

src/main/app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Nunjucks } from 'modules/nunjucks'
1616
import * as moment from 'moment'
1717
import { Feature as EligibilityFeature } from 'eligibility/index'
1818
import { Feature as ClaimIssueFeature } from 'claim/index'
19+
import { Feature as ClaimDocumentsFeature } from 'claim-documents/index'
1920
import { Feature as DefendantFirstContactFeature } from 'first-contact/index'
2021
import { Feature as DefendantResponseFeature } from 'response/index'
2122
import { Feature as SettlementAgreementFeature } from 'settlement-agreement/index'
@@ -96,6 +97,9 @@ if (env !== 'mocha') {
9697
logger.info('Loading DashboardFeature')
9798
new DashboardFeature().enableFor(app)
9899

100+
logger.info('Loading ClaimDocumentsFeature')
101+
new ClaimDocumentsFeature().enableFor(app)
102+
99103
if (!FeatureToggles.isEnabled('disablePages')) {
100104
logger.info('Loading EligibilityFeature')
101105
new EligibilityFeature().enableFor(app)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as express from 'express'
2+
import * as path from 'path'
3+
4+
import { Paths } from 'claim-documents/paths'
5+
6+
import { RouterFinder } from 'shared/router/routerFinder'
7+
import { OAuthHelper } from 'idam/oAuthHelper'
8+
import { AuthorizationMiddleware } from 'idam/authorizationMiddleware'
9+
10+
export function claimIssueRequestHandler (): express.RequestHandler {
11+
function accessDeniedCallback (req: express.Request, res: express.Response): void {
12+
res.redirect(OAuthHelper.forLogin(req, res))
13+
}
14+
15+
const requiredRoles = [
16+
'citizen'
17+
]
18+
const unprotectedPaths = []
19+
return AuthorizationMiddleware.requestHandler(requiredRoles, accessDeniedCallback, unprotectedPaths)
20+
}
21+
22+
export class Feature {
23+
enableFor (app: express.Express) {
24+
if (app.settings.nunjucksEnv && app.settings.nunjucksEnv.globals) {
25+
app.settings.nunjucksEnv.globals.ClaimDocumentsPaths = Paths
26+
}
27+
28+
app.all('/claim/*', claimIssueRequestHandler())
29+
app.use('/', RouterFinder.findAll(path.join(__dirname, 'routes')))
30+
}
31+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { RoutablePath } from 'shared/router/routablePath'
2+
3+
export class Paths {
4+
static readonly receiptReceiver = new RoutablePath('/claim/:externalId/receipt')
5+
static readonly sealedClaimPdfReceiver = new RoutablePath('/claim/:externalId/sealed-claim')
6+
static readonly documentPage = new RoutablePath('/claim/:externalId/document/:documentURI')
7+
}

src/main/features/claim/routes/document.ts renamed to src/main/features/claim-documents/routes/document.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as express from 'express'
2-
import { Paths } from 'claim/paths'
2+
import { Paths } from 'claim-documents/paths'
33

44
import { Claim } from 'claims/models/claim'
55
import { ClaimMiddleware } from 'claims/claimMiddleware'
@@ -16,7 +16,7 @@ const documentsClient: DocumentsClient = new DocumentsClient()
1616
const scannedDocumentsClient: ScannedDocumentsClient = new ScannedDocumentsClient()
1717

1818
function getDocumentPath (path: string): string {
19-
return path.match(`[^\/]+$`)[0]
19+
return path.match(`[^\/]+$`)[0]// NOSONAR
2020
}
2121
/* tslint:disable:no-default-export */
2222
export default express.Router()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as express from 'express'
2+
import { Paths } from 'claim-documents/paths'
3+
4+
import { Claim } from 'claims/models/claim'
5+
import { ClaimMiddleware } from 'claims/claimMiddleware'
6+
import { DocumentsClient } from 'documents/documentsClient'
7+
8+
import { ErrorHandling } from 'shared/errorHandling'
9+
10+
import { DownloadUtils } from 'utils/downloadUtils'
11+
12+
const documentsClient: DocumentsClient = new DocumentsClient()
13+
14+
/* tslint:disable:no-default-export */
15+
export default express.Router()
16+
.get(Paths.receiptReceiver.uri,
17+
ClaimMiddleware.retrieveByExternalId,
18+
ErrorHandling.apply(async (req: express.Request, res: express.Response): Promise<void> => {
19+
const claim: Claim = res.locals.claim
20+
21+
const pdf: Buffer = await documentsClient.getClaimIssueReceiptPDF(claim.externalId, res.locals.user.bearerToken)
22+
DownloadUtils.downloadPDF(res, pdf, `${claim.claimNumber}-claim-form-claimant-copy`)
23+
}))

src/main/features/claim/routes/sealed-claim.ts renamed to src/main/features/claim-documents/routes/sealed-claim.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as express from 'express'
2-
import { Paths } from 'claim/paths'
2+
import { Paths } from 'claim-documents/paths'
33

44
import { ErrorHandling } from 'shared/errorHandling'
55
import { ClaimMiddleware } from 'claims/claimMiddleware'

src/main/features/claim/index.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,20 @@ import * as path from 'path'
33

44
import { Paths } from 'claim/paths'
55

6-
import { AuthorizationMiddleware } from 'idam/authorizationMiddleware'
76
import { ClaimEligibilityGuard } from 'claim/guards/claimEligibilityGuard'
87
import { RouterFinder } from 'shared/router/routerFinder'
98
import { DraftMiddleware } from '@hmcts/cmc-draft-store-middleware'
109
import { DraftService } from 'services/draftService'
1110
import { DraftClaim } from 'drafts/models/draftClaim'
12-
import { OAuthHelper } from 'idam/oAuthHelper'
13-
14-
function claimIssueRequestHandler (): express.RequestHandler {
15-
function accessDeniedCallback (req: express.Request, res: express.Response): void {
16-
res.redirect(OAuthHelper.forLogin(req, res))
17-
}
18-
19-
const requiredRoles = [
20-
'citizen'
21-
]
22-
const unprotectedPaths = []
23-
return AuthorizationMiddleware.requestHandler(requiredRoles, accessDeniedCallback, unprotectedPaths)
24-
}
11+
// import { claimIssueRequestHandler } from 'claim-documents/index'
2512

2613
export class Feature {
2714
enableFor (app: express.Express) {
2815
if (app.settings.nunjucksEnv && app.settings.nunjucksEnv.globals) {
2916
app.settings.nunjucksEnv.globals.ClaimPaths = Paths
3017
}
31-
32-
app.all('/claim/*', claimIssueRequestHandler())
18+
// commented out as claim document index.ts will handle this
19+
// app.all('/claim/*', claimIssueRequestHandler())
3320
app.all(/^\/claim\/(?!start|amount-exceeded|new-features-consent|.+\/confirmation|.+\/receipt|.+\/draftReceipt|.+\/sealed-claim).*$/,
3421
DraftMiddleware.requestHandler(new DraftService(), 'claim', 100, (value: any): DraftClaim => {
3522
return new DraftClaim().deserialize(value)

src/main/features/claim/paths.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ export class Paths {
3535
static readonly startPaymentReceiver = new RoutablePath('/claim/pay')
3636
static readonly finishPaymentReceiver = new RoutablePath('/claim/pay/:externalId/receiver')
3737
static readonly confirmationPage = new RoutablePath('/claim/:externalId/confirmation')
38-
static readonly receiptReceiver = new RoutablePath('/claim/:externalId/receipt')
3938
static readonly claimantPartyTypeSelectionPage = new RoutablePath('/claim/claimant-party-type-selection')
4039
static readonly defendantPartyTypeSelectionPage = new RoutablePath('/claim/defendant-party-type-selection')
4140
static readonly incompleteSubmissionPage = new RoutablePath('/claim/incomplete-submission')
42-
static readonly sealedClaimPdfReceiver = new RoutablePath('/claim/:externalId/sealed-claim')
4341
static readonly initiatePaymentController = new RoutablePath('/claim/initiate-payment')
4442
static readonly finishPaymentController = new RoutablePath('/claim/:externalId/finish-payment')
45-
static readonly documentPage = new RoutablePath('/claim/:externalId/document/:documentURI')
4643
static readonly draftReceiptReceiver = new RoutablePath('/claim/:externalId/draftReceipt')
4744
}
4845

src/main/features/claim/routes/receipt.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as express from 'express'
22
import { Paths } from 'claim/paths'
33

4-
import { Claim } from 'claims/models/claim'
54
import { ClaimMiddleware } from 'claims/claimMiddleware'
65
import { DocumentsClient } from 'documents/documentsClient'
76

@@ -13,15 +12,6 @@ const documentsClient: DocumentsClient = new DocumentsClient()
1312

1413
/* tslint:disable:no-default-export */
1514
export default express.Router()
16-
.get(Paths.receiptReceiver.uri,
17-
ClaimMiddleware.retrieveByExternalId,
18-
ErrorHandling.apply(async (req: express.Request, res: express.Response): Promise<void> => {
19-
const claim: Claim = res.locals.claim
20-
21-
const pdf: Buffer = await documentsClient.getClaimIssueReceiptPDF(claim.externalId, res.locals.user.bearerToken)
22-
DownloadUtils.downloadPDF(res, pdf, `${claim.claimNumber}-claim-form-claimant-copy`)
23-
}))
24-
2515
.get(Paths.draftReceiptReceiver.uri,
2616
ClaimMiddleware.retrieveByExternalId,
2717
ErrorHandling.apply(async (req: express.Request, res: express.Response): Promise<void> => {

src/main/features/claim/views/macro/claim-confirmation.njk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<h1 class="bold-large">{{ claim.claimNumber }}</h1>
1010
</div>
1111
<p class="receipt-download-container">
12-
{{ internalLink(t('Download your claim form'), ClaimPaths.receiptReceiver.evaluateUri({ externalId: claim.externalId})) }}
12+
{{ internalLink(t('Download your claim form'), ClaimDocumentsPaths.receiptReceiver.evaluateUri({ externalId: claim.externalId})) }}
1313
</p>
1414
</div>
1515
<h2 class="heading-medium">{{ t('What happens next') }}</h2>
@@ -24,4 +24,4 @@
2424

2525
<h2 class="heading-medium">{{ t('If the defendant pays you') }}</h2>
2626
<p>{{ t('You need to sign in to your account to tell us you’ve been paid.') }}</p>
27-
{% endmacro %}
27+
{% endmacro %}

0 commit comments

Comments
 (0)