Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haar 2376 add service roles #90

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@ Or run tests with the cypress UI:

## Environment variables

The following environment variables can be set to run the application:
The following environment variables can be set when running the application:

`ENABLE_AUTHORIZATION_CODE` - set to `true` to enable the authorization code grant type. Default is `false`.

`ENABLE_SERVICE_DETAILS` - set to `true` to enable the service details section. Default is `false`.
`AUDIT_ENABLED` - Default is `true` - can be set to `false` to disable audit logging locally. Audit statements are sent to the console.

## Change log

Expand Down
3 changes: 1 addition & 2 deletions feature.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ API_CLIENT_ID=clientid
API_CLIENT_SECRET=clientsecret
SYSTEM_CLIENT_ID=clientid
SYSTEM_CLIENT_SECRET=clientsecret
ENVIRONMENT_NAME=dev
ENABLE_AUTHORIZATION_CODE=true
ENVIRONMENT_NAME=dev
2 changes: 0 additions & 2 deletions helm_deploy/values-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ generic-service:
HMPPS_AUTHORIZATION_SERVER_URL: "https://authorization-server-dev.hmpps.service.justice.gov.uk"
MANAGE_USERS_API_URL: "https://manage-users-api-dev.hmpps.service.justice.gov.uk"
TOKEN_VERIFICATION_API_URL: "https://token-verification-api-dev.prison.service.justice.gov.uk"
ENABLE_AUTHORIZATION_CODE: "true"
ENABLE_SERVICE_DETAILS: "false"
ENVIRONMENT_NAME: DEV

generic-prometheus-alerts:
Expand Down
2 changes: 0 additions & 2 deletions helm_deploy/values-preprod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ generic-service:
HMPPS_AUTHORIZATION_SERVER_URL: "https://authorization-preprod.hmpps.service.justice.gov.uk"
MANAGE_USERS_API_URL: "https://manage-users-api-preprod.hmpps.service.justice.gov.uk"
TOKEN_VERIFICATION_API_URL: "https://token-verification-api-preprod.prison.service.justice.gov.uk"
ENABLE_AUTHORIZATION_CODE: "true"
ENABLE_SERVICE_DETAILS: "false"
ENVIRONMENT_NAME: PRE-PRODUCTION

generic-prometheus-alerts:
Expand Down
2 changes: 0 additions & 2 deletions helm_deploy/values-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ generic-service:
HMPPS_AUTHORIZATION_SERVER_URL: "https://authorization.hmpps.service.justice.gov.uk"
MANAGE_USERS_API_URL: "https://manage-users-api.hmpps.service.justice.gov.uk"
TOKEN_VERIFICATION_API_URL: "https://token-verification-api.prison.service.justice.gov.uk"
ENABLE_AUTHORIZATION_CODE: "true"
ENABLE_SERVICE_DETAILS: "false"

generic-prometheus-alerts:
alertSeverity: digital-prison-service
2 changes: 0 additions & 2 deletions helm_deploy/values-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ generic-service:
HMPPS_AUTHORIZATION_SERVER_URL: "https://authorization-api-stage.hmpps.service.justice.gov.uk"
MANAGE_USERS_API_URL: "https://manage-users-api-stage.hmpps.service.justice.gov.uk"
TOKEN_VERIFICATION_API_URL: "https://token-verification-api-stage.prison.service.justice.gov.uk"
ENABLE_AUTHORIZATION_CODE: "true"
ENABLE_SERVICE_DETAILS: "false"
ENVIRONMENT_NAME: STAGE

