Skip to content

Commit

Permalink
[SELC-4683] fix: added filter to remove products from userinstitution…
Browse files Browse the repository at this point in the history
… records when state isn't allowed (#405)
  • Loading branch information
empassaro authored Apr 10, 2024
1 parent 94b9fc9 commit 8cefca7
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<RelationshipState> allowedStates;
private static final EnumSet<PartyRole> 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<InstitutionBase> getInstitutions(String userId) {
Expand Down Expand Up @@ -114,6 +128,7 @@ public Collection<UserInfo> getUsersByInstitutionId(String institutionId, String
UserInfo.UserInfoFilter userInfoFilter = new UserInfo.UserInfoFilter();
userInfoFilter.setProductId(productId);
userInfoFilter.setProductRoles(productRoles);
userInfoFilter.setAllowedStates(allowedStates);
Collection<UserInfo> result = userApiConnector.getUsers(institutionId, userInfoFilter, loggedUserId);
log.info("getUsersByInstitutionId result size = {}", result.size());
log.trace("getUsersByInstitutionId end");
Expand Down

0 comments on commit 8cefca7

Please sign in to comment.