Skip to content

Commit

Permalink
Merge branch 'master' into S28-3356/schema-edit-requests
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-phillips28 committed Oct 14, 2024
2 parents 546e717 + 6f14cf9 commit 8433e3c
Show file tree
Hide file tree
Showing 22 changed files with 976 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# renovate: datasource=github-releases depName=microsoft/ApplicationInsights-Java
ARG APP_INSIGHTS_AGENT_VERSION=3.6.0
ARG APP_INSIGHTS_AGENT_VERSION=3.6.1
FROM openjdk:21-jdk-slim-bullseye AS build-env
RUN apt-get update && apt-get install -y ffmpeg

Expand Down
2 changes: 1 addition & 1 deletion infrastructure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module "pre_api" {
api_mgmt_rg = "ss-${var.env}-network-rg"
api_mgmt_name = "sds-api-mgmt-${var.env}"
display_name = "Pre Recorded Evidence API"
revision = "83"
revision = "86"
product_id = module.pre_product[0].product_id
path = "pre-api"
service_url = local.apim_service_url
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/state.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "4.4.0"
version = "4.5.0"
}
}
}
92 changes: 92 additions & 0 deletions pre-api-stg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,12 @@ definitions:
items:
$ref: '#/definitions/PortalAccessDTO'
type: array
terms_accepted:
additionalProperties:
description: UserTermsAccepted
type: boolean
description: UserTermsAccepted
type: object
required:
- email
- first_name
Expand Down Expand Up @@ -1773,6 +1779,22 @@ definitions:
format: date-time
type: string
type: object
TermsAndConditionsDTO:
properties:
created_at:
format: date-time
type: string
html:
type: string
id:
format: uuid
type: string
type:
enum:
- APP
- PORTAL
type: string
type: object
UserDTO:
description: UserDTO
properties:
Expand Down Expand Up @@ -1817,6 +1839,12 @@ definitions:
items:
$ref: '#/definitions/PortalAccessDTO'
type: array
terms_accepted:
additionalProperties:
description: UserTermsAccepted
type: boolean
description: UserTermsAccepted
type: object
required:
- email
- first_name
Expand All @@ -1835,6 +1863,49 @@ info:
title: PRE API
version: v0.0.1
paths:
'/accept-terms-and-conditions/{termsId}':
post:
operationId: acceptTermsAndConditions
parameters:
- format: uuid
in: path
name: termsId
required: true
type: string
- description: The User Id of the User making the request
format: uuid
in: header
name: X-User-Id
required: false
type: string
x-example: 123e4567-e89b-12d3-a456-426614174000
responses:
'200':
description: OK
summary: Accept terms and conditions for a user
tags:
- terms-and-conditions-controller
/app-terms-and-conditions/latest:
get:
operationId: getLatestTermsForApp
parameters:
- description: The User Id of the User making the request
format: uuid
in: header
name: X-User-Id
required: false
type: string
x-example: 123e4567-e89b-12d3-a456-426614174000
produces:
- application/octet-stream
responses:
'200':
description: OK
schema:
$ref: '#/definitions/TermsAndConditionsDTO'
summary: Get the latest terms and conditions for the app
tags:
- terms-and-conditions-controller
'/audit/{id}':
put:
consumes:
Expand Down Expand Up @@ -3048,6 +3119,27 @@ paths:
$ref: '#/definitions/PlaybackDTO'
tags:
- media-service-controller
/portal-terms-and-conditions/latest:
get:
operationId: getLatestTermsForPortal
parameters:
- description: The User Id of the User making the request
format: uuid
in: header
name: X-User-Id
required: false
type: string
x-example: 123e4567-e89b-12d3-a456-426614174000
produces:
- application/octet-stream
responses:
'200':
description: OK
schema:
$ref: '#/definitions/TermsAndConditionsDTO'
summary: Get the latest terms and conditions for the portal
tags:
- terms-and-conditions-controller
/recordings:
get:
operationId: getRecordings
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package uk.gov.hmcts.reform.preapi.services;

import jakarta.transaction.Transactional;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import uk.gov.hmcts.reform.preapi.entities.TermsAndConditions;
import uk.gov.hmcts.reform.preapi.enums.TermsAndConditionsType;
import uk.gov.hmcts.reform.preapi.exception.NotFoundException;
import uk.gov.hmcts.reform.preapi.util.HelperFactory;
import uk.gov.hmcts.reform.preapi.utils.IntegrationTestBase;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class TermsAndConditionsServiceIT extends IntegrationTestBase {
@Autowired
private TermsAndConditionsService termsAndConditionsService;

private TermsAndConditions termsAndConditionsApp;
private TermsAndConditions termsAndConditionsPortal;

@BeforeEach
public void setUp() {
termsAndConditionsApp = HelperFactory.createTermsAndConditions(TermsAndConditionsType.APP, "app content");
entityManager.persist(termsAndConditionsApp);

termsAndConditionsPortal = HelperFactory.createTermsAndConditions(
TermsAndConditionsType.PORTAL,
"portal content"
);
entityManager.persist(termsAndConditionsPortal);
}

@Test
@Transactional
public void getLatestTermsAndConditionsApp() {
var latestAppTerms1 = termsAndConditionsService.getLatestTermsAndConditions(TermsAndConditionsType.APP);

assertThat(latestAppTerms1.getId()).isEqualTo(termsAndConditionsApp.getId());

var newTerms = HelperFactory.createTermsAndConditions(TermsAndConditionsType.APP, "app content 2");
entityManager.persist(newTerms);

var latestAppTerms2 = termsAndConditionsService.getLatestTermsAndConditions(TermsAndConditionsType.APP);
assertThat(latestAppTerms2.getId()).isEqualTo(newTerms.getId());
assertThat(latestAppTerms2.getCreatedAt()).isAfter(latestAppTerms1.getCreatedAt());
}

@Test
@Transactional
public void getLatestTermsAndConditionsPortal() {
var latestPortalTerms1 = termsAndConditionsService.getLatestTermsAndConditions(TermsAndConditionsType.PORTAL);

assertThat(latestPortalTerms1.getId()).isEqualTo(termsAndConditionsPortal.getId());

var newTerms = HelperFactory.createTermsAndConditions(TermsAndConditionsType.PORTAL, "portal content 2");
entityManager.persist(newTerms);

var latestPortalTerms2 = termsAndConditionsService.getLatestTermsAndConditions(TermsAndConditionsType.PORTAL);
assertThat(latestPortalTerms2.getId()).isEqualTo(newTerms.getId());
assertThat(latestPortalTerms2.getCreatedAt()).isAfter(latestPortalTerms1.getCreatedAt());
}

@Test
@Transactional
public void getLatestTermsAndConditionsNotFound() {
// delete all entities
entityManager.clear();
entityManager.flush();

var message1 = assertThrows(
NotFoundException.class,
() -> termsAndConditionsService.getLatestTermsAndConditions(TermsAndConditionsType.APP)
);
assertThat(message1.getMessage()).isEqualTo("Not found: Terms and conditions of type: APP");

var message2 = assertThrows(
NotFoundException.class,
() -> termsAndConditionsService.getLatestTermsAndConditions(TermsAndConditionsType.PORTAL)
);
assertThat(message2.getMessage()).isEqualTo("Not found: Terms and conditions of type: PORTAL");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package uk.gov.hmcts.reform.preapi.services;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import uk.gov.hmcts.reform.preapi.entities.TermsAndConditions;
import uk.gov.hmcts.reform.preapi.entities.User;
import uk.gov.hmcts.reform.preapi.enums.TermsAndConditionsType;
import uk.gov.hmcts.reform.preapi.util.HelperFactory;
import uk.gov.hmcts.reform.preapi.utils.IntegrationTestBase;

import java.time.Instant;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

public class UserTermsAcceptedServiceIT extends IntegrationTestBase {

@Autowired
private UserTermsAcceptedService userTermsAcceptedService;

private User user;
private TermsAndConditions termsAndConditions;

@BeforeEach
void setUp() {
user = HelperFactory.createDefaultTestUser();
user.setId(UUID.randomUUID());
entityManager.persist(user);

termsAndConditions = HelperFactory.createTermsAndConditions(TermsAndConditionsType.APP, "Content");
entityManager.persist(termsAndConditions);

entityManager.flush();
}

@Test
@Transactional
public void acceptTermsAndConditions() {
var mockedUser = mockAdminUser();
when(mockedUser.getUserId()).thenReturn(user.getId());
userTermsAcceptedService.acceptTermsAndConditions(termsAndConditions.getId());

entityManager.flush();
entityManager.refresh(user);

assertThat(user.getUserTermsAccepted()).isNotNull();
assertThat(user.getUserTermsAccepted()).hasSize(1);

var termsAccepted = user.getUserTermsAccepted().stream().findFirst().get();
assertThat(termsAccepted).isNotNull();
assertThat(termsAccepted.getUser().getId()).isEqualTo(user.getId());
assertThat(termsAccepted.getTermsAndConditions().getId()).isEqualTo(termsAndConditions.getId());
// very recently created
assertThat(termsAccepted.getAcceptedAt()).isAfter(Instant.now().minusSeconds(5));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class SecurityConfig {
new AntPathRequestMatcher("/error"),
new AntPathRequestMatcher("/invites", "GET"),
new AntPathRequestMatcher("/invites/redeem", "POST"),
new AntPathRequestMatcher("/api/app-terms-and-conditions/latest"),
new AntPathRequestMatcher("/api/portal-terms-and-conditions/latest"),
};

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package uk.gov.hmcts.reform.preapi.controllers;

import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import uk.gov.hmcts.reform.preapi.dto.TermsAndConditionsDTO;
import uk.gov.hmcts.reform.preapi.enums.TermsAndConditionsType;
import uk.gov.hmcts.reform.preapi.services.TermsAndConditionsService;
import uk.gov.hmcts.reform.preapi.services.UserTermsAcceptedService;

import java.util.UUID;

@RestController
public class TermsAndConditionsController {

private final TermsAndConditionsService termsAndConditionsService;
private final UserTermsAcceptedService userTermsAcceptedService;

@Autowired
public TermsAndConditionsController(TermsAndConditionsService termsAndConditionsService,
UserTermsAcceptedService userTermsAcceptedService) {
this.termsAndConditionsService = termsAndConditionsService;
this.userTermsAcceptedService = userTermsAcceptedService;
}

@GetMapping("/app-terms-and-conditions/latest")
@Operation(
operationId = "getLatestTermsForApp",
summary = "Get the latest terms and conditions for the app"
)
public ResponseEntity<TermsAndConditionsDTO> getLatestAppTermsAndConditions() {
return ResponseEntity.ok(termsAndConditionsService.getLatestTermsAndConditions(TermsAndConditionsType.APP));
}

@GetMapping("/portal-terms-and-conditions/latest")
@Operation(
operationId = "getLatestTermsForPortal",
summary = "Get the latest terms and conditions for the portal"
)
public ResponseEntity<TermsAndConditionsDTO> getLatestPortalTermsAndConditions() {
return ResponseEntity.ok(termsAndConditionsService.getLatestTermsAndConditions(TermsAndConditionsType.PORTAL));
}

@PostMapping("/accept-terms-and-conditions/{termsId}")
@Operation(
operationId = "acceptTermsAndConditions",
summary = "Accept terms and conditions for a user"
)
@PreAuthorize("hasAnyRole('ROLE_SUPER_USER', 'ROLE_LEVEL_1', 'ROLE_LEVEL_2', 'ROLE_LEVEL_3', 'ROLE_LEVEL_4')")
public ResponseEntity<Void> acceptTermsAndConditions(@PathVariable UUID termsId) {
userTermsAcceptedService.acceptTermsAndConditions(termsId);
return ResponseEntity.noContent().build();
}
}
Loading

0 comments on commit 8433e3c

Please sign in to comment.