generic-prometheus-alerts:
Expand Down
4 changes: 4 additions & 0 deletions integration_tests/e2e/view-base-client.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,9 @@ context('Base client page - authorization-code flow', () => {
it('User can see config table', () => {
baseClientsPage.baseClientConfigTable().should('be.visible')
})

it('User can see service details panel', () => {
baseClientsPage.baseClientServiceDetailsTable().should('be.visible')
})
})
})
2 changes: 2 additions & 0 deletions integration_tests/pages/viewBaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default class ViewBaseClientPage extends Page {

baseClientConfigTable = () => cy.get('[data-qa="base-client-config-table"]')

baseClientServiceDetailsTable = () => cy.get('[data-qa="base-client-service-table"]')

baseClientDeploymentContactTable = () => cy.get('[data-qa="base-client-deployment-contact-table"]')

baseClientDeploymentPlatformTable = () => cy.get('[data-qa="base-client-deployment-platform-table"]')
Expand Down
4 changes: 1 addition & 3 deletions server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ export default {
password: process.env.REDIS_PASSWORD,
tls_enabled: get('REDIS_TLS_ENABLED', 'false'),
},
enableAuthorizationCode: get('ENABLE_AUTHORIZATION_CODE', 'true') === 'true',
enableServiceDetails: get('ENABLE_SERVICE_DETAILS', 'false') === 'true',
session: {
secret: get('SESSION_SECRET', 'app-insecure-default-session', requiredInProduction),
expiryMinutes: Number(get('WEB_SESSION_TIMEOUT_IN_MINUTES', 120)),
},
apis: {
audit: {
enabled: get('AUDIT_ENABLED', 'false') === 'true',
enabled: get('AUDIT_ENABLED', 'true') === 'true',
region: get('AUDIT_SQS_REGION', 'eu-west-2', requiredInProduction),
queueUrl: get('AUDIT_SQS_QUEUE_URL', 'http://localhost:4566/000000000000/mainQueue', requiredInProduction),
serviceName: get('AUDIT_SERVICE_NAME', 'authorization-ui', requiredInProduction),
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/baseClientController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ describe('BaseClientController', () => {
await baseClientController.displayNewBaseClient()(request, response, next)

// THEN the choose client type page is rendered
expect(response.render).toHaveBeenCalledWith('pages/new-base-client-grant.njk', expect.anything())
expect(response.render).toHaveBeenCalledWith('pages/new-base-client-grant.njk')
})

it('if grant is specified with client-credentials renders the details screen', async () => {
Expand Down Expand Up @@ -218,7 +218,7 @@ describe('BaseClientController', () => {
await baseClientController.displayNewBaseClient()(request, response, next)

// THEN the choose client type page is rendered
expect(response.render).toHaveBeenCalledWith('pages/new-base-client-grant.njk', expect.anything())
expect(response.render).toHaveBeenCalledWith('pages/new-base-client-grant.njk')
})

it('if validation fails because no id specified renders the details screen with error message', async () => {
Expand Down
5 changes: 1 addition & 4 deletions server/controllers/baseClientController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ import baseClientAudit, { BaseClientAuditFunction } from '../audit/baseClientAud
import { BaseClientEvent } from '../audit/baseClientEvent'
import { Client } from '../interfaces/baseClientApi/client'
import { mapFilterToUrlQuery, mapListBaseClientRequest } from '../mappers/baseClientApi/listBaseClients'
import config from '../config'

const { enableAuthorizationCode } = config

export default class BaseClientController {
constructor(private readonly baseClientService: BaseClientService) {}
Expand Down Expand Up @@ -72,7 +69,7 @@ export default class BaseClientController {
return async (req, res) => {
const { grant } = req.query
if (!(grant === kebab(GrantType.ClientCredentials) || grant === kebab(GrantType.AuthorizationCode))) {
res.render('pages/new-base-client-grant.njk', { enableAuthorizationCode })
res.render('pages/new-base-client-grant.njk')
return
}
res.render('pages/new-base-client-details.njk', {
Expand Down
1 change: 1 addition & 0 deletions server/data/localMockData/baseClientsResponseMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const getBaseClientResponseMock: (grantType: GrantType) => GetBaseClientR
jiraNumber: 'jiraNumber',
validDays: 1,
accessTokenValiditySeconds: 3600,
serviceAuthorities: ['ROLE_ONE', 'ROLE_TWO'],
deployment: {
clientType: 'service',
team: 'deployment team',
Expand Down
2 changes: 1 addition & 1 deletion server/interfaces/baseClientApi/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface AuthorisationCodeDetails {
interface ServiceDetails {
serviceName: string
description: string
authorisedRoles: string[]
serviceRoles: string[]
url: string
contact: string
status: string
Expand Down
1 change: 1 addition & 0 deletions server/interfaces/baseClientApi/baseClientResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface GetBaseClientResponse {
secretKey: string
deploymentInfo: string
}
serviceAuthorities?: string[]
}

export interface ClientSecretsResponse {
Expand Down
6 changes: 3 additions & 3 deletions server/mappers/baseClientApi/getBaseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { GetBaseClientResponse } from '../../interfaces/baseClientApi/baseClient
import { BaseClient, DeploymentDetails } from '../../interfaces/baseClientApi/baseClient'
import { ClientType } from '../../data/enums/clientTypes'
import { HostingType } from '../../data/enums/hostingTypes'
import { snake } from '../../utils/utils'
import { snake, toBaseClientId } from '../../utils/utils'

export default (response: GetBaseClientResponse): BaseClient => {
return {
baseClientId: response.clientId,
baseClientId: toBaseClientId(response.clientId),
accessTokenValidity: response.accessTokenValiditySeconds ? response.accessTokenValiditySeconds : 0,
scopes: response.scopes ? response.scopes : [],
grantType: snake(response.grantType),
Expand All @@ -26,7 +26,7 @@ export default (response: GetBaseClientResponse): BaseClient => {
service: {
serviceName: '',
description: '',
authorisedRoles: [],
serviceRoles: response.serviceAuthorities ? response.serviceAuthorities : [],
url: '',
contact: '',
status: '',
Expand Down
2 changes: 1 addition & 1 deletion server/mappers/baseClientApi/listBaseClients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default (response: ListBaseClientsResponse): BaseClient[] => {
service: {
serviceName: client.teamName || '',
description: '',
authorisedRoles: multiSeparatorSplit(client.roles, [' ', ',', '\n']),
serviceRoles: [],
url: '',
contact: '',
status: '',
Expand Down
2 changes: 1 addition & 1 deletion server/mappers/forms/mapCreateBaseClientForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default (request: Request): BaseClient => {
service: {
serviceName: '',
description: '',
authorisedRoles: [],
serviceRoles: [],
url: '',
contact: '',
status: '',
Expand Down
2 changes: 1 addition & 1 deletion server/testutils/factories/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default Factory.define<BaseClient>(() => ({
service: {
serviceName: 'service name',
description: 'service description',
authorisedRoles: ['ROLE_CLIENT_CREDENTIALS'],
serviceRoles: ['ROLE_CLIENT_CREDENTIALS'],
url: 'https://localhost:3000',
contact: 'service contact',
status: 'ACTIVE',
Expand Down
101 changes: 27 additions & 74 deletions server/views/pages/base-client.njk
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,35 @@
"data-qa": "base-client-authorization-code-table"
}
}) }}

{{ govukTable({
firstCellIsHeader: false,
head: [
{
text: "Service details",
classes: "govuk-!-width-one-half"
},{
text: ""
}],
rows: [
[
{
text: "Service roles",
classes: "govuk-!-width-one-half"
},{
html: toLinesHtml(baseClient.service.serviceRoles)
}
]
],
attributes: {
"data-qa": "base-client-service-table"
}
}) }}
{% endif %}




{{ govukTable({
firstCellIsHeader: false,
head: [
Expand Down Expand Up @@ -262,85 +288,12 @@
}
}) }}


{% if baseClient.grantType == "authorization_code" and presenter.enableServiceDetails %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h2 class="govuk-heading-l">Service details</h2>
</div>
<div class="govuk-grid-column-one-third">
<a class="govuk-link" href="/clients/{{ baseClient.baseClientId }}/edit-service-details">Change
service details</a>
</div>
</div>

{{ govukTable({
firstCellIsHeader: false,
head: [
{
text: "Service details",
classes: "govuk-!-width-one-half"
},{
text: ""
}],
rows: [
[
{
text: "Name",
classes: "govuk-!-width-one-half"
},{
text: baseClient.service.serviceName
}
],[
{
text: "Description",
classes: "govuk-!-width-one-half"
},{
text: baseClient.service.description
}
],[
{
text: "Authorised roles",
classes: "govuk-!-width-one-half"
},{
html: toLinesHtml(baseClient.service.authorisedRoles)
}
],[
{
text: "URL",
classes: "govuk-!-width-one-half"
},{
text: baseClient.service.url
}
],[
{
text: "Contact URL/email",
classes: "govuk-!-width-one-half"
},{
text: baseClient.service.contact
}
],[
{
text: "Status",
classes: "govuk-!-width-one-half"
},{
text: presenter.serviceEnabledLabel
}
]
],
attributes: {
"data-qa": "base-client-service-table"
}
}) }}
{% endif %}

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h2 class="govuk-heading-l">Deployment details</h2>
</div>
<div class="govuk-grid-column-one-third govuk-!-text-align-right">
<a class="govuk-link" href="/base-clients/{{ baseClient.baseClientId }}/deployment" data-qa='change-deployment-details-link'>Change
deployment details</a>
<a class="govuk-link" href="/base-clients/{{ baseClient.baseClientId }}/deployment" data-qa='change-deployment-details-link'>Change deployment details</a>
</div>
</div>

Expand Down
2 changes: 0 additions & 2 deletions server/views/presenters/viewBaseClientPresenter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BaseClient } from '../../interfaces/baseClientApi/baseClient'
import { Client } from '../../interfaces/baseClientApi/client'
import { dateTimeFormat, daysRemaining } from '../../utils/utils'
import config from '../../config'

export default (baseClient: BaseClient, clients: Client[]) => {
return {
Expand All @@ -21,6 +20,5 @@ export default (baseClient: BaseClient, clients: Client[]) => {
]),
expiry: baseClient.config.expiryDate ? `Yes - days remaining ${daysRemaining(baseClient.config.expiryDate)}` : 'No',
skipToAzureField: '',
enableServiceDetails: config.enableServiceDetails,
}
}