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

[SELC-6055] feat: add fiscalCode and createdAt fields in getUsers API and add roles filter #496

Merged
merged 4 commits into from
Nov 25, 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
23 changes: 21 additions & 2 deletions app/src/main/resources/swagger/api-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2466,6 +2466,16 @@
"schema" : {
"type" : "string"
}
}, {
"name" : "roles",
"in" : "query",
"description" : "roles",
"required" : false,
"style" : "form",
"explode" : true,
"schema" : {
"type" : "string"
}
} ],
"responses" : {
"200" : {
Expand Down Expand Up @@ -3928,7 +3938,7 @@
},
"selcRole" : {
"type" : "string",
"description" : "User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]",
"description" : "User's Selfcare role, available value: [ADMIN, ADMIN_EA, LIMITED]",
"enum" : [ "ADMIN", "ADMIN_EA", "LIMITED" ]
},
"status" : {
Expand Down Expand Up @@ -3993,10 +4003,19 @@
"title" : "ProductUserResource",
"type" : "object",
"properties" : {
"createdAt" : {
"type" : "string",
"description" : "User's creation date associated with a product",
"format" : "date-time"
},
"email" : {
"type" : "string",
"description" : "User's personal email"
},
"fiscalCode" : {
"type" : "string",
"description" : "User's fiscal code"
},
"id" : {
"type" : "string",
"description" : "User's unique identifier",
Expand All @@ -4012,7 +4031,7 @@
},
"role" : {
"type" : "string",
"description" : "User's role, available value: [MANAGER, DELEGATE, SUBDELEGATE, OPERATOR, ADMIN_EA]",
"description" : "User's Selfcare role, available value: [ADMIN, ADMIN_EA, LIMITED]",
"enum" : [ "ADMIN", "ADMIN_EA", "LIMITED" ]
},
"status" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

@Data
Expand All @@ -10,5 +11,6 @@ public class ProductInfo {
private String id;
private String title;
private List<RoleInfo> roleInfos;
private LocalDateTime createdAt;

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.*;
import java.util.List;
import java.util.Map;

@Data
@EqualsAndHashCode(of = "id")
Expand All @@ -24,6 +25,7 @@ public static class UserInfoFilter {
private SelfCareAuthority role;
private String productId;
private List<String> productRoles;
private List<String> roles;
private String userId;
private List<RelationshipState> allowedStates;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ public Collection<UserInfo> getUsers(String institutionId, UserInfo.UserInfoFilt

Assert.hasText(institutionId, REQUIRED_INSTITUTION_ID_MESSAGE);

List<String> roles = Arrays.stream(PartyRole.values())
.filter(partyRole -> partyRole.getSelfCareAuthority().equals(userInfoFilter.getRole()))
.map(Enum::name)
.toList();
List<String> roles = Optional.ofNullable(userInfoFilter.getRoles()).orElse(
Arrays.stream(PartyRole.values())
.filter(partyRole -> partyRole.getSelfCareAuthority().equals(userInfoFilter.getRole()))
.map(Enum::name)
.toList());

return Optional.ofNullable(userApiRestClient._retrieveUsers(institutionId,
loggedUserId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import it.pagopa.selfcare.dashboard.connector.model.user.User;
import it.pagopa.selfcare.dashboard.connector.model.user.*;
import it.pagopa.selfcare.user.generated.openapi.v1.dto.*;
import it.pagopa.selfcare.user.generated.openapi.v1.dto.UserInstitutionWithActions;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
Expand Down Expand Up @@ -92,6 +91,7 @@ default Map<String, ProductInfo> toProductInfoMap(List<OnboardedProductResponse>
onboardedProducts.forEach(onboardedProduct -> {
RoleInfo roleInfo = new RoleInfo();
productInfo.setId(onboardedProduct.getProductId());
productInfo.setCreatedAt(onboardedProduct.getCreatedAt());
roleInfo.setRole(onboardedProduct.getProductRole());
roleInfo.setStatus(onboardedProduct.getStatus().name());
roleInfo.setSelcRole(it.pagopa.selfcare.commons.base.security.PartyRole.valueOf(onboardedProduct.getRole()).getSelfCareAuthority());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package it.pagopa.selfcare.dashboard.core;

import it.pagopa.selfcare.dashboard.connector.model.institution.InstitutionBase;
import it.pagopa.selfcare.dashboard.connector.model.user.*;
import it.pagopa.selfcare.dashboard.connector.model.user.UpdateUserRequestDto;
import it.pagopa.selfcare.dashboard.connector.model.user.User;
import it.pagopa.selfcare.dashboard.connector.model.user.UserInfo;
import it.pagopa.selfcare.dashboard.connector.model.user.UserToCreate;

import java.util.Collection;
import java.util.List;
Expand All @@ -23,7 +26,7 @@ public interface UserV2Service {

void updateUser(String id, String institutionId, UpdateUserRequestDto userDto);

Collection<UserInfo> getUsersByInstitutionId(String institutionId, String productId, List<String> productRoles, String loggedUserId);
Collection<UserInfo> getUsersByInstitutionId(String institutionId, String productId, List<String> productRoles, List<String> roles , String loggedUserId);

String createUsers(String institutionId, String productId, UserToCreate userToCreate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,14 @@ public void updateUser(String id, String institutionId, UpdateUserRequestDto use
}

@Override
public Collection<UserInfo> getUsersByInstitutionId(String institutionId, String productId, List<String> productRoles, String loggedUserId) {
public Collection<UserInfo> getUsersByInstitutionId(String institutionId, String productId, List<String> productRoles, List<String> roles, String loggedUserId) {
log.trace("getUsersByInstitutionId start");
log.debug("getUsersByInstitutionId institutionId = {}", institutionId);
UserInfo.UserInfoFilter userInfoFilter = new UserInfo.UserInfoFilter();
userInfoFilter.setProductId(productId);
userInfoFilter.setProductRoles(productRoles);
userInfoFilter.setAllowedStates(allowedStates);
userInfoFilter.setRoles(roles);
Collection<UserInfo> result = userApiConnector.getUsers(institutionId, userInfoFilter, loggedUserId);
log.info("getUsersByInstitutionId result size = {}", result.size());
log.trace("getUsersByInstitutionId end");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void getUsersByInstitutionIdWithoutInstitutionId() {
List<String> productRoles = new ArrayList<>();
String loggedUserId = "loggedUserId";

Collection<UserInfo> result = userV2ServiceImpl.getUsersByInstitutionId(institutionId, productId, productRoles, loggedUserId);
Collection<UserInfo> result = userV2ServiceImpl.getUsersByInstitutionId(institutionId, productId, productRoles, null, loggedUserId);
Assertions.assertTrue(result.isEmpty());
}

Expand All @@ -171,7 +171,7 @@ void getUsersByInstitutionIdEmptyUserInfo() {

when(userApiConnectorMock.getUsers(institutionId, userInfoFilter, loggedUserId)).thenReturn(new ArrayList<>());

Collection<UserInfo> result = userV2ServiceImpl.getUsersByInstitutionId(institutionId, productId, productRoles, loggedUserId);
Collection<UserInfo> result = userV2ServiceImpl.getUsersByInstitutionId(institutionId, productId, productRoles, null, loggedUserId);
Assertions.assertTrue(result.isEmpty());
}

Expand All @@ -195,7 +195,7 @@ void getUsersByInstitutionId() throws IOException {

when(userApiConnectorMock.getUsers(institutionId, userInfoFilter, loggedUserId)).thenReturn(userInfo);

Collection<UserInfo> result = userV2ServiceImpl.getUsersByInstitutionId(institutionId, productId, productRoles, loggedUserId);
Collection<UserInfo> result = userV2ServiceImpl.getUsersByInstitutionId(institutionId, productId, productRoles, null, loggedUserId);
Assertions.assertEquals(userInfo, result);
Mockito.verify(userApiConnectorMock, Mockito.times(1)).getUsers(institutionId, userInfoFilter, loggedUserId);
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<description>Self Care Dashboard Backend</description>

<properties>
<selc-commons.version>2.5.3</selc-commons.version>
<selc-commons.version>2.5.4</selc-commons.version>
<sonar.host.url>https://sonarcloud.io/</sonar.host.url>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,14 @@ public List<ProductUserResource> getUsers(@ApiParam("${swagger.dashboard.institu
@PathVariable("institutionId") String institutionId,
@RequestParam(value = "productId", required = false) String productId,
@RequestParam(value = "productRoles", required = false) List<String> productRoles,
@RequestParam(value = "roles", required = false) List<String> roles,
Authentication authentication) {
log.trace("getUsers start");
log.debug("getUsers for institution: {} and product: {}", institutionId, productId);
String loggedUserId = ((SelfCareUser) authentication.getPrincipal()).getId();

List<ProductUserResource> response = new ArrayList<>();
Collection<UserInfo> userInfos = userService.getUsersByInstitutionId(institutionId, productId, productRoles, loggedUserId);
Collection<UserInfo> userInfos = userService.getUsersByInstitutionId(institutionId, productId, productRoles, roles, loggedUserId);
userInfos.forEach(userInfo -> response.addAll(UserMapper.toProductUsers(userInfo)));
log.debug("getUsers result = {}", response);
log.trace("getUsers end");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ public static List<ProductUserResource> toProductUsers(UserInfo model) {
if (model.getUser() != null) {
resource.setName(CertifiedFieldMapper.toValue(model.getUser().getName()));
resource.setSurname(CertifiedFieldMapper.toValue(model.getUser().getFamilyName()));
resource.setFiscalCode(model.getUser().getFiscalCode());
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));
resource.setCreatedAt(productInfo.getCreatedAt());
response.add(resource);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ProductRoleInfoResource {
private String role;
@ApiModelProperty(value = "${swagger.dashboard.user.model.status}")
private String status;
@ApiModelProperty(value = "${swagger.dashboard.user.model.role}")
@ApiModelProperty(value = "${swagger.dashboard.user.model.selcRole}")
private SelfCareAuthority selcRole;

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import it.pagopa.selfcare.commons.base.security.SelfCareAuthority;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.UUID;

@Data
Expand All @@ -30,10 +31,13 @@ public class ProductUserResource {
@ApiModelProperty(value = "${swagger.dashboard.user.model.surname}")
private String surname;

@ApiModelProperty(value = "${swagger.dashboard.user.model.fiscalCode}")
private String fiscalCode;

@ApiModelProperty(value = "${swagger.dashboard.user.model.email}")
private String email;

@ApiModelProperty(value = "${swagger.dashboard.user.model.role}")
@ApiModelProperty(value = "${swagger.dashboard.user.model.selcRole}")
private SelfCareAuthority role;

@ApiModelProperty(value = "${swagger.dashboard.user.model.product}")
Expand All @@ -42,5 +46,8 @@ public class ProductUserResource {
@ApiModelProperty(value = "${swagger.dashboard.user.model.status}")
private String status;

@ApiModelProperty(value = "${swagger.dashboard.user.model.createdAt}")
private LocalDateTime createdAt;


}
2 changes: 2 additions & 0 deletions web/src/main/resources/swagger/swagger_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ 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.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
swagger.dashboard.user.model.createdAt=User's creation date associated with a product
swagger.dashboard.products.model.roleInfos=User's role infos in product
swagger.dashboard.user.model.productRoles=User's roles in product
swagger.dashboard.user.model.productRole=User's role in product
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import it.pagopa.selfcare.dashboard.web.model.UpdateUserDto;
import it.pagopa.selfcare.dashboard.web.model.mapper.UserMapperV2Impl;
import it.pagopa.selfcare.dashboard.web.model.user.UserResource;
import it.pagopa.selfcare.onboarding.common.PartyRole;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -223,21 +224,22 @@ void getUsers_institutionIdProductIdValid() throws Exception {
UserInfo userInfo = objectMapper.readValue(userInfoStream, UserInfo.class);
List<UserInfo> userInfos = List.of(userInfo);

when(userServiceMock.getUsersByInstitutionId(institutionId, productId, null, "userId")).thenReturn(userInfos);
when(userServiceMock.getUsersByInstitutionId(institutionId, productId, null, List.of(PartyRole.MANAGER.name()), "userId")).thenReturn(userInfos);

// when
mockMvc.perform(MockMvcRequestBuilders
.get(BASE_URL + "/institution/" + institutionId)
.principal(authentication)
.queryParam("productId", productId)
.queryParam("roles", PartyRole.MANAGER.name())
.contentType(APPLICATION_JSON_VALUE)
.accept(APPLICATION_JSON_VALUE))
.andExpect(status().isOk())
.andExpect(content().json(new String(Files.readAllBytes(Paths.get(FILE_JSON_PATH + "ProductUserResource.json")))));

// then
verify(userServiceMock, times(1))
.getUsersByInstitutionId(institutionId, productId, null, "userId");
.getUsersByInstitutionId(institutionId, productId, null, List.of(PartyRole.MANAGER.name()), "userId");
verifyNoMoreInteractions(userServiceMock);
}

Expand Down Expand Up @@ -397,7 +399,7 @@ void getUsers_institutionIdProductIdValid_EmptyObject() throws Exception {
when(authentication.getPrincipal()).thenReturn(SelfCareUser.builder("userId").build());

// when
when(userServiceMock.getUsersByInstitutionId(institutionId, productId, null, "userId"))
when(userServiceMock.getUsersByInstitutionId(institutionId, productId, null, null, "userId"))
.thenReturn(List.of(new UserInfo()));

// when
Expand All @@ -412,7 +414,7 @@ void getUsers_institutionIdProductIdValid_EmptyObject() throws Exception {

// then
verify(userServiceMock, times(1))
.getUsersByInstitutionId(institutionId, productId, null, "userId");
.getUsersByInstitutionId(institutionId, productId, null, null, "userId");
verifyNoMoreInteractions(userServiceMock);
}

Expand Down
Loading