Skip to content

Commit

Permalink
Merge branch 'main' into fix/admin-paper-signature-upload
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Oct 22, 2024
2 parents e752254 + 11b480a commit 80cfb07
Show file tree
Hide file tree
Showing 45 changed files with 831 additions and 242 deletions.
39 changes: 23 additions & 16 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
#!/bin/bash

source_env .env.secret
declare -A TIME_KEEP
# t <target> - get elapsed time in milliseconds since first invocation (with nanosecond precision)
t() {
if [[ -v TIME_KEEP[$1] ]]; then
D="$(date +%N)"
echo "$(((${D##0} - ${TIME_KEEP[$1]##0}) / 1000000))"
else
TIME_KEEP[$1]=$(date +%N)
fi
}
set -euo pipefail
t root

# global

export NODE_OPTIONS="--max-old-space-size=8192"

# MacOS specific

export REDIS_CLUSTER_IP=0.0.0.0

# developer custom direnv config

source_env_if_exists .envrc.private
if [[ "${IS_DEVCONTAINER:-}" == true ]]; then
source_env_if_exists .devcontainer/.envrc.private
fi

# Podman compatibility
# NOTE: Exits direnv if user is using docker.
source_env_if_exists .envrc.podman

source_env_if_exists .envrc.kube
# Developer custom direnv config
for envrc in .envrc.* $(if [[ "${IS_DEVCONTAINER:-}" == true ]]; then echo .devcontainer/.envrc.private; fi); do
t "${envrc}"
source_env_if_exists "$envrc"
T_TOTAL=$(t "${envrc}")
if ((T_TOTAL > 100)); then
echo -e "\033[93mSetting '$envrc' took ${T_TOTAL}ms\033[0m"
fi
done

echo "Loading .envrc took $(t root)ms"
27 changes: 26 additions & 1 deletion apps/judicial-system/api/src/app/modules/file/file.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,32 @@ export class FileController {
)
}

@Get(['subpoena/:defendantId', 'subpoena/:defendantId/:subpoenaId'])
@Get('serviceCertificate/:defendantId/:subpoenaId')
@Header('Content-Type', 'application/pdf')
getServiceCertificatePdf(
@Param('id') id: string,
@Param('defendantId') defendantId: string,
@CurrentHttpUser() user: User,
@Req() req: Request,
@Res() res: Response,
@Param('subpoenaId') subpoenaId?: string,
): Promise<Response> {
this.logger.debug(
`Getting service certificate for defendant ${defendantId} of case ${id} as a pdf document`,
)

return this.fileService.tryGetFile(
user.id,
AuditedAction.GET_SERVICE_CERTIFICATE_PDF,
id,
`defendant/${defendantId}/subpoena/${subpoenaId}/serviceCertificate`,
req,
res,
'pdf',
)
}

@Get('subpoena/:defendantId')
@Header('Content-Type', 'application/pdf')
getSubpoenaPdf(
@Param('id') id: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Header,
Inject,
Param,
Query,
Req,
Res,
UseGuards,
Expand All @@ -20,7 +19,7 @@ import {
CurrentHttpUser,
JwtInjectBearerAuthGuard,
} from '@island.is/judicial-system/auth'
import type { SubpoenaType, User } from '@island.is/judicial-system/types'
import type { User } from '@island.is/judicial-system/types'

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

Expand Down Expand Up @@ -201,6 +200,31 @@ export class LimitedAccessFileController {
)
}

@Get('serviceCertificate/:defendantId/:subpoenaId')
@Header('Content-Type', 'application/pdf')
getServiceCertificatePdf(
@Param('id') id: string,
@Param('defendantId') defendantId: string,
@CurrentHttpUser() user: User,
@Req() req: Request,
@Res() res: Response,
@Param('subpoenaId') subpoenaId?: string,
): Promise<Response> {
this.logger.debug(
`Getting service certificate for defendant ${defendantId} of case ${id} as a pdf document`,
)

return this.fileService.tryGetFile(
user.id,
AuditedAction.GET_SERVICE_CERTIFICATE_PDF,
id,
`limitedAccess/defendant/${defendantId}/subpoena/${subpoenaId}/serviceCertificate`,
req,
res,
'pdf',
)
}

@Get('allFiles')
@Header('Content-Type', 'application/zip')
async getAllFiles(
Expand Down
1 change: 1 addition & 0 deletions apps/judicial-system/backend/src/app/formatters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ export { createCaseFilesRecord } from './caseFilesRecordPdf'
export { createIndictment } from './indictmentPdf'
export { createConfirmedPdf } from './confirmedPdf'
export { createSubpoena } from './subpoenaPdf'
export { createServiceCertificate } from './serviceCertificatePdf'
8 changes: 8 additions & 0 deletions apps/judicial-system/backend/src/app/formatters/pdfHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ export const addMediumText = (
addText(doc, mediumFontSize, text, font)
}

export const addMediumCenteredText = (
doc: PDFKit.PDFDocument,
text: string,
font?: string,
) => {
addAlignedText(doc, mediumFontSize, text, 'center', font)
}

export const addNormalPlusText = (
doc: PDFKit.PDFDocument,
text: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import PDFDocument from 'pdfkit'

import { FormatMessage } from '@island.is/cms-translations'

import {
capitalize,
formatDate,
formatDOB,
getWordByGender,
Word,
} from '@island.is/judicial-system/formatters'
import { ServiceStatus, SubpoenaType } from '@island.is/judicial-system/types'

import { serviceCertificate as strings } from '../messages'
import { Case } from '../modules/case'
import { Defendant } from '../modules/defendant'
import { Subpoena } from '../modules/subpoena'
import {
addEmptyLines,
addFooter,
addHugeHeading,
addMediumCenteredText,
addNormalCenteredText,
addNormalText,
setTitle,
} from './pdfHelpers'

const getSubpoenaType = (subpoenaType?: SubpoenaType): string => {
switch (subpoenaType) {
case SubpoenaType.ABSENCE:
return 'Útivistarfyrirkall'
case SubpoenaType.ARREST:
return 'Handtökufyrirkall'
default:
// Should never happen
return 'Ekki skráð'
}
}

export const createServiceCertificate = (
theCase: Case,
defendant: Defendant,
subpoena: Subpoena,
formatMessage: FormatMessage,
): Promise<Buffer> => {
const doc = new PDFDocument({
size: 'A4',
margins: {
top: 40,
bottom: 60,
left: 50,
right: 50,
},
bufferPages: true,
})

const sinc: Buffer[] = []

doc.on('data', (chunk) => sinc.push(chunk))

setTitle(doc, formatMessage(strings.title))

addHugeHeading(doc, formatMessage(strings.title).toUpperCase(), 'Times-Bold')
addMediumCenteredText(
doc,
`Mál nr. ${theCase.courtCaseNumber || ''}`,
'Times-Bold',
)
addNormalCenteredText(doc, theCase.court?.name || '', 'Times-Bold')

addEmptyLines(doc, 2)

addMediumCenteredText(
doc,
`Birting tókst ${
subpoena.serviceDate ? formatDate(subpoena.serviceDate, 'PPp') : ''
}`,
'Times-Bold',
)

addEmptyLines(doc)

addNormalText(doc, 'Birtingaraðili: ', 'Times-Bold', true)
addNormalText(
doc,
subpoena.serviceStatus === ServiceStatus.ELECTRONICALLY
? 'Rafrænt pósthólf island.is'
: subpoena.servedBy || '',
'Times-Roman',
)

if (subpoena.serviceStatus !== ServiceStatus.ELECTRONICALLY) {
addNormalText(doc, 'Athugasemd: ', 'Times-Bold', true)
addNormalText(
doc,
subpoena.serviceStatus === ServiceStatus.DEFENDER
? `Birt fyrir verjanda ${
defendant.defenderName ? `- ${defendant.defenderName}` : ''
}`
: subpoena.comment || '',
'Times-Roman',
)
}

addEmptyLines(doc, 2)

addNormalText(
doc,
`${capitalize(getWordByGender(Word.AKAERDI, defendant.gender))}: `,
'Times-Bold',
true,
)
addNormalText(
doc,
defendant.name && defendant.nationalId && defendant.address
? `${defendant.name}, ${formatDOB(
defendant.nationalId,
defendant.noNationalId,
)}, ${defendant.address}`
: 'Ekki skráður',
'Times-Roman',
)

addEmptyLines(doc, 2)

addNormalText(doc, 'Ákærandi: ', 'Times-Bold', true)
addNormalText(
doc,
theCase.prosecutor?.institution
? theCase.prosecutor.institution.name
: 'Ekki skráður',
'Times-Roman',
)

addNormalText(doc, 'Dómari: ', 'Times-Bold', true)
addNormalText(
doc,
theCase.judge ? theCase.judge.name : 'Ekki skráður',
'Times-Roman',
)

addEmptyLines(doc)

addNormalText(doc, 'Þingfesting: ', 'Times-Bold', true)
addNormalText(
doc,
formatDate(
subpoena.arraignmentDate ? new Date(subpoena.arraignmentDate) : null,
'Pp',
) || 'Ekki skráð',
'Times-Roman',
)

addNormalText(doc, 'Staður: ', 'Times-Bold', true)
addNormalText(doc, subpoena.location || 'Ekki skráður', 'Times-Roman')

addNormalText(doc, 'Tegund fyrirkalls: ', 'Times-Bold', true)
addNormalText(doc, getSubpoenaType(defendant.subpoenaType), 'Times-Roman')

addFooter(doc)
doc.end()

return new Promise<Buffer>((resolve) =>
doc.on('end', () => resolve(Buffer.concat(sinc))),
)
}
1 change: 1 addition & 0 deletions apps/judicial-system/backend/src/app/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export { courtUpload } from './courtUpload'
export { caseFilesRecord } from './pdfCaseFilesRecord'
export { indictment } from './pdfIndictment'
export { subpoena } from './pdfSubpoena'
export { serviceCertificate } from './pdfServiceCertificate'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineMessage } from '@formatjs/intl'

export const serviceCertificate = {
title: defineMessage({
id: 'judicial.system.backend:pdf.service_certificate.title',
defaultMessage: 'Birtingarvottorð',
description: 'Notaður sem titill á birtingarvottorði.',
}),
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ export const defenderGeneratedPdfRule: RolesRule = {
const user: User = request.user
const theCase: Case = request.case

// Deny if something is missing - shuould never happen
// Deny if something is missing - should never happen
if (!user || !theCase) {
return false
}
Expand Down
18 changes: 18 additions & 0 deletions apps/judicial-system/backend/src/app/modules/case/pdf.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
Confirmation,
createCaseFilesRecord,
createIndictment,
createServiceCertificate,
createSubpoena,
getCourtRecordPdfAsBuffer,
getCustodyNoticePdfAsBuffer,
Expand Down Expand Up @@ -355,4 +356,21 @@ export class PdfService {

return generatedPdf
}

async getServiceCertificatePdf(
theCase: Case,
defendant: Defendant,
subpoena: Subpoena,
): Promise<Buffer> {
await this.refreshFormatMessage()

const generatedPdf = await createServiceCertificate(
theCase,
defendant,
subpoena,
this.formatMessage,
)

return generatedPdf
}
}
Loading

0 comments on commit 80cfb07

Please sign in to comment.