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

fix(j-s): Merge Case Access #16053

Merged
merged 15 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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 @@ -264,8 +264,16 @@ export class BackendService extends DataSource<{ req: Request }> {
return this.post(`case/${id}/file`, createFile)
}

getCaseFileSignedUrl(caseId: string, id: string): Promise<SignedUrl> {
return this.get(`case/${caseId}/file/${id}/url`)
getCaseFileSignedUrl(
caseId: string,
id: string,
mergedCaseId?: string,
): Promise<SignedUrl> {
const mergedCaseInjection = mergedCaseId
? `/mergedCase/${mergedCaseId}`
: ''

return this.get(`case/${caseId}${mergedCaseInjection}/file/${id}/url`)
}

deleteCaseFile(caseId: string, id: string): Promise<DeleteFileResponse> {
Expand Down Expand Up @@ -396,8 +404,15 @@ export class BackendService extends DataSource<{ req: Request }> {
limitedAccessGetCaseFileSignedUrl(
caseId: string,
id: string,
mergedCaseId?: string,
): Promise<SignedUrl> {
return this.get(`case/${caseId}/limitedAccess/file/${id}/url`)
const mergedCaseInjection = mergedCaseId
? `/mergedCase/${mergedCaseId}`
: ''

return this.get(
`case/${caseId}/limitedAccess${mergedCaseInjection}/file/${id}/url`,
)
}

limitedAccessDeleteCaseFile(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Allow } from 'class-validator'
import { Allow, IsOptional } from 'class-validator'

import { Field, ID, InputType } from '@nestjs/graphql'

Expand All @@ -11,4 +11,9 @@ export class GetSignedUrlInput {
@Allow()
@Field(() => ID)
readonly caseId!: string

@Allow()
@IsOptional()
@Field(() => ID, { nullable: true })
readonly mergedCaseId?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,30 @@ export class FileController {
)
}

@Get('caseFilesRecord/:policeCaseNumber')
@Get([
gudjong marked this conversation as resolved.
Show resolved Hide resolved
'caseFilesRecord/:policeCaseNumber',
'mergedCase/:mergedCaseId/caseFilesRecord/:policeCaseNumber',
])
@Header('Content-Type', 'application/pdf')
getCaseFilesRecordPdf(
@Param('id') id: string,
@Param('mergedCaseId') mergedCaseId: string,
@Param('policeCaseNumber') policeCaseNumber: string,
@CurrentHttpUser() user: User,
@Req() req: Request,
@Res() res: Response,
): Promise<Response> {
this.logger.debug(`Getting the case files for case ${id} as a pdf document`)

const mergedCaseInjection = mergedCaseId
? `mergedCase/${mergedCaseId}/`
: ''

return this.fileService.tryGetFile(
user.id,
AuditedAction.GET_CASE_FILES_PDF,
id,
`caseFilesRecord/${policeCaseNumber}`,
`${mergedCaseInjection}caseFilesRecord/${policeCaseNumber}`,
req,
res,
'pdf',
Expand Down Expand Up @@ -143,21 +151,26 @@ export class FileController {
)
}

@Get('indictment')
@Get(['indictment', 'mergedCase/:mergedCaseId/indictment'])
@Header('Content-Type', 'application/pdf')
getIndictmentPdf(
@Param('id') id: string,
@Param('mergedCaseId') mergedCaseId: string,
@CurrentHttpUser() user: User,
@Req() req: Request,
@Res() res: Response,
): Promise<Response> {
this.logger.debug(`Getting the indictment for case ${id} as a pdf document`)

const mergedCaseInjection = mergedCaseId
? `mergedCase/${mergedCaseId}/`
: ''

return this.fileService.tryGetFile(
user.id,
AuditedAction.GET_INDICTMENT_PDF,
id,
'indictment',
`${mergedCaseInjection}indictment`,
req,
res,
'pdf',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ export class FileResolver {
@Context('dataSources')
{ backendService }: { backendService: BackendService },
): Promise<SignedUrl> {
const { caseId, id } = input
const { caseId, id, mergedCaseId } = input

this.logger.debug(`Getting a signed url for file ${id} of case ${caseId}`)

return this.auditTrailService.audit(
user.id,
AuditedAction.GET_SIGNED_URL,
backendService.getCaseFileSignedUrl(caseId, id),
backendService.getCaseFileSignedUrl(caseId, id, mergedCaseId),
id,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,30 @@ export class LimitedAccessFileController {
)
}

@Get('caseFilesRecord/:policeCaseNumber')
@Get([
'caseFilesRecord/:policeCaseNumber',
'mergedCase/:mergedCaseId/caseFilesRecord/:policeCaseNumber',
])
@Header('Content-Type', 'application/pdf')
async getCaseFilesRecordPdf(
@Param('id') id: string,
@Param('mergedCaseId') mergedCaseId: string,
@Param('policeCaseNumber') policeCaseNumber: string,
@CurrentHttpUser() user: User,
@Req() req: Request,
@Res() res: Response,
): Promise<Response> {
this.logger.debug(`Getting the case files for case ${id} as a pdf document`)

const mergedCaseInjection = mergedCaseId
? `mergedCase/${mergedCaseId}/`
: ''

return this.fileService.tryGetFile(
user.id,
AuditedAction.GET_CASE_FILES_PDF,
id,
`limitedAccess/caseFilesRecord/${policeCaseNumber}`,
`limitedAccess/${mergedCaseInjection}caseFilesRecord/${policeCaseNumber}`,
req,
res,
'pdf',
Expand Down Expand Up @@ -141,21 +149,26 @@ export class LimitedAccessFileController {
)
}

@Get('indictment')
@Get(['indictment', 'mergedCase/:mergedCaseId/indictment'])
@Header('Content-Type', 'application/pdf')
async getIndictmentPdf(
@Param('id') id: string,
@Param('mergedCaseId') mergedCaseId: string,
@CurrentHttpUser() user: User,
@Req() req: Request,
@Res() res: Response,
): Promise<Response> {
this.logger.debug(`Getting the indictment for case ${id} as a pdf document`)

const mergedCaseInjection = mergedCaseId
? `mergedCase/${mergedCaseId}/`
: ''

return this.fileService.tryGetFile(
user.id,
AuditedAction.GET_INDICTMENT_PDF,
id,
'limitedAccess/indictment',
`limitedAccess/${mergedCaseInjection}indictment`,
req,
res,
'pdf',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,18 @@ export class LimitedAccessFileResolver {
@Context('dataSources')
{ backendService }: { backendService: BackendService },
): Promise<SignedUrl> {
const { caseId, id } = input
const { caseId, id, mergedCaseId } = input

this.logger.debug(`Getting a signed url for file ${id} of case ${caseId}`)

return this.auditTrailService.audit(
user.id,
AuditedAction.GET_SIGNED_URL,
backendService.limitedAccessGetCaseFileSignedUrl(caseId, id),
backendService.limitedAccessGetCaseFileSignedUrl(
caseId,
id,
mergedCaseId,
),
id,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import { CaseExistsGuard } from './guards/caseExists.guard'
import { CaseReadGuard } from './guards/caseRead.guard'
import { CaseTypeGuard } from './guards/caseType.guard'
import { CaseWriteGuard } from './guards/caseWrite.guard'
import { MergedCaseExistsGuard } from './guards/mergedCaseExists.guard'
import {
courtOfAppealsAssistantTransitionRule,
courtOfAppealsAssistantUpdateRule,
Expand Down Expand Up @@ -549,6 +550,7 @@ export class CaseController {
CaseExistsGuard,
new CaseTypeGuard(indictmentCases),
CaseReadGuard,
MergedCaseExistsGuard,
)
@RolesRules(
prosecutorRule,
Expand All @@ -558,7 +560,10 @@ export class CaseController {
districtCourtRegistrarRule,
districtCourtAssistantRule,
)
@Get('case/:caseId/caseFilesRecord/:policeCaseNumber')
@Get([
'case/:caseId/caseFilesRecord/:policeCaseNumber',
'case/:caseId/mergedCase/:mergedCaseId/caseFilesRecord/:policeCaseNumber',
])
@ApiOkResponse({
content: { 'application/pdf': {} },
description:
Expand Down Expand Up @@ -705,6 +710,7 @@ export class CaseController {
CaseExistsGuard,
new CaseTypeGuard(indictmentCases),
CaseReadGuard,
MergedCaseExistsGuard,
)
@RolesRules(
prosecutorRule,
Expand All @@ -714,7 +720,10 @@ export class CaseController {
districtCourtRegistrarRule,
districtCourtAssistantRule,
)
@Get('case/:caseId/indictment')
@Get([
'case/:caseId/indictment',
'case/:caseId/mergedCase/:mergedCaseId/indictment',
])
@Header('Content-Type', 'application/pdf')
@ApiOkResponse({
content: { 'application/pdf': {} },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ export const include: Includeable[] = [
CaseFileCategory.CRIMINAL_RECORD,
CaseFileCategory.COST_BREAKDOWN,
CaseFileCategory.CRIMINAL_RECORD_UPDATE,
CaseFileCategory.CASE_FILE,
CaseFileCategory.PROSECUTOR_CASE_FILE,
CaseFileCategory.DEFENDANT_CASE_FILE,
CaseFileCategory.CIVIL_CLAIM,
],
},
},
Expand Down Expand Up @@ -386,14 +390,13 @@ export const caseListInclude: Includeable[] = [
as: 'eventLogs',
required: false,
where: { eventType: { [Op.in]: eventTypes } },
order: [['created', 'DESC']],
separate: true,
},
]

export const listOrder: OrderItem[] = [
[{ model: Defendant, as: 'defendants' }, 'created', 'ASC'],
[{ model: DateLog, as: 'dateLogs' }, 'created', 'DESC'],
[{ model: EventLog, as: 'eventLogs' }, 'created', 'DESC'],
]

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
CaseIndictmentRulingDecision,
CaseState,
CaseType,
EventType,
getIndictmentVerdictAppealDeadlineStatus,
IndictmentCaseReviewDecision,
isCourtOfAppealsUser,
Expand Down Expand Up @@ -87,6 +88,27 @@ const canPublicProsecutionUserAccessCase = (theCase: Case): boolean => {
return false
}

// Check indictment ruling decision access
if (
!theCase.indictmentRulingDecision ||
![
CaseIndictmentRulingDecision.FINE,
CaseIndictmentRulingDecision.RULING,
].includes(theCase.indictmentRulingDecision)
) {
return false
}

// Make sure the indictment has been sent to the public prosecutor
if (
!theCase.eventLogs?.some(
(eventLog) =>
eventLog.eventType === EventType.INDICTMENT_SENT_TO_PUBLIC_PROSECUTOR,
)
) {
return false
}

return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CaseState,
CaseType,
DateType,
EventType,
IndictmentCaseReviewDecision,
indictmentCases,
investigationCases,
Expand Down Expand Up @@ -75,8 +76,20 @@ const getPublicProsecutionUserCasesQueryFilter = (): WhereOptions => {
return {
[Op.and]: [
{ is_archived: false },
{ state: [CaseState.COMPLETED] },
{ type: indictmentCases },
{ state: CaseState.COMPLETED },
{
indictment_ruling_decision: [
CaseIndictmentRulingDecision.FINE,
CaseIndictmentRulingDecision.RULING,
],
},
{
// The following condition will filter out all event logs that are not of type INDICTMENT_SENT_TO_PUBLIC_PROSECUTOR
// but that should be ok the case list for the public prosecutor is not using other event logs
'$eventLogs.event_type$':
EventType.INDICTMENT_SENT_TO_PUBLIC_PROSECUTOR,
},
],
}
}
Expand Down Expand Up @@ -190,15 +203,10 @@ const getPrisonAdminUserCasesQueryFilter = (): WhereOptions => {
[Op.or]: [
{
state: CaseState.ACCEPTED,
type: [
CaseType.CUSTODY,
CaseType.ADMISSION_TO_FACILITY,
CaseType.PAROLE_REVOCATION,
CaseType.TRAVEL_BAN,
],
type: [...restrictionCases, CaseType.PAROLE_REVOCATION],
},
{
type: CaseType.INDICTMENT,
type: indictmentCases,
state: CaseState.COMPLETED,
indictment_ruling_decision: CaseIndictmentRulingDecision.RULING,
indictment_review_decision: IndictmentCaseReviewDecision.ACCEPT,
Expand Down
Loading
Loading