Skip to content

Commit

Permalink
Merge pull request #2910 from ministryofjustice/CAS-486-remove-duplic…
Browse files Browse the repository at this point in the history
…ate-calls-to-delius-to-check-user-acess-to-applications

CAS-486 Remove duplicate calls to delius when getting applications
  • Loading branch information
muhammad-elabdulla authored Jan 31, 2025
2 parents 0a9417a + 2aadb4a commit 7cf4ec9
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,6 @@ class ApplicationsController(

val applications = applicationService.getAllApplicationsForUsername(user, serviceName)

/*
This code is inefficient:
getPersonDetailAndTransformToSummary will retrieve/check user access (via the call to offenderService),
but the prior call to getAllApplicationsForUsername has already retrieved this information
and filtered out applications that the user cannot access. This leads to duplicate calls being made.
This check should be moved into getPersonDetailAndTransformToSummary (or a custom version of it to
avoid breaking behaviour for other callers), where we filter out any response from
offenderService.getInfoForPerson of type PersonInfoResult.Restricted. This will most likely have
to be optional as to not 'break' other functions using getPersonDetailAndTransformToSummary
*/
return ResponseEntity.ok(getPersonDetailAndTransformToSummary(applications, user))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,12 @@ class ApplicationService(
fun getApplication(applicationId: UUID) = applicationRepository.findByIdOrNull(applicationId)

fun getAllApplicationsForUsername(userEntity: UserEntity, serviceName: ServiceName): List<ApplicationSummary> {
val applicationSummaries = when (serviceName) {
return when (serviceName) {
ServiceName.approvedPremises -> getAllApprovedPremisesApplicationsForUser(userEntity)
ServiceName.cas2 -> throw RuntimeException("CAS2 applications now require NomisUser")
ServiceName.cas2v2 -> throw RuntimeException("CAS2v2 applications now require Cas2v2User")
ServiceName.temporaryAccommodation -> getAllTemporaryAccommodationApplicationsForUser(userEntity)
}

val crns = applicationSummaries.map { it.getCrn() }.distinct()
val offendersAccess = offenderService.canAccessOffenders(userEntity.deliusUsername, crns)
return applicationSummaries.filter {
offendersAccess.containsKey(it.getCrn()) && offendersAccess[it.getCrn()] == true
}
}

fun getAllApprovedPremisesApplications(
Expand Down

0 comments on commit 7cf4ec9

Please sign in to comment.