Skip to content

Commit

Permalink
[SELC-4683] Fixed get users by institutionId to retrieve all product
Browse files Browse the repository at this point in the history
  • Loading branch information
flaminiaScarciofolo committed Apr 11, 2024
1 parent 8cefca7 commit d41d876
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 160 deletions.
2 changes: 1 addition & 1 deletion app/src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ logging:

dashboard:
security:
connector: ${B4F_DASHBOARD_SECURITY_CONNECTOR:v1}
connector: ${B4F_DASHBOARD_SECURITY_CONNECTOR:v2}
167 changes: 16 additions & 151 deletions connector/rest/docs/openapi/selfcare-user-docs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"openapi" : "3.0.3",
"info" : {
"title" : "user-ms API",
"title" : "User API (development)",
"version" : "1.0.0"
},
"servers" : [ {
Expand Down Expand Up @@ -316,17 +316,8 @@
}
}
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
},
"post" : {
"tags" : [ "User Controller" ],
Expand All @@ -350,17 +341,8 @@
}
}
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/emails" : {
Expand Down Expand Up @@ -395,17 +377,8 @@
}
}
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/ids" : {
Expand Down Expand Up @@ -435,17 +408,8 @@
}
}
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/notification" : {
Expand Down Expand Up @@ -485,17 +449,8 @@
}
}
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/search" : {
Expand Down Expand Up @@ -528,17 +483,8 @@
}
}
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/{id}" : {
Expand Down Expand Up @@ -575,17 +521,8 @@
}
}
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/{id}/details" : {
Expand Down Expand Up @@ -622,17 +559,8 @@
}
}
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/{id}/institution/{institutionId}/product/{productId}/status" : {
Expand Down Expand Up @@ -671,17 +599,8 @@
"responses" : {
"204" : {
"description" : "No Content"
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/{id}/status" : {
Expand Down Expand Up @@ -732,17 +651,8 @@
"content" : {
"application/json" : { }
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/{id}/user-registry" : {
Expand Down Expand Up @@ -778,17 +688,8 @@
"content" : {
"application/json" : { }
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/{userId}" : {
Expand Down Expand Up @@ -818,17 +719,8 @@
"content" : {
"application/json" : { }
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/{userId}/institution/{institutionId}" : {
Expand Down Expand Up @@ -905,17 +797,8 @@
}
}
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/{userId}/institutions" : {
Expand Down Expand Up @@ -955,17 +838,8 @@
}
}
}
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
},
"/users/{userId}/institutions/{institutionId}/products/{productId}" : {
Expand Down Expand Up @@ -997,17 +871,8 @@
"responses" : {
"204" : {
"description" : "No Content"
},
"403" : {
"description" : "Not Allowed"
},
"401" : {
"description" : "Not Authorized"
}
},
"security" : [ {
"SecurityScheme" : [ ]
} ]
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -162,13 +163,12 @@ public List<ProductUserResource> getUsers(@ApiParam("${swagger.dashboard.institu
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);
List<ProductUserResource> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -145,6 +143,29 @@ public static ProductUserResource toProductUser(UserInfo model) {
return resource;
}

public static List<ProductUserResource> toProductUsers(UserInfo model) {
List<ProductUserResource> 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;
Expand Down
Loading

0 comments on commit d41d876

Please sign in to comment.