Skip to content
Open
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
2 changes: 1 addition & 1 deletion infrastructure/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ locals {
env_to_deploy = 1
env_long_name = var.env == "sbox" ? "sandbox" : var.env == "stg" ? "staging" : var.env
apim_service_url = var.env == "prod" ? "https://pre-api.platform.hmcts.net" : "https://pre-api.${local.env_long_name}.platform.hmcts.net"
api_revision = "126"
api_revision = "127"
}

data "azurerm_client_config" "current" {}
Expand Down
8 changes: 8 additions & 0 deletions pre-api-stg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4734,6 +4734,14 @@ paths:
in: query
name: name
type: string
- description: The first name of the user to search by
in: query
name: firstName
type: string
- description: The last name of the user to search by
in: query
name: lastName
type: string
- description: The email of the user to search by
in: query
name: email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,16 @@ public void searchUsersAsAdmin() {
entityManager.persist(userEntity);
entityManager.flush();

var users = userService.findAllBy(null, null, null, null, null, null, false, null, Pageable.unpaged()).toList();
var users = userService
.findAllBy(null, null, null, null, null, null, null, null, false, null, Pageable.unpaged()).toList();

Assertions.assertEquals(users.size(), 2);
Assertions.assertTrue(users.stream().anyMatch(user -> user.getId().equals(portalUserEntity.getId())));
Assertions.assertTrue(users.stream().anyMatch(user -> user.getId().equals(appUserEntity.getId())));
Assertions.assertFalse(users.stream().anyMatch(user -> user.getId().equals(userEntity.getId())));

var users2 = userService.findAllBy(null, null, null, null, null, null, true, null, Pageable.unpaged()).toList();
var users2 = userService
.findAllBy(null, null, null, null, null, null, null, null, true, null, Pageable.unpaged()).toList();

Assertions.assertEquals(users2.size(), 3);
Assertions.assertTrue(users2.stream().anyMatch(user -> user.getId().equals(portalUserEntity.getId())));
Expand All @@ -137,7 +139,19 @@ public void searchUsersAsNonAdmin() {
entityManager.persist(userEntity);
entityManager.flush();

var users = userService.findAllBy(null, null, null, null, null, null, false, null, Pageable.unpaged()).toList();
var users = userService.findAllBy(
null,
null,
null,
null,
null,
null,
null,
null,
false,
null,
Pageable.unpaged()
).toList();

Assertions.assertEquals(users.size(), 2);
Assertions.assertTrue(users.stream().anyMatch(user -> user.getId().equals(portalUserEntity.getId())));
Expand All @@ -146,7 +160,19 @@ public void searchUsersAsNonAdmin() {

var message = Assertions.assertThrows(
AccessDeniedException.class,
() -> userService.findAllBy(null, null, null, null, null, null, true, null, Pageable.unpaged()).toList()
() -> userService.findAllBy(
null,
null,
null,
null,
null,
null,
null,
null,
true,
null,
Pageable.unpaged()
).toList()
).getMessage();

Assertions.assertEquals(message, "Access Denied");
Expand All @@ -162,6 +188,8 @@ public void testGetUserByAccessType() {
null,
null,
null,
null,
null,
AccessType.APP,
false,
null,
Expand All @@ -179,6 +207,8 @@ public void testGetUserByAccessType() {
null,
null,
null,
null,
null,
AccessType.PORTAL,
false,
null,
Expand All @@ -190,7 +220,19 @@ public void testGetUserByAccessType() {
Assertions.assertEquals(userEntity.getFirstName(), usersPortal.get(0).getFirstName());
Assertions.assertEquals(portalUserEntity.getId(), usersPortal.get(1).getId());

var resultAll = userService.findAllBy(null, null, null, null, null, null, false,null, PageRequest.of(0, 20));
var resultAll = userService.findAllBy(
null,
null,
null,
null,
null,
null,
null,
null,
false,
null,
PageRequest.of(0, 20)
);
Assertions.assertEquals(3, resultAll.getContent().size());
var usersAll = resultAll.getContent().stream()
.sorted(Comparator.comparing(BaseUserDTO::getFirstName)).toList();
Expand All @@ -205,6 +247,8 @@ public void testGetUserByAccessType() {
null,
null,
null,
null,
null,
AccessType.PORTAL,
false,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ public ResponseEntity<UserDTO> getUserById(@PathVariable UUID userId) {
description = "The name of the user to search by",
schema = @Schema(implementation = String.class)
)
@Parameter(
name = "firstName",
description = "The first name of the user to search by",
schema = @Schema(implementation = String.class)
)
@Parameter(
name = "lastName",
description = "The last name of the user to search by",
schema = @Schema(implementation = String.class)
)
@Parameter(
name = "email",
description = "The email of the user to search by",
Expand Down Expand Up @@ -133,6 +143,8 @@ public ResponseEntity<PagedModel<EntityModel<UserDTO>>> getUsers(
) {
var resultPage = userService.findAllBy(
params.getName(),
params.getFirstName(),
params.getLastName(),
params.getEmail(),
params.getOrganisation(),
params.getCourtId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
@Data
public class SearchUsers {
private String name;
private String firstName;
private String lastName;
private String email;
private String organisation;
private UUID courtId;
Expand All @@ -20,6 +22,14 @@ public String getName() {
return name != null && !name.isEmpty() ? name : null;
}

public String getFirstName() {
return firstName != null && !firstName.isEmpty() ? firstName : null;
}

public String getLastName() {
return lastName != null && !lastName.isEmpty() ? lastName : null;
}

public String getEmail() {
return email != null && !email.isEmpty() ? email : null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package uk.gov.hmcts.reform.preapi.repositories;


import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down Expand Up @@ -40,6 +39,8 @@ public interface UserRepository extends JpaRepository<User, UUID> {
ELSE 0
END = 1
)
AND (:firstName IS NULL OR u.firstName ILIKE %:firstName%)
AND (:lastName IS NULL OR u.lastName ILIKE %:lastName%)
AND (:organisation IS NULL OR u.organisation ILIKE %:organisation%)
AND (CAST(:courtId as uuid) IS NULL OR EXISTS (SELECT 1 FROM u.appAccess aa WHERE aa.court.id = :courtId))
AND (CAST(:roleId as uuid) IS NULL OR EXISTS (SELECT 1 FROM u.appAccess aa WHERE aa.role.id = :roleId))
Expand All @@ -56,6 +57,8 @@ OR EXISTS (
)
Page<User> searchAllBy(
@Param("name") String name,
@Param("firstName") String firstName,
@Param("lastName") String lastName,
@Param("email") String email,
@Param("organisation") String organisation,
@Param("courtId") UUID courtId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public AccessDTO findByEmail(String email) {
@SuppressWarnings("PMD.UseObjectForClearerAPI")
public Page<UserDTO> findAllBy(
String name,
String firstName,
String lastName,
String email,
String organisation,
UUID court,
Expand All @@ -112,14 +114,23 @@ public Page<UserDTO> findAllBy(
throw new NotFoundException("Court: " + court);
}

if (role != null && !roleRepository.existsById(role)) {
throw new NotFoundException("Role: " + role);
if (role != null) {
var r = roleRepository.findById(role);
if (r.isEmpty()) {
throw new NotFoundException("Role: " + role);
}
if (r.get().getName().equals("Level 3") && accessType == null) {
role = null;
accessType = AccessType.PORTAL;
}
}

var allLatestTermsAndConditions = getAllLatestTermsAndConditions();

return userRepository.searchAllBy(
name,
firstName,
lastName,
email,
organisation,
court,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ void getUsersSuccess() throws Exception {
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
eq(false),
isNull(),
any()
Expand All @@ -146,6 +148,8 @@ void getUsersSuccess() throws Exception {
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
eq(false),
isNull(),
any()
Expand All @@ -158,7 +162,19 @@ void getUsersCourtNotFound() throws Exception {
UUID courtId = UUID.randomUUID();
doThrow(new NotFoundException("Court: " + courtId))
.when(userService)
.findAllBy(isNull(), isNull(), isNull(), eq(courtId), isNull(), isNull(), eq(false), isNull(), any());
.findAllBy(
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
eq(courtId),
isNull(),
isNull(),
eq(false),
isNull(),
any()
);

mockMvc.perform(get("/users")
.param("courtId", courtId.toString()))
Expand All @@ -172,7 +188,7 @@ void getUsersRoleNotFound() throws Exception {
UUID roleId = UUID.randomUUID();
doThrow(new NotFoundException("Role: " + roleId))
.when(userService)
.findAllBy(any(), any(), any(), any(), eq(roleId), any(), eq(false), any(), any());
.findAllBy(any(), any(), any(), any(), any(), any(), eq(roleId), any(), eq(false), any(), any());

mockMvc.perform(get("/users")
.param("roleId", roleId.toString()))
Expand Down Expand Up @@ -923,6 +939,8 @@ public void testGetCasesIncludeDeletedNotSet() throws Exception {
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
anyBoolean(),
isNull(),
any()
Expand All @@ -936,7 +954,19 @@ public void testGetCasesIncludeDeletedNotSet() throws Exception {
.andReturn();

verify(userService, times(1))
.findAllBy(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), eq(false), isNull(), any());
.findAllBy(
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
eq(false),
isNull(),
any()
);
}

@DisplayName("Should set include deleted param to false when set to false")
Expand All @@ -949,6 +979,8 @@ public void testGetCasesIncludeDeletedFalse() throws Exception {
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
anyBoolean(),
isNull(),
any()
Expand All @@ -962,7 +994,19 @@ public void testGetCasesIncludeDeletedFalse() throws Exception {
.andReturn();

verify(userService, times(1))
.findAllBy(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), eq(false), isNull(), any());
.findAllBy(
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
eq(false),
isNull(),
any()
);
}

@DisplayName("Should set include deleted param to true when set to true")
Expand All @@ -975,6 +1019,8 @@ public void testGetCasesIncludeDeletedTrue() throws Exception {
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
anyBoolean(),
isNull(),
any()
Expand All @@ -988,7 +1034,19 @@ public void testGetCasesIncludeDeletedTrue() throws Exception {
.andReturn();

verify(userService, times(1))
.findAllBy(isNull(), isNull(), isNull(), isNull(), isNull(), isNull(), eq(true), isNull(), any());
.findAllBy(
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
isNull(),
eq(true),
isNull(),
any()
);
}

@DisplayName("Should undelete a user by id and return a 200 response")
Expand Down
Loading