From 8cefca730114887d922dc121d9370ce1eac2f583 Mon Sep 17 00:00:00 2001 From: empassaro <113031808+empassaro@users.noreply.github.com> Date: Wed, 10 Apr 2024 18:00:30 +0200 Subject: [PATCH] [SELC-4683] fix: added filter to remove products from userinstitution records when state isn't allowed (#405) --- .../dashboard/core/UserV2ServiceImpl.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/it/pagopa/selfcare/dashboard/core/UserV2ServiceImpl.java b/core/src/main/java/it/pagopa/selfcare/dashboard/core/UserV2ServiceImpl.java index 3435419d..7fe2cf7d 100644 --- a/core/src/main/java/it/pagopa/selfcare/dashboard/core/UserV2ServiceImpl.java +++ b/core/src/main/java/it/pagopa/selfcare/dashboard/core/UserV2ServiceImpl.java @@ -14,8 +14,8 @@ import it.pagopa.selfcare.dashboard.connector.model.user.*; import it.pagopa.selfcare.dashboard.core.exception.InvalidOnboardingStatusException; import it.pagopa.selfcare.dashboard.core.exception.InvalidProductRoleException; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.util.Assert; @@ -27,15 +27,29 @@ @Slf4j @Service -@RequiredArgsConstructor public class UserV2ServiceImpl implements UserV2Service { private final MsCoreConnector msCoreConnector; private final UserGroupV2Service userGroupService; private final UserApiConnector userApiConnector; private final ProductsConnector productsConnector; + + private final List allowedStates; private static final EnumSet PARTY_ROLE_WHITE_LIST = EnumSet.of(PartyRole.SUB_DELEGATE, PartyRole.OPERATOR); + public UserV2ServiceImpl( + MsCoreConnector msCoreConnector, + UserGroupV2Service userGroupService, + UserApiConnector userApiConnector, ProductsConnector productsConnector, + @Value("${dashboard.institution.getUsers.filter.states}") String[] allowedStates + ) { + this.msCoreConnector = msCoreConnector; + this.userGroupService = userGroupService; + this.userApiConnector = userApiConnector; + this.productsConnector = productsConnector; + this.allowedStates = allowedStates != null && allowedStates.length != 0 ? Arrays.stream(allowedStates).map(RelationshipState::valueOf).toList() : null; + } + @Override public Collection getInstitutions(String userId) { @@ -114,6 +128,7 @@ public Collection getUsersByInstitutionId(String institutionId, String UserInfo.UserInfoFilter userInfoFilter = new UserInfo.UserInfoFilter(); userInfoFilter.setProductId(productId); userInfoFilter.setProductRoles(productRoles); + userInfoFilter.setAllowedStates(allowedStates); Collection result = userApiConnector.getUsers(institutionId, userInfoFilter, loggedUserId); log.info("getUsersByInstitutionId result size = {}", result.size()); log.trace("getUsersByInstitutionId end");