Skip to content

Commit

Permalink
Remove duplicate calls to delius to check if the user have access to …
Browse files Browse the repository at this point in the history
…the applications
  • Loading branch information
Muhammad El Abdulla authored and muhammad-elabdulla committed Jan 31, 2025
1 parent 0a9417a commit 2aadb4a
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 2aadb4a

Please sign in to comment.