Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAS-486 Remove duplicate calls to delius when getting applications #2910

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading