Skip to content

Commit

Permalink
Merge branch 'main' into my-pages/notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
disaerna authored Nov 21, 2024
2 parents e3037c9 + be1824e commit e1f04ee
Show file tree
Hide file tree
Showing 512 changed files with 11,508 additions and 5,100 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Run on whenever you check out a branch:

```bash
yarn install
yarn infra install
(cd infra/ && yarn install)
yarn codegen
```

Expand Down
12 changes: 0 additions & 12 deletions apps/judicial-system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,18 +226,6 @@ You can serve this service locally by running:
yarn start judicial-system-xrd-api
```

## Robot API

This service is for access through xRoad.

### Running locally

You can serve this service locally by running:

```bash
yarn start judicial-system-robot-api
```

## Digital Mailbox API

This service is for access through xRoad.
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
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,10 @@ import {
} from '@island.is/judicial-system/formatters'
import type { User } from '@island.is/judicial-system/types'
import {
CaseAppealRulingDecision,
CaseDecision,
CaseState,
CaseTransition,
CaseType,
indictmentCases,
investigationCases,
isRestrictionCase,
restrictionCases,
UserRole,
} from '@island.is/judicial-system/types'
Expand Down
19 changes: 15 additions & 4 deletions apps/judicial-system/backend/src/app/modules/case/case.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,9 @@ export class CaseService {
elementId: caseFile.id,
})) ?? []

const messages = this.getDeliverProsecutorToCourtMessages(theCase, user)
.concat(this.getDeliverDefendantToCourtMessages(theCase, user))
.concat(deliverCaseFilesRecordToCourtMessages)
.concat(deliverCaseFileToCourtMessages)
const messages: Message[] = deliverCaseFilesRecordToCourtMessages.concat(
deliverCaseFileToCourtMessages,
)

if (isTrafficViolationCase(theCase)) {
messages.push({
Expand Down Expand Up @@ -2035,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
Loading

0 comments on commit e1f04ee

Please sign in to comment.