Skip to content

Commit

Permalink
Merge branch 'j-s/civil-claimant-courts' of https://github.com/island…
Browse files Browse the repository at this point in the history
…-is/island.is into j-s/civil-claimant-courts
  • Loading branch information
unakb committed Sep 26, 2024
2 parents 1a358c8 + f4d8eaa commit 5ccdc51
Show file tree
Hide file tree
Showing 150 changed files with 3,705 additions and 1,028 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,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 @@ -426,8 +434,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
}
21 changes: 17 additions & 4 deletions apps/judicial-system/api/src/app/modules/file/file.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,30 @@ export class FileController {
)
}

@Get('caseFilesRecord/:policeCaseNumber')
@Get([
'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 @@ -53,22 +53,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 @@ -142,21 +150,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 @@ -321,6 +321,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 @@ -388,14 +392,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

0 comments on commit 5ccdc51

Please sign in to comment.