Skip to content

Commit

Permalink
MOSIP-37748: Removed checks in deactivate SBI and device for PARTNER_…
Browse files Browse the repository at this point in the history
…ADMIN (#1024)

Signed-off-by: Swetha K <[email protected]>
Co-authored-by: Swetha K <[email protected]>
  • Loading branch information
SwethaKrish4 and Swetha K authored Dec 6, 2024
1 parent a54b5d1 commit 79d6d2f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -546,28 +546,10 @@ public ResponseWrapperV2<DeviceDetailResponseDto> deactivateDevice(String device
ErrorCode.DEVICE_NOT_EXISTS.getErrorMessage());
}
DeviceDetail device = deviceDetail.get();
// check if the device is associated with user.
String deviceProviderId = device.getDeviceProviderId();
boolean deviceProviderExist = false;
Partner partnerDetails = new Partner();
for (Partner partner : partnerList) {
if (partner.getId().equals(deviceProviderId)) {
validatePartnerId(partner, userId);
deviceProviderExist = true;
partnerDetails = partner;
break;
}
}
if (!deviceProviderExist) {
LOGGER.info("sessionId", "idType", "id", "Device is not associated with user.");
throw new PartnerServiceException(ErrorCode.DEVICE_NOT_ASSOCIATED_WITH_USER.getErrorCode(),
ErrorCode.DEVICE_NOT_ASSOCIATED_WITH_USER.getErrorMessage());
}
//check if Partner is Active or not
if (!partnerDetails.getIsActive()) {
LOGGER.error("Partner is not Active with id {}", deviceProviderId);
throw new PartnerServiceException(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode(),
ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage());
boolean isAdmin = partnerHelper.isPartnerAdmin(authUserDetails().getAuthorities().toString());
if (!isAdmin) {
Partner partnerDetails = getAssociatedPartner(partnerList, device.getDeviceProviderId(), userId);
partnerHelper.checkIfPartnerIsNotActive(partnerDetails);
}
if (!device.getApprovalStatus().equals(APPROVED)) {
LOGGER.error("Unable to deactivate device with id {}", device.getId());
Expand Down Expand Up @@ -608,6 +590,25 @@ public ResponseWrapperV2<DeviceDetailResponseDto> deactivateDevice(String device
return responseWrapper;
}

public Partner getAssociatedPartner (List<Partner> partnerList, String deviceProviderId, String userId) {
boolean deviceProviderExist = false;
Partner partnerDetails = null;
for (Partner partner : partnerList) {
if (partner.getId().equals(deviceProviderId)) {
validatePartnerId(partner, userId);
deviceProviderExist = true;
partnerDetails = partner;
break;
}
}
if (!deviceProviderExist) {
LOGGER.info("sessionId", "idType", "id", "Device is not associated with user.");
throw new PartnerServiceException(ErrorCode.DEVICE_NOT_ASSOCIATED_WITH_USER.getErrorCode(),
ErrorCode.DEVICE_NOT_ASSOCIATED_WITH_USER.getErrorMessage());
}
return partnerDetails;
}

@Override
public ResponseWrapperV2<PageResponseV2Dto<DeviceDetailSummaryDto>> getAllDeviceDetails(String sortFieldName, String sortType, int pageNo, int pageSize, DeviceDetailFilterDto filterDto) {
ResponseWrapperV2<PageResponseV2Dto<DeviceDetailSummaryDto>> responseWrapper = new ResponseWrapperV2<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(String ftmId) {
boolean isAdmin = partnerHelper.isPartnerAdmin(authUserDetails().getAuthorities().toString());
if(!isAdmin){
Partner partnerDetails = getAssociatedPartner(partnerList, ftm, userId);
checkIfPartnerIsNotActive(partnerDetails);
partnerHelper.checkIfPartnerIsNotActive(partnerDetails);
}

if (!ftm.getApprovalStatus().equals(APPROVED)) {
Expand Down Expand Up @@ -619,7 +619,7 @@ public ResponseWrapperV2<FtmCertificateDownloadResponseDto> getOriginalFtmCertif
boolean isAdmin = partnerHelper.isPartnerAdmin(authUserDetails().getAuthorities().toString());
if(!isAdmin){
Partner partnerDetails = getAssociatedPartner(partnerList, ftm, userId);
checkIfPartnerIsNotActive(partnerDetails);
partnerHelper.checkIfPartnerIsNotActive(partnerDetails);
}

if (!(ftm.getApprovalStatus().equals(PENDING_APPROVAL) || ftm.getApprovalStatus().equals(APPROVED))) {
Expand Down Expand Up @@ -731,14 +731,6 @@ public static void validateFtmChipDetail(Optional<FTPChipDetail> ftmChipDetail)
}
}

public static void checkIfPartnerIsNotActive(Partner partner) {
if (!partner.getIsActive()) {
LOGGER.error("Partner is not Active with id {}", partner.getId());
throw new PartnerServiceException(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode(),
ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage());
}
}

public Partner getAssociatedPartner(List<Partner> partnerList, FTPChipDetail ftm, String userId) {
String ftmProviderId = ftm.getFtpProviderId();
boolean ftmProviderExist = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,28 +775,11 @@ public ResponseWrapperV2<SbiDetailsResponseDto> deactivateSbi(String sbiId) {
ErrorCode.SBI_NOT_EXISTS.getErrorMessage());
}
SecureBiometricInterface sbi = secureBiometricInterface.get();
// check if the SBI is associated with user.
String sbiProviderId = sbi.getProviderId();
boolean sbiProviderExist = false;
Partner partnerDetails = new Partner();
for (Partner partner : partnerList) {
if (partner.getId().equals(sbiProviderId)) {
validatePartnerId(partner, userId);
sbiProviderExist = true;
partnerDetails = partner;
break;
}
}
if (!sbiProviderExist) {
LOGGER.info("sessionId", "idType", "id", "SBI is not associated with user.");
throw new PartnerServiceException(ErrorCode.SBI_NOT_ASSOCIATED_WITH_USER.getErrorCode(),
ErrorCode.SBI_NOT_ASSOCIATED_WITH_USER.getErrorMessage());
}
//check if Partner is Active or not
if (!partnerDetails.getIsActive()) {
LOGGER.error("Partner is not Active with id {}", sbiProviderId);
throw new PartnerServiceException(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode(),
ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage());

boolean isAdmin = partnerHelper.isPartnerAdmin(authUserDetails().getAuthorities().toString());
if (!isAdmin) {
Partner partnerDetails = getAssociatedPartner(partnerList, sbi.getProviderId(), userId);
partnerHelper.checkIfPartnerIsNotActive(partnerDetails);
}
if (!sbi.getApprovalStatus().equals(APPROVED)) {
LOGGER.error("Unable to deactivate sbi with id {}", sbi.getId());
Expand Down Expand Up @@ -852,6 +835,25 @@ public ResponseWrapperV2<SbiDetailsResponseDto> deactivateSbi(String sbiId) {
return responseWrapper;
}

public Partner getAssociatedPartner (List<Partner> partnerList, String sbiProviderId, String userId) {
boolean sbiProviderExist = false;
Partner partnerDetails = null;
for (Partner partner : partnerList) {
if (partner.getId().equals(sbiProviderId)) {
validatePartnerId(partner, userId);
sbiProviderExist = true;
partnerDetails = partner;
break;
}
}
if (!sbiProviderExist) {
LOGGER.info("sessionId", "idType", "id", "SBI is not associated with user.");
throw new PartnerServiceException(ErrorCode.SBI_NOT_ASSOCIATED_WITH_USER.getErrorCode(),
ErrorCode.SBI_NOT_ASSOCIATED_WITH_USER.getErrorMessage());
}
return partnerDetails;
}

@Override
public ResponseWrapperV2<PageResponseV2Dto<SbiSummaryDto>> getAllSbiDetails(String sortFieldName, String sortType, int pageNo, int pageSize, SbiFilterDto filterDto) {
ResponseWrapperV2<PageResponseV2Dto<SbiSummaryDto>> responseWrapper = new ResponseWrapperV2<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.pms.common.constant.ApiAccessibleExceptionConstant;
import io.mosip.pms.common.entity.Partner;
import io.mosip.pms.common.exception.ApiAccessibleException;
import io.mosip.pms.common.repository.DeviceDetailSbiRepository;
import io.mosip.pms.common.util.PMSLogger;
Expand Down Expand Up @@ -310,4 +311,12 @@ public void validateRequestParameters(Map<String, String> aliasToColumnMap, Stri
ErrorCode.INVALID_PAGE_SIZE.getErrorMessage());
}
}

public void checkIfPartnerIsNotActive(Partner partner) {
if (!partner.getIsActive()) {
LOGGER.error("Partner is not Active with id {}", partner.getId());
throw new PartnerServiceException(ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorCode(),
ErrorCode.PARTNER_NOT_ACTIVE_EXCEPTION.getErrorMessage());
}
}
}

0 comments on commit 79d6d2f

Please sign in to comment.