diff --git a/app/src/main/resources/swagger/api-docs.json b/app/src/main/resources/swagger/api-docs.json index e3582c818..00abb9d5b 100644 --- a/app/src/main/resources/swagger/api-docs.json +++ b/app/src/main/resources/swagger/api-docs.json @@ -4278,6 +4278,11 @@ "format" : "email", "example" : "email@example.com" }, + "mobilePhone" : { + "pattern" : "^\\+?[0-9]{9,15}$", + "type" : "string", + "description" : "User's institutional phone number" + }, "name" : { "type" : "string", "description" : "User's name" diff --git a/connector-api/src/main/java/it/pagopa/selfcare/dashboard/connector/model/user/UpdateUserRequestDto.java b/connector-api/src/main/java/it/pagopa/selfcare/dashboard/connector/model/user/UpdateUserRequestDto.java index 6711817de..076bee18a 100644 --- a/connector-api/src/main/java/it/pagopa/selfcare/dashboard/connector/model/user/UpdateUserRequestDto.java +++ b/connector-api/src/main/java/it/pagopa/selfcare/dashboard/connector/model/user/UpdateUserRequestDto.java @@ -7,4 +7,5 @@ public class UpdateUserRequestDto { private String name; private String surname; private String email; + private String mobilePhone; } diff --git a/connector/rest/docs/openapi/selfcare-user-docs.json b/connector/rest/docs/openapi/selfcare-user-docs.json index 572c8f4d3..39d3966ca 100644 --- a/connector/rest/docs/openapi/selfcare-user-docs.json +++ b/connector/rest/docs/openapi/selfcare-user-docs.json @@ -21,6 +21,8 @@ "name" : "external-pnpg" }, { "name" : "external-v2" + }, { + "name" : "internal-pnpg" }, { "name" : "internal-v1" }, { @@ -472,7 +474,7 @@ } ] }, "post" : { - "tags" : [ "User" ], + "tags" : [ "User", "internal-pnpg" ], "summary" : "Create or update a user by fiscal code", "description" : "The createOrUpdateByFiscalCode function is used to create a new user or update an existing one.", "operationId" : "createOrUpdateByFiscalCode", @@ -1308,6 +1310,51 @@ "SecurityScheme" : [ ] } ] } + }, + "/users/{userId}/onboarding" : { + "post" : { + "tags" : [ "User" ], + "summary" : "Check if the user is manager or Update/create a user by userId with a new role", + "description" : "Checks if the user is already a manager for the specified product and, if not, creates or updates the user with a new role.", + "operationId" : "createUserByUserId", + "parameters" : [ { + "name" : "userId", + "in" : "path", + "required" : true, + "schema" : { + "type" : "string" + } + } ], + "requestBody" : { + "content" : { + "application/json" : { + "schema" : { + "$ref" : "#/components/schemas/AddUserRoleDto" + } + } + } + }, + "responses" : { + "200" : { + "description" : "The user is already a manager for the specified product.", + "content" : { + "application/json" : { } + } + }, + "201" : { + "description" : "The user has been created or updated with a new role." + }, + "401" : { + "description" : "Not Authorized" + }, + "403" : { + "description" : "Not Allowed" + } + }, + "security" : [ { + "SecurityScheme" : [ ] + } ] + } } }, "components" : { @@ -1577,7 +1624,6 @@ } }, "UpdateUserRequest" : { - "required" : [ "email" ], "type" : "object", "properties" : { "name" : { @@ -1588,6 +1634,10 @@ }, "email" : { "type" : "string" + }, + "mobilePhone" : { + "pattern" : "^\\+?[0-9]{9,15}$", + "type" : "string" } } }, @@ -1670,6 +1720,9 @@ "email" : { "$ref" : "#/components/schemas/CertifiableFieldResponseString" }, + "mobilePhone" : { + "$ref" : "#/components/schemas/CertifiableFieldResponseString" + }, "workContacts" : { "type" : "object", "additionalProperties" : { @@ -1875,6 +1928,12 @@ "productRole" : { "type" : "string" }, + "roles" : { + "type" : "array", + "items" : { + "type" : "string" + } + }, "relationshipStatus" : { "$ref" : "#/components/schemas/OnboardedProductState" } diff --git a/web/src/main/java/it/pagopa/selfcare/dashboard/web/model/UpdateUserDto.java b/web/src/main/java/it/pagopa/selfcare/dashboard/web/model/UpdateUserDto.java index ea63078bd..637047048 100644 --- a/web/src/main/java/it/pagopa/selfcare/dashboard/web/model/UpdateUserDto.java +++ b/web/src/main/java/it/pagopa/selfcare/dashboard/web/model/UpdateUserDto.java @@ -4,6 +4,7 @@ import lombok.Data; import javax.validation.constraints.Email; +import javax.validation.constraints.Pattern; @Data public class UpdateUserDto { @@ -17,4 +18,8 @@ public class UpdateUserDto { @ApiModelProperty(value = "${swagger.dashboard.user.model.institutionalEmail}") @Email private String email; + + @ApiModelProperty(value = "${swagger.dashboard.user.model.institutionalPhone}") + @Pattern(regexp = "^\\+?[0-9]{9,15}$", message = "Il numero di telefono non รจ valido") + private String mobilePhone; } diff --git a/web/src/main/resources/swagger/swagger_en.properties b/web/src/main/resources/swagger/swagger_en.properties index 8e5be3789..e4ccc5e96 100644 --- a/web/src/main/resources/swagger/swagger_en.properties +++ b/web/src/main/resources/swagger/swagger_en.properties @@ -103,6 +103,7 @@ swagger.dashboard.user.model.birthDate=User's birth date swagger.dashboard.user.model.email=User's personal email swagger.dashboard.user.model.workContacts=User's workcontacts, contains the emails associated to every institution the user is assigned to swagger.dashboard.user.model.institutionalEmail=User's institutional email +swagger.dashboard.user.model.institutionalPhone=User's institutional phone number swagger.dashboard.user.model.role=User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA] swagger.dashboard.user.model.selcRole=User's Selfcare role, available value: [ADMIN, ADMIN_EA, LIMITED] swagger.dashboard.user.model.fields=Fields to retrieve from pdv when searching for user 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 7b2a4adfa..de0f7020c 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 @@ -212,6 +212,50 @@ void updateUser() throws Exception { Mockito.verifyNoMoreInteractions(userServiceMock); } + @Test + void updateUserInvalidMobilePhone() throws Exception { + //given + final String id = "userId"; + final String institutionId = "institutionId"; + + byte[] userStream = Files.readAllBytes(Paths.get("src/test/resources/stubs/updateUserDto.json")); + UpdateUserDto updateUserDto = objectMapper.readValue(userStream, UpdateUserDto.class); + updateUserDto.setMobilePhone("12345678912345566788"); + + //when + mockMvc.perform(MockMvcRequestBuilders + .put(BASE_URL + "/{id}", id) + .queryParam("institutionId", institutionId) + .content(objectMapper.writeValueAsString(updateUserDto)) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isBadRequest()); + + Mockito.verifyNoInteractions(userServiceMock); + } + + @Test + void updateUserInvalidMail() throws Exception { + //given + final String id = "userId"; + final String institutionId = "institutionId"; + + byte[] userStream = Files.readAllBytes(Paths.get("src/test/resources/stubs/updateUserDto.json")); + UpdateUserDto updateUserDto = objectMapper.readValue(userStream, UpdateUserDto.class); + updateUserDto.setEmail("test"); + + //when + mockMvc.perform(MockMvcRequestBuilders + .put(BASE_URL + "/{id}", id) + .queryParam("institutionId", institutionId) + .content(objectMapper.writeValueAsString(updateUserDto)) + .contentType(MediaType.APPLICATION_JSON_VALUE) + .accept(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isBadRequest()); + + Mockito.verifyNoInteractions(userServiceMock); + } + @Test void getUsers_institutionIdProductIdValid() throws Exception { // given @@ -365,31 +409,6 @@ void search_EmptyObject() throws Exception { Mockito.verifyNoMoreInteractions(userServiceMock); } - @Test - void updateUser_EmptyObject() throws Exception { - //given - final String id = "userId"; - final String institutionId = "institutionId"; - - byte[] userStream = Files.readAllBytes(Paths.get("src/test/resources/stubs/updateUserDto.json")); - UpdateUserDto updateUserDto = objectMapper.readValue(userStream, UpdateUserDto.class); - - //when - mockMvc.perform(MockMvcRequestBuilders - .put(BASE_URL + "/{id}", id) - .queryParam("institutionId", institutionId) - .content(userStream) - .contentType(MediaType.APPLICATION_JSON_VALUE) - .accept(MediaType.APPLICATION_JSON_VALUE)) - .andExpect(status().isNoContent()) - .andExpect(content().string(emptyString())); - //then - verify(userServiceMock, times(1)) - .updateUser(id, institutionId, userMapper.fromUpdateUser(updateUserDto)); - - Mockito.verifyNoMoreInteractions(userServiceMock); - } - @Test void getUsers_institutionIdProductIdValid_EmptyObject() throws Exception { // given diff --git a/web/src/test/java/it/pagopa/selfcare/dashboard/web/model/UpdateUserDtoTest.java b/web/src/test/java/it/pagopa/selfcare/dashboard/web/model/UpdateUserDtoTest.java index f4c0f8e99..a5fc3a280 100644 --- a/web/src/test/java/it/pagopa/selfcare/dashboard/web/model/UpdateUserDtoTest.java +++ b/web/src/test/java/it/pagopa/selfcare/dashboard/web/model/UpdateUserDtoTest.java @@ -13,7 +13,6 @@ import java.util.HashMap; import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -46,7 +45,7 @@ void validateNullFields() { Class annotationToCheck = toCheckMap.get(violation.getPropertyPath().toString()); return !violation.getConstraintDescriptor().getAnnotation().annotationType().equals(annotationToCheck); }) - .collect(Collectors.toList()); + .toList(); assertTrue(filteredViolations.isEmpty()); } @@ -56,6 +55,7 @@ void validateNotNullFields() { // given UpdateUserDto model = TestUtils.mockInstance(new UpdateUserDto()); model.setEmail("email@example.com"); + model.setMobilePhone("1234567890"); // when Set> violations = validator.validate(model); // then @@ -69,6 +69,7 @@ void validate_emailFieldsNotValid() { HashMap> toCheckMap = new HashMap<>(); toCheckMap.put("email", Email.class); UpdateUserDto model = TestUtils.mockInstance(new UpdateUserDto()); + model.setMobilePhone("1234567890"); // when Set> violations = validator.validate(model); // then @@ -77,7 +78,7 @@ void validate_emailFieldsNotValid() { Class annotationToCheck = toCheckMap.get(violation.getPropertyPath().toString()); return !violation.getConstraintDescriptor().getAnnotation().annotationType().equals(annotationToCheck); }) - .collect(Collectors.toList()); + .toList(); assertTrue(filteredViolations.isEmpty()); } diff --git a/web/src/test/resources/stubs/updateUserDto.json b/web/src/test/resources/stubs/updateUserDto.json index 0f767e51f..9eb211453 100644 --- a/web/src/test/resources/stubs/updateUserDto.json +++ b/web/src/test/resources/stubs/updateUserDto.json @@ -1,5 +1,6 @@ { "email": "email@example.com", + "mobilePhone": "123456789", "name": "string", "surname": "string" }