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-4683] Fix: fixed get users by institutionId to retrieve all product #406

Merged
merged 2 commits into from
Apr 11, 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
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,17 +248,18 @@ 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)))
when(userApiRestClient._usersUserIdInstitutionInstitutionIdGet(eq(institutionId), eq(loggedUserId), eq(null), eq(null), eq(null),eq(List.of("MANAGER", "DELEGATE", "SUB_DELEGATE")), eq(List.of("ACTIVE", "SUSPENDED"))))
.thenReturn(ResponseEntity.ok(Collections.emptyList()));

// when
Collection<UserInfo> result = userConnector.getUsers(institutionId, userInfoFilter, loggedUserId);

// then
assertTrue(result.isEmpty());
verify(userApiRestClient, times(1))._usersUserIdInstitutionInstitutionIdGet(eq(institutionId), eq(loggedUserId), eq(null), eq(null), eq(null),anyList(), eq(null));
verify(userApiRestClient, times(1))._usersUserIdInstitutionInstitutionIdGet(eq(institutionId), eq(loggedUserId), eq(null), eq(null), eq(null),eq(List.of("MANAGER", "DELEGATE", "SUB_DELEGATE")), eq(List.of("ACTIVE", "SUSPENDED")));
verifyNoMoreInteractions(userApiRestClient);
}

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
Loading