From d41d8763b4b54f31021597e701c342e2a0ab1d53 Mon Sep 17 00:00:00 2001 From: flaminiaScarciofolo Date: Thu, 11 Apr 2024 13:58:00 +0200 Subject: [PATCH] [SELC-4683] Fixed get users by institutionId to retrieve all product --- app/src/main/resources/config/application.yml | 2 +- .../rest/docs/openapi/selfcare-user-docs.json | 167 ++---------------- .../connector/rest/UserConnectorImplTest.java | 1 + .../web/controller/UserV2Controller.java | 10 +- .../web/model/mapper/UserMapper.java | 27 ++- .../web/controller/UserV2ControllerTest.java | 11 ++ 6 files changed, 58 insertions(+), 160 deletions(-) diff --git a/app/src/main/resources/config/application.yml b/app/src/main/resources/config/application.yml index a1ba795a..f28f0621 100644 --- a/app/src/main/resources/config/application.yml +++ b/app/src/main/resources/config/application.yml @@ -33,4 +33,4 @@ logging: dashboard: security: - connector: ${B4F_DASHBOARD_SECURITY_CONNECTOR:v1} \ No newline at end of file + connector: ${B4F_DASHBOARD_SECURITY_CONNECTOR:v2} \ No newline at end of file diff --git a/connector/rest/docs/openapi/selfcare-user-docs.json b/connector/rest/docs/openapi/selfcare-user-docs.json index 10c0fe6c..8b0f8171 100644 --- a/connector/rest/docs/openapi/selfcare-user-docs.json +++ b/connector/rest/docs/openapi/selfcare-user-docs.json @@ -1,7 +1,7 @@ { "openapi" : "3.0.3", "info" : { - "title" : "user-ms API", + "title" : "User API (development)", "version" : "1.0.0" }, "servers" : [ { @@ -316,17 +316,8 @@ } } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } }, "post" : { "tags" : [ "User Controller" ], @@ -350,17 +341,8 @@ } } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/emails" : { @@ -395,17 +377,8 @@ } } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/ids" : { @@ -435,17 +408,8 @@ } } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/notification" : { @@ -485,17 +449,8 @@ } } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/search" : { @@ -528,17 +483,8 @@ } } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/{id}" : { @@ -575,17 +521,8 @@ } } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/{id}/details" : { @@ -622,17 +559,8 @@ } } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/{id}/institution/{institutionId}/product/{productId}/status" : { @@ -671,17 +599,8 @@ "responses" : { "204" : { "description" : "No Content" - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/{id}/status" : { @@ -732,17 +651,8 @@ "content" : { "application/json" : { } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/{id}/user-registry" : { @@ -778,17 +688,8 @@ "content" : { "application/json" : { } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/{userId}" : { @@ -818,17 +719,8 @@ "content" : { "application/json" : { } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/{userId}/institution/{institutionId}" : { @@ -905,17 +797,8 @@ } } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/{userId}/institutions" : { @@ -955,17 +838,8 @@ } } } - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } }, "/users/{userId}/institutions/{institutionId}/products/{productId}" : { @@ -997,17 +871,8 @@ "responses" : { "204" : { "description" : "No Content" - }, - "403" : { - "description" : "Not Allowed" - }, - "401" : { - "description" : "Not Authorized" } - }, - "security" : [ { - "SecurityScheme" : [ ] - } ] + } } } }, diff --git a/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/UserConnectorImplTest.java b/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/UserConnectorImplTest.java index 85248b31..76f172f8 100644 --- a/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/UserConnectorImplTest.java +++ b/connector/rest/src/test/java/it/pagopa/selfcare/dashboard/connector/rest/UserConnectorImplTest.java @@ -248,6 +248,7 @@ void getUsers_emptyList() { String loggedUserId = "loggedUserId"; UserInfo.UserInfoFilter userInfoFilter = new UserInfo.UserInfoFilter(); + userInfoFilter.setAllowedStates(List.of(ACTIVE, SUSPENDED)); userInfoFilter.setRole(SelfCareAuthority.ADMIN); when(userApiRestClient._usersUserIdInstitutionInstitutionIdGet(eq(institutionId), eq(loggedUserId), eq(null), eq(null), eq(null),anyList(), eq(null))) diff --git a/web/src/main/java/it/pagopa/selfcare/dashboard/web/controller/UserV2Controller.java b/web/src/main/java/it/pagopa/selfcare/dashboard/web/controller/UserV2Controller.java index e24363dc..fe956aaa 100644 --- a/web/src/main/java/it/pagopa/selfcare/dashboard/web/controller/UserV2Controller.java +++ b/web/src/main/java/it/pagopa/selfcare/dashboard/web/controller/UserV2Controller.java @@ -27,6 +27,7 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; +import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -162,13 +163,12 @@ public List getUsers(@ApiParam("${swagger.dashboard.institu log.debug("getUsers for institution: {} and product: {}", institutionId, productId); String loggedUserId = ((SelfCareUser) authentication.getPrincipal()).getId(); + List response = new ArrayList<>(); Collection userInfos = userService.getUsersByInstitutionId(institutionId, productId, productRoles, loggedUserId); - List result = userInfos.stream() - .map(UserMapper::toProductUser) - .toList(); - log.debug("getUsers result = {}", result); + userInfos.forEach(userInfo -> response.addAll(UserMapper.toProductUsers(userInfo))); + log.debug("getUsers result = {}", response); log.trace("getUsers end"); - return result; + return response; } } diff --git a/web/src/main/java/it/pagopa/selfcare/dashboard/web/model/mapper/UserMapper.java b/web/src/main/java/it/pagopa/selfcare/dashboard/web/model/mapper/UserMapper.java index 92907bfb..8e9c3604 100644 --- a/web/src/main/java/it/pagopa/selfcare/dashboard/web/model/mapper/UserMapper.java +++ b/web/src/main/java/it/pagopa/selfcare/dashboard/web/model/mapper/UserMapper.java @@ -15,9 +15,7 @@ import lombok.AccessLevel; import lombok.NoArgsConstructor; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -145,6 +143,29 @@ public static ProductUserResource toProductUser(UserInfo model) { return resource; } + public static List toProductUsers(UserInfo model) { + List response = new ArrayList<>(); + if (model != null && model.getProducts() != null && !model.getProducts().isEmpty()) { + model.getProducts().forEach((s, productInfo) -> { + ProductUserResource resource = new ProductUserResource(); + resource.setId(UUID.fromString(model.getId())); + resource.setRole(model.getRole()); + resource.setStatus(model.getStatus()); + if (model.getUser() != null) { + resource.setName(CertifiedFieldMapper.toValue(model.getUser().getName())); + resource.setSurname(CertifiedFieldMapper.toValue(model.getUser().getFamilyName())); + Optional.ofNullable(model.getUser().getWorkContacts()) + .map(map -> map.get(model.getUserMailUuid())) + .map(WorkContact::getEmail) + .map(CertifiedFieldMapper::toValue) + .ifPresent(resource::setEmail); + } + resource.setProduct(UserMapper.toUserProductInfoResource(productInfo)); + response.add(resource); + }); + } + return response; + } public static it.pagopa.selfcare.dashboard.connector.model.user.CreateUserDto fromCreateUserDto(CreateUserDto dto, String institutionId) { it.pagopa.selfcare.dashboard.connector.model.user.CreateUserDto model = null; diff --git a/web/src/test/java/it/pagopa/selfcare/dashboard/web/controller/UserV2ControllerTest.java b/web/src/test/java/it/pagopa/selfcare/dashboard/web/controller/UserV2ControllerTest.java index 927cc700..475f4c1a 100644 --- a/web/src/test/java/it/pagopa/selfcare/dashboard/web/controller/UserV2ControllerTest.java +++ b/web/src/test/java/it/pagopa/selfcare/dashboard/web/controller/UserV2ControllerTest.java @@ -34,7 +34,9 @@ import java.util.List; import java.util.Map; +import static it.pagopa.selfcare.commons.base.security.SelfCareAuthority.ADMIN; import static it.pagopa.selfcare.commons.utils.TestUtils.mockInstance; +import static it.pagopa.selfcare.dashboard.connector.model.institution.RelationshipState.ACTIVE; import static java.util.UUID.randomUUID; import static org.hamcrest.Matchers.emptyString; import static org.junit.jupiter.api.Assertions.*; @@ -225,6 +227,15 @@ void getUsers_institutionIdProductIdValid() throws Exception { UserInfo userInfo = mockInstance(new UserInfo()); userInfo.setId(randomUUID().toString()); + Map map = new HashMap<>(); + ProductInfo productInfo = new ProductInfo(); + RoleInfo roleInfo = new RoleInfo(); + roleInfo.setSelcRole(ADMIN); + roleInfo.setRole("role"); + roleInfo.setStatus(ACTIVE.name()); + productInfo.setRoleInfos(List.of(roleInfo)); + map.put("productId", productInfo); + userInfo.setProducts(map); List userInfos = List.of(userInfo); when(userServiceMock.getUsersByInstitutionId(institutionId, productId, null, "userId")).thenReturn(userInfos);