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

feat(j-s): Subpoena PDF #16098

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -6,6 +6,7 @@ import {
Header,
Inject,
Param,
Query,
Req,
Res,
UseGuards,
Expand All @@ -19,7 +20,7 @@ import {
CurrentHttpUser,
JwtInjectBearerAuthGuard,
} from '@island.is/judicial-system/auth'
import type { User } from '@island.is/judicial-system/types'
import type { SubpoenaType, User } from '@island.is/judicial-system/types'

import { FileService } from './file.service'

Expand Down Expand Up @@ -162,6 +163,33 @@ export class LimitedAccessFileController {
)
}

@Get('subpoena/:defendantId')
@Header('Content-Type', 'application/pdf')
getSubpoenaPdf(
@Param('id') id: string,
@Param('defendantId') defendantId: string,
@Query('arraignmentDate') arraignmentDate: string,
@Query('location') location: string,
@Query('subpoenaType') subpoenaType: SubpoenaType,
@CurrentHttpUser() user: User,
@Req() req: Request,
@Res() res: Response,
): Promise<Response> {
this.logger.debug(
`Getting the subpoena for defendant ${defendantId} of case ${id} as a pdf document`,
)

return this.fileService.tryGetFile(
user.id,
AuditedAction.GET_SUBPOENA_PDF,
id,
`limitedAccess/defendant/${defendantId}/subpoena?arraignmentDate=${arraignmentDate}&location=${location}&subpoenaType=${subpoenaType}`,
gudjong marked this conversation as resolved.
Show resolved Hide resolved
req,
res,
'pdf',
)
}

@Get('allFiles')
@Header('Content-Type', 'application/zip')
async getAllFiles(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export class LimitedAccessCaseController {
private readonly limitedAccessCaseService: LimitedAccessCaseService,
private readonly eventService: EventService,
private readonly pdfService: PdfService,

@Inject(LOGGER_PROVIDER) private readonly logger: Logger,
) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ export class DefendantController {
DefendantExistsGuard,
)
@RolesRules(
prosecutorRule,
prosecutorRepresentativeRule,
publicProsecutorStaffRule,
districtCourtJudgeRule,
districtCourtRegistrarRule,
districtCourtAssistantRule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { CivilClaimantService } from './civilClaimant.service'
import { DefendantController } from './defendant.controller'
import { DefendantService } from './defendant.service'
import { InternalDefendantController } from './internalDefendant.controller'
import { LimitedAccessDefendantController } from './limitedAccessDefendant.controller'

@Module({
imports: [
Expand All @@ -23,6 +24,7 @@ import { InternalDefendantController } from './internalDefendant.controller'
controllers: [
DefendantController,
InternalDefendantController,
LimitedAccessDefendantController,
CivilClaimantController,
],
providers: [DefendantService, CivilClaimantService],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Response } from 'express'

import {
Controller,
Get,
Header,
Inject,
Param,
Query,
Res,
UseGuards,
} from '@nestjs/common'
import { ApiOkResponse, ApiTags } from '@nestjs/swagger'

import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'

import {
JwtAuthGuard,
RolesGuard,
RolesRules,
} from '@island.is/judicial-system/auth'
import { indictmentCases, SubpoenaType } from '@island.is/judicial-system/types'

import { defenderRule } from '../../guards'
import {
Case,
CaseExistsGuard,
CaseReadGuard,
CaseTypeGuard,
CurrentCase,
PdfService,
} from '../case'
import { CurrentDefendant } from './guards/defendant.decorator'
import { DefendantExistsGuard } from './guards/defendantExists.guard'
import { Defendant } from './models/defendant.model'

@Controller('api/case/:caseId/limitedAccess/defendant/:defendantId/subpoena')
@UseGuards(
JwtAuthGuard,
RolesGuard,
CaseExistsGuard,
new CaseTypeGuard(indictmentCases),
CaseReadGuard,
DefendantExistsGuard,
)
@ApiTags('limited access defendants')
export class LimitedAccessDefendantController {
constructor(
private readonly pdfService: PdfService,
@Inject(LOGGER_PROVIDER) private readonly logger: Logger,
) {}

@RolesRules(defenderRule)
@Get()
@Header('Content-Type', 'application/pdf')
@ApiOkResponse({
content: { 'application/pdf': {} },
description: 'Gets the subpoena for a given defendant as a pdf document',
})
async getSubpoenaPdf(
@Param('caseId') caseId: string,
@Param('defendantId') defendantId: string,
@CurrentCase() theCase: Case,
@CurrentDefendant() defendant: Defendant,
@Res() res: Response,
@Query('arraignmentDate') arraignmentDate?: Date,
@Query('location') location?: string,
@Query('subpoenaType') subpoenaType?: SubpoenaType,
gudjong marked this conversation as resolved.
Show resolved Hide resolved
): Promise<void> {
this.logger.debug(
`Getting the subpoena for defendant ${defendantId} of case ${caseId} as a pdf document`,
)

const pdf = await this.pdfService.getSubpoenaPdf(
theCase,
defendant,
arraignmentDate,
location,
subpoenaType,
)

res.end(pdf)
gudjong marked this conversation as resolved.
Show resolved Hide resolved
}
gudjong marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ export const strings = defineMessages({
description:
'Notaður sem titill á innsend gögn hluta á dómskjalaskjá í ákærum.',
},
subpoenaTitle: {
id: 'judicial.system.core:court.indictment_case_files_list.subpoena_title',
defaultMessage: 'Fyrirkall',
description:
'Notaður sem titill á firyrkall hluta á dómskjalaskjá í ákærum.',
},
subpoenaButtonText: {
id: 'judicial.system.indictments:indictment_case_files_list.subpoena_button_text',
defaultMessage: 'Fyrirkall {name}.pdf',
description:
'Notaður sem texti á PDF takka til að sækja firyrkall í ákærum.',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const IndictmentCaseFilesList: FC<Props> = ({
})

const showTrafficViolationCaseFiles = isTrafficViolationCase(workingCase)
const showSubpoenaPdf = workingCase.arraignmentDate

const cf = workingCase.caseFiles

Expand Down Expand Up @@ -254,6 +255,28 @@ const IndictmentCaseFilesList: FC<Props> = ({
<CaseFileTable caseFiles={uploadedCaseFiles} onOpenFile={onOpen} />
</Box>
)}
{showSubpoenaPdf &&
workingCase.defendants &&
workingCase.defendants.length > 0 && (
<Box marginBottom={5}>
<Text variant="h4" as="h4" marginBottom={1}>
{formatMessage(strings.subpoenaTitle)}
</Text>
{workingCase.defendants.map((defendant) => (
<Box marginBottom={2} key={`subpoena-${workingCase.id}`}>
gudjong marked this conversation as resolved.
Show resolved Hide resolved
<PdfButton
caseId={workingCase.id}
title={formatMessage(strings.subpoenaButtonText, {
name: defendant.name,
})}
pdfType="subpoena"
elementId={defendant.id}
renderAs="row"
/>
</Box>
))}
</Box>
)}
<AnimatePresence>
{fileNotFound && <FileNotFoundModal dismiss={dismissFileNotFound} />}
</AnimatePresence>
Expand Down