Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ddac823
Move "Regulation 43" section up one
timabell Jul 13, 2026
d85569a
AMCR-309 - Enable sonar step in other workflows
dashkatuk Jul 14, 2026
0ad0557
Merge pull request #37 from DEFRA/AMCR-251-move-declaration43-section
timabell Jul 14, 2026
0d7a9d9
Move approve-flow banner assertions to the accept-confirmation tests
timabell Jul 14, 2026
a86f514
Point the sign-in-and-retry journey test at `/accept` instead of `/ap…
timabell Jul 14, 2026
0d3ee53
Delete `/approve` guard tests already covered on the `/accept` route
timabell Jul 14, 2026
50ff18e
Point the action-controller approval tests at `/accept`
timabell Jul 14, 2026
ff50121
Remove the unused `POST /approve` route
timabell Jul 14, 2026
23f0974
Move the approval logic into the accept controller
timabell Jul 14, 2026
a67d789
Use a `switch` for the accept confirmation choice
timabell Jul 14, 2026
3969f4d
Merge pull request #42 from DEFRA/AMCR-338-remove-orphaned-approve-route
timabell Jul 15, 2026
e39ab01
AMCR-309 - Enable sonar step in other workflows
dashkatuk Jul 14, 2026
c441e7a
Merge remote-tracking branch 'origin/AMCR-309-EnableSonarInPublishSte…
dashkatuk Jul 15, 2026
50bb968
AMCR-309 - Add object mothers for test data to reduce duplicated code
dashkatuk Jul 15, 2026
9fa6e45
AMCR-309 - formatting
dashkatuk Jul 15, 2026
687fc14
AMCR-309 - Further sonar fixes
dashkatuk Jul 15, 2026
3182ace
AMCR-309 - further tidy
dashkatuk Jul 15, 2026
50413c7
AMCR-309 - Fix major sonar issue, start of critical
dashkatuk Jul 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/publish-hotfix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

# - name: SonarCloud Scan
# uses: SonarSource/sonarqube-scan-action@v5.3.1 # (or check latest version on https://github.com/marketplace/actions/official-sonarqube-scan)
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@v5.3.1 # (or check latest version on https://github.com/marketplace/actions/official-sonarqube-scan)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.WASTE_PACKAGING_SONAR_TOKEN }}
12 changes: 6 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

# - name: SonarCloud Scan
# uses: SonarSource/sonarqube-scan-action@v5.3.1 # (or check latest version on https://github.com/marketplace/actions/official-sonarqube-scan)
# continue-on-error: true
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: SonarCloud Scan
uses: SonarSource/sonarqube-scan-action@v5.3.1 # (or check latest version on https://github.com/marketplace/actions/official-sonarqube-scan)
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.WASTE_PACKAGING_SONAR_TOKEN }}
74 changes: 58 additions & 16 deletions src/server/routes/certificatesOfCompliance/accept/controller.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { config } from '#config/config.js'
import { handleApiError } from '#server/common/helpers/handle-api-error.js'
import {
getCertificateOfComplianceDetailViewModel,
getComplianceDeclarationReviewStatus,
canApproveComplianceDeclaration
canApproveComplianceDeclaration,
approveComplianceDeclaration,
certificateActionSessionKeys,
getDeclarationSessionKey,
setMockDeclarationStatusOverride
} from '../certificates-of-compliance.service.js'
import {
redirectToSignIn,
runApproveAction
} from '../detail/actions-controller.js'
import { redirectToSignIn } from '../detail/actions-controller.js'

const ERROR_TEXT = 'Select yes or no'

const TRACING_HEADER = 'tracing.header'
function buildErrors() {
return {
summary: [{ text: ERROR_TEXT, href: '#confirm-accept' }],
Expand All @@ -24,7 +26,8 @@ function detailPath(organisationId, id) {

async function renderForm(request, h, { errors = null } = {}) {
const { organisationId, id } = request.params
const traceId = request.headers[config.get('tracing.header')]

const traceId = request.headers[config.get(TRACING_HEADER)]
const { companyName, registrationType } =
await getCertificateOfComplianceDetailViewModel(organisationId, id, {
traceId,
Expand All @@ -46,14 +49,54 @@ async function renderForm(request, h, { errors = null } = {}) {
})
}

// Approves the declaration and returns to the detail page with the accepted
// banner. Idempotent: an already-approved declaration re-shows the banner, and
// one that can no longer be approved bounces back without it.
async function approveDeclaration(request, h) {
const { organisationId, id } = request.params
const traceId = request.headers[config.get(TRACING_HEADER)]
const declarationKey = getDeclarationSessionKey(organisationId, id)
const reviewStatus = await getComplianceDeclarationReviewStatus(
organisationId,
id,
traceId,
request.yar
)

if (reviewStatus === 'Approved') {
request.yar.set(certificateActionSessionKeys.justApproved, declarationKey)
return h.redirect(detailPath(organisationId, id))
}

if (!canApproveComplianceDeclaration(reviewStatus)) {
return h.redirect(detailPath(organisationId, id))
}

try {
await approveComplianceDeclaration(
organisationId,
id,
request.yar.get('user'),
traceId
)
} catch (error) {
handleApiError(request, error)
}

setMockDeclarationStatusOverride(request.yar, declarationKey, 'Approved')
request.yar.set(certificateActionSessionKeys.justApproved, declarationKey)

return h.redirect(detailPath(organisationId, id))
}

export const certificatesOfComplianceAcceptGetController = {
async handler(request, h) {
if (!request.yar.get('user')) {
return redirectToSignIn(request, h)
}

const { organisationId, id } = request.params
const traceId = request.headers[config.get('tracing.header')]
const traceId = request.headers[config.get(TRACING_HEADER)]
const reviewStatus = await getComplianceDeclarationReviewStatus(
organisationId,
id,
Expand All @@ -80,14 +123,13 @@ export const certificatesOfComplianceAcceptPostController = {
const choice = request.payload?.['confirm-accept']
const { organisationId, id } = request.params

if (choice !== 'yes' && choice !== 'no') {
return renderForm(request, h, { errors: buildErrors() })
switch (choice) {
case 'no':
return h.redirect(detailPath(organisationId, id))
case 'yes':
return approveDeclaration(request, h)
default:
return renderForm(request, h, { errors: buildErrors() })
}

if (choice === 'no') {
return h.redirect(detailPath(organisationId, id))
}

return runApproveAction(request, h)
}
}
Loading
Loading