Skip to content

Commit

Permalink
Merge branch 'main' of github.com:island-is/island.is into j-s/defend…
Browse files Browse the repository at this point in the history
…er-to-court
  • Loading branch information
gudjong committed Nov 19, 2024
2 parents 8ba25ac + b90bbfa commit caaee74
Show file tree
Hide file tree
Showing 363 changed files with 9,493 additions and 3,087 deletions.
8 changes: 6 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ codemagic.yaml
/apps/portals/my-pages*/ @island-is/hugsmidjan
/apps/services/regulations-admin-backend/ @island-is/hugsmidjan
/apps/services/user-profile/ @island-is/hugsmidjan @island-is/juni @island-is/aranja
/apps/web/components/Grant/ @island-is/hugsmidjan
/apps/web/components/PlazaCard/ @island-is/hugsmidjan
/apps/web/screens/Grants/ @island-is/hugsmidjan
/apps/web/screens/Regulations/ @island-is/hugsmidjan
/apps/web/components/Regulations/ @island-is/hugsmidjan
/apps/web/screens/OfficialJournalOfIceland/ @island-is/hugsmidjan
Expand Down Expand Up @@ -195,7 +198,8 @@ codemagic.yaml
/libs/portals/admin/regulations-admin/ @island-is/hugsmidjan
/libs/portals/admin/document-provider/ @island-is/hugsmidjan @island-is/core
/libs/clients/icelandic-health-insurance/rights-portal/ @island-is/hugsmidjan
/libs/clients/health-directorate @island-is/hugsmidjan @island-is/origo
/libs/clients/health-directorate @island-is/hugsmidjan
/libs/clients/health-directorate/src/lib/clients/occupational-license @island-is/hugsmidjan @island-is/origo
/libs/clients/mms/grade @island-is/hugsmidjan
/libs/portals/admin/air-discount-scheme @island-is/hugsmidjan
/libs/application/templates/official-journal-of-iceland/ @island-is/hugsmidjan
Expand Down Expand Up @@ -389,7 +393,7 @@ codemagic.yaml

# QA
/apps/system-e2e/ @island-is/qa
/libs/testing/e2e @island-is/qa
/libs/testing/e2e @island-is/qa

# Islandis
/apps/system-e2e/src/tests/islandis/admin-portal/ @island-is/aranja
Expand Down
36 changes: 36 additions & 0 deletions apps/judicial-system/backend/src/app/formatters/formatters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@island.is/judicial-system/types'

import {
filterWhitelistEmails,
formatCourtHeadsUpSmsNotification,
formatCourtReadyForCourtSmsNotification,
formatCourtResubmittedToCourtSmsNotification,
Expand Down Expand Up @@ -1982,3 +1983,38 @@ describe('formatDefenderResubmittedToCourtEmailNotification', () => {
expect(result.subject).toEqual('Krafa í máli R-2022/999')
})
})

describe('filterWhitelistEmails', () => {
const emails = [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
]

it('should return only whitelisted emails', () => {
const whitelist = `${emails[0]}, ${emails[2]}`
const domainWhitelist = 'example.com'

const result = filterWhitelistEmails(emails, domainWhitelist, whitelist)

expect(result).toEqual([emails[0], emails[2], emails[3]])
})

it('should return empty array if no emails are whitelisted', () => {
const whitelist = ''
const domainWhitelist = ''

const result = filterWhitelistEmails(emails, domainWhitelist, whitelist)

expect(result).toEqual([])
})
it('should return domain whitelisted emails', () => {
const whitelist = ''
const domainWhitelist = 'rvg.is'

const result = filterWhitelistEmails(emails, domainWhitelist, whitelist)

expect(result).toEqual([emails[0], emails[1], emails[2]])
})
})
71 changes: 28 additions & 43 deletions apps/judicial-system/backend/src/app/formatters/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,49 +668,6 @@ export const formatCustodyRestrictions = (
})
}

export const formatAdvocateAssignedEmailNotification = (
formatMessage: FormatMessage,
theCase: Case,
advocateType: AdvocateType,
overviewUrl?: string,
): SubjectAndBody => {
const subject =
advocateType === AdvocateType.DEFENDER
? formatMessage(
notifications.advocateAssignedEmail.subjectAccessToCaseFiles,
{
court: capitalize(theCase.court?.name ?? ''),
},
)
: formatMessage(notifications.advocateAssignedEmail.subjectAccess, {
courtCaseNumber: theCase.courtCaseNumber,
})

const body =
advocateType === AdvocateType.DEFENDER
? formatMessage(
notifications.advocateAssignedEmail.bodyAccessToCaseFiles,
{
defenderHasAccessToRVG: Boolean(overviewUrl),
courtCaseNumber: capitalize(theCase.courtCaseNumber ?? ''),
court: theCase.court?.name ?? '',
courtName: theCase.court?.name.replace('dómur', 'dómi') ?? '',
linkStart: `<a href="${overviewUrl}">`,
linkEnd: '</a>',
},
)
: formatMessage(notifications.advocateAssignedEmail.bodyAccess, {
defenderHasAccessToRVG: Boolean(overviewUrl),
court: theCase.court?.name,
advocateType,
courtCaseNumber: capitalize(theCase.courtCaseNumber ?? ''),
linkStart: `<a href="${overviewUrl}">`,
linkEnd: '</a>',
})

return { body, subject }
}

export const formatCourtOfAppealJudgeAssignedEmailNotification = (
formatMessage: FormatMessage,
caseNumber: string,
Expand Down Expand Up @@ -802,3 +759,31 @@ export const formatDefenderRoute = (

export const formatConfirmedIndictmentKey = (key?: string) =>
key?.replace(/\/([^/]*)$/, '/confirmed/$1') ?? ''

export const filterWhitelistEmails = (
emails: string[],
domainWhitelist: string,
emailWhitelist: string,
) => {
if (!emails || emails.length === 0) return []

const allowedDomains = new Set(
domainWhitelist
.split(',')
.map((d) => d.trim())
.filter(Boolean),
)
const allowedEmails = new Set(
emailWhitelist
.split(',')
.map((e) => e.trim())
.filter(Boolean),
)

return emails.filter((email) => {
const domain = email.split('@')[1]
return (
domain && (allowedDomains.has(domain) || allowedEmails.has(email.trim()))
)
})
}
2 changes: 1 addition & 1 deletion apps/judicial-system/backend/src/app/formatters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export {
formatProsecutorReceivedByCourtSmsNotification,
formatDefenderCourtDateLinkEmailNotification,
formatDefenderResubmittedToCourtEmailNotification,
formatAdvocateAssignedEmailNotification,
formatCourtIndictmentReadyForCourtEmailNotification,
formatDefenderRoute,
formatDefenderReadyForCourtEmailNotification,
formatCourtOfAppealJudgeAssignedEmailNotification,
formatPostponedCourtDateEmailNotification,
stripHtmlTags,
filterWhitelistEmails,
} from './formatters'
export { Confirmation } from './pdfHelpers'
export { getRequestPdfAsBuffer, getRequestPdfAsString } from './requestPdf'
Expand Down
36 changes: 10 additions & 26 deletions apps/judicial-system/backend/src/app/messages/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ export const notifications = {
'Hægt er að nálgast yfirlitssíðu málsins á <a href="https://rettarvorslugatt.island.is">rettarvorslugatt.island.is</a>.',
description: 'Notaður sem texti í email til þess að tilgreina slóð á RVG',
}),
emailWhitelist: defineMessage({
id: 'judicial.system.backend:notifications.email_whitelist',
defaultMessage: '',
description: 'Notað til að tilgreina hvort póstfang sé í hvítlista',
}),
emailWhitelistDomains: defineMessage({
id: 'judicial.system.backend:notifications.email_whitelist_domains',
defaultMessage: 'omnitrix.is,kolibri.is',
description: 'Notað til að tilgreina hvort póstfang sé í hvítlista',
}),
readyForCourt: defineMessages({
subject: {
id: 'judicial.system.backend:notifications.ready_for_court.subjectV2',
Expand Down Expand Up @@ -607,32 +617,6 @@ export const notifications = {
'Notaður sem texti í tölvupósti til verjanda vegna breytingar á lengd gæslu/einangrunar/vistunar þar sem úrskurðað var í einangrun.',
},
}),
advocateAssignedEmail: defineMessages({
subjectAccessToCaseFiles: {
id: 'judicial.system.backend:notifications.defender_assigned_email.subject_access_to_case_files',
defaultMessage: '{court} - aðgangur að málsgögnum',
description:
'Fyrirsögn í pósti til verjanda þegar hann er skráður á mál.',
},
subjectAccess: {
id: 'judicial.system.backend:notifications.defender_assigned_email.subject_access',
defaultMessage: 'Skráning í máli {courtCaseNumber}',
description:
'Fyrirsögn í pósti til verjanda þegar hann er skráður á mál.',
},
bodyAccessToCaseFiles: {
id: 'judicial.system.backend:notifications.defender_assigned_email.body_access_to_case_files',
defaultMessage:
'{court} hefur skráð þig verjanda í máli {courtCaseNumber}.<br /><br />{defenderHasAccessToRVG, select, true {Gögn málsins eru aðgengileg á {linkStart}yfirlitssíðu málsins í Réttarvörslugátt{linkEnd}} other {Þú getur nálgast gögn málsins hjá {courtName} ef þau hafa ekki þegar verið afhent}}.',
description: 'Texti í pósti til verjanda þegar hann er skráður á mál.',
},
bodyAccess: {
id: 'judicial.system.backend:notifications.defender_assigned_email.body_access',
defaultMessage:
'{court} hefur skráð þig {advocateType, select, LAWYER {lögmann einkaréttarkröfuhafa} LEGAL_RIGHTS_PROTECTOR {réttargæslumann einkaréttarkröfuhafa} other {verjanda}} í máli {courtCaseNumber}.<br /><br />{defenderHasAccessToRVG, select, true {Sjá nánar á {linkStart}yfirlitssíðu málsins í Réttarvörslugátt{linkEnd}} other {Þú getur nálgast málið hjá {courtName}.}}.',
description: 'Texti í pósti til verjanda þegar hann er skráður á mál.',
},
}),
defendantsNotUpdatedAtCourt: defineMessages({
subject: {
id: 'judicial.system.backend:notifications.defendants_not_updated_at_court.subject',
Expand Down
12 changes: 12 additions & 0 deletions apps/judicial-system/backend/src/app/modules/case/case.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2034,11 +2034,23 @@ export class CaseService {
}

async createCourtCase(theCase: Case, user: TUser): Promise<Case> {
let receivalDate: Date

if (isIndictmentCase(theCase.type)) {
receivalDate =
theCase.eventLogs?.find(
(eventLog) => eventLog.eventType === EventType.INDICTMENT_CONFIRMED,
)?.created ?? nowFactory()
} else {
receivalDate = nowFactory()
}

const courtCaseNumber = await this.courtService.createCourtCase(
user,
theCase.id,
theCase.courtId,
theCase.type,
receivalDate,
theCase.policeCaseNumbers,
Boolean(theCase.parentCaseId),
theCase.indictmentSubtypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IsObject,
IsOptional,
IsString,
MaxLength,
} from 'class-validator'

import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'
Expand All @@ -31,33 +32,39 @@ export class CreateCaseDto {
readonly indictmentSubtypes?: IndictmentSubtypeMap

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly description?: string

@IsNotEmpty()
@IsArray()
@ArrayMinSize(1)
@MaxLength(255, { each: true })
@IsString({ each: true })
@ApiProperty({ type: String, isArray: true })
readonly policeCaseNumbers!: string[]

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly defenderName?: string

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly defenderNationalId?: string

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly defenderEmail?: string

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly defenderPhoneNumber?: string
Expand All @@ -68,6 +75,7 @@ export class CreateCaseDto {
readonly requestSharedWithDefender?: RequestSharedWithDefender

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly leadInvestigator?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
IsOptional,
IsString,
IsUUID,
MaxLength,
ValidateNested,
} from 'class-validator'

Expand Down Expand Up @@ -43,6 +44,7 @@ class UpdateDateLog {
readonly date?: Date

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly location?: string
Expand All @@ -60,33 +62,39 @@ export class UpdateCaseDto {
readonly indictmentSubtypes?: IndictmentSubtypeMap

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly description?: string

@IsOptional()
@IsArray()
@ArrayMinSize(1)
@MaxLength(255, { each: true })
@IsString({ each: true })
@ApiPropertyOptional({ type: String, isArray: true })
readonly policeCaseNumbers?: string[]

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly defenderName?: string

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly defenderNationalId?: string

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly defenderEmail?: string

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly defenderPhoneNumber?: string
Expand All @@ -107,6 +115,7 @@ export class UpdateCaseDto {
readonly courtId?: string

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly leadInvestigator?: string
Expand All @@ -124,6 +133,7 @@ export class UpdateCaseDto {
readonly requestedCourtDate?: Date

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly translator?: string
Expand Down Expand Up @@ -207,6 +217,7 @@ export class UpdateCaseDto {
readonly sharedWithProsecutorsOfficeId?: string

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly courtCaseNumber?: string
Expand All @@ -229,6 +240,7 @@ export class UpdateCaseDto {
readonly courtDate?: UpdateDateLog

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly courtLocation?: string
Expand Down Expand Up @@ -407,6 +419,7 @@ export class UpdateCaseDto {
readonly defendantStatementDate?: Date

@IsOptional()
@MaxLength(255)
@IsString()
@ApiPropertyOptional({ type: String })
readonly appealCaseNumber?: string
Expand Down
Loading

0 comments on commit caaee74

Please sign in to comment.