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): Indictment sent or withdrawn from prison notifications #16943

Merged
merged 88 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
335edc1
Add a send to fmst button that routes to a page
oddsson Nov 11, 2024
a8cb9f7
Remove unused code
oddsson Nov 11, 2024
8b888fe
Add UI
oddsson Nov 11, 2024
ea5923f
Create event log when indictment is sent to FMSt
oddsson Nov 12, 2024
ad88263
Create event log when indictment is sent to FMSt
oddsson Nov 12, 2024
a32c269
Create event log when indictment is sent to FMSt
oddsson Nov 12, 2024
da85475
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 12, 2024
6b2c737
Refactor
oddsson Nov 12, 2024
633b19d
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 13, 2024
f308a97
Refactor
oddsson Nov 13, 2024
785f979
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 13, 2024
f85488e
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 13, 2024
bd8d258
Refactor
oddsson Nov 13, 2024
1fbff2a
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 13, 2024
191b8b6
Updates FMST queries
gudjong Nov 13, 2024
e62975b
Merge branch 'j-s/send-to-fmst' of github.com:island-is/island.is int…
gudjong Nov 13, 2024
7ec2ed0
Refactor
oddsson Nov 13, 2024
338d40e
Refactor
oddsson Nov 13, 2024
0c5c2f1
Refactor
oddsson Nov 13, 2024
8955343
Refactor
oddsson Nov 13, 2024
d4671f6
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 14, 2024
50cd6c4
Add DefendantEventLog table
oddsson Nov 14, 2024
e3a1512
Refactor
oddsson Nov 15, 2024
4c8e936
Send sentToPrisonAdminDate to client
oddsson Nov 15, 2024
166d956
Show sent to prison admin date on info cards
oddsson Nov 15, 2024
964192c
Refactor
oddsson Nov 15, 2024
b6ca9de
Refactor
oddsson Nov 15, 2024
ed7d42c
Refactor
oddsson Nov 15, 2024
fe071b4
Refactor
oddsson Nov 15, 2024
3c3813e
Refactor
oddsson Nov 15, 2024
e4f9b55
Refactor
oddsson Nov 15, 2024
587ce2b
Refactor
oddsson Nov 15, 2024
1a59c08
Refactor
oddsson Nov 15, 2024
f54c953
Refactor
oddsson Nov 15, 2024
8f82463
Refactor
oddsson Nov 15, 2024
d5bb749
Refactor
oddsson Nov 15, 2024
a488cc3
Refactor
oddsson Nov 15, 2024
7f3d087
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 18, 2024
9c8b0fd
Frontend: Upload file to prison admin
oddsson Nov 18, 2024
7672505
Frontend: Upload file to prison admin
oddsson Nov 18, 2024
79f4a6b
Add SentToPrisonAdmin tag in cases list for PP
oddsson Nov 18, 2024
05b083c
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 18, 2024
6ce143a
Merge
oddsson Nov 18, 2024
944b868
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 18, 2024
f235f82
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 18, 2024
141db7d
Refactor
oddsson Nov 18, 2024
3e38681
Refactor
oddsson Nov 18, 2024
e30106e
Refactor
oddsson Nov 18, 2024
4e352f8
Refactor
oddsson Nov 19, 2024
84e8365
Refactor
oddsson Nov 19, 2024
4d3737d
Refactor
oddsson Nov 19, 2024
ba815f9
Refactor
oddsson Nov 19, 2024
920f13b
Refactor
oddsson Nov 19, 2024
cd41cdc
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 19, 2024
b344d21
chore(j-s): Notifications to prison when indictment sent or withdrawn
unakb Nov 19, 2024
0668c66
fix(j-s): Test fix
unakb Nov 19, 2024
bfee33e
Merge branch 'main' into j-s/indictment-to-prison-notifications
unakb Nov 19, 2024
edc30af
chore: charts update dirty files
andes-it Nov 19, 2024
cee3ec1
fix(j-s): Tests
unakb Nov 19, 2024
f210126
Merge branch 'j-s/indictment-to-prison-notifications' of https://gith…
unakb Nov 19, 2024
8d97c7c
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 20, 2024
6f93150
Merge branch 'j-s/send-to-fmst' of github.com:island-is/island.is int…
oddsson Nov 20, 2024
60d3182
Merge branch 'j-s/send-to-fmst' into j-s/indictment-to-prison-notific…
unakb Nov 20, 2024
1883a44
chore: nx format:write update dirty files
andes-it Nov 20, 2024
8c5df94
Merge branch 'main' of github.com:island-is/island.is into j-s/send-t…
oddsson Nov 20, 2024
ad5dd12
Refactor
oddsson Nov 20, 2024
f1f8027
Remove caseId from defendant event log table
oddsson Nov 20, 2024
5e1fdbc
Remove caseId from defendant event log table
oddsson Nov 20, 2024
262a0ad
Revert
oddsson Nov 20, 2024
7119d36
Remove unused code
oddsson Nov 20, 2024
cedc69c
Refactor
oddsson Nov 20, 2024
a303e84
Merge branch 'main' of github.com:island-is/island.is into j-s/send-…
oddsson Nov 20, 2024
01e9c25
Removes unused event type
gudjong Nov 21, 2024
28669df
Merge branch 'j-s/send-to-fmst' of github.com:island-is/island.is int…
gudjong Nov 21, 2024
6ec3000
Removes the defendant event log from the api
gudjong Nov 21, 2024
402f584
Moves defendant event log to defendant model
gudjong Nov 21, 2024
719bfbd
Fixes backend case retrieval
gudjong Nov 21, 2024
4b2389f
Merge branch 'j-s/send-to-fmst' into j-s/indictment-to-prison-notific…
unakb Nov 22, 2024
02d9e49
Merge branch 'main' into j-s/indictment-to-prison-notifications
unakb Nov 25, 2024
bb8740d
Merge branch 'main' into j-s/indictment-to-prison-notifications
unakb Nov 25, 2024
1c49d77
test(j-s): add missing test
unakb Nov 25, 2024
dc3d264
fix(j-s): Tests
unakb Nov 25, 2024
207d74f
Update civilClaimantNotification.service.ts
unakb Nov 25, 2024
718772e
Merge branch 'main' into j-s/indictment-to-prison-notifications
unakb Nov 25, 2024
e93d98b
Merge branch 'main' into j-s/indictment-to-prison-notifications
unakb Nov 26, 2024
918943a
Merge branch 'main' into j-s/indictment-to-prison-notifications
unakb Nov 26, 2024
939e7cf
Reorders notification types to group related type together
gudjong Nov 27, 2024
2492f48
Merge branch 'main' into j-s/indictment-to-prison-notifications
kodiakhq[bot] Nov 27, 2024
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 @@ -70,6 +70,8 @@ export const serviceSetup = (): ServiceBuilder<'judicial-system-backend'> =>
EMAIL_REPLY_TO_NAME: '/k8s/judicial-system/EMAIL_REPLY_TO_NAME',
PRISON_EMAIL: '/k8s/judicial-system/PRISON_EMAIL',
PRISON_ADMIN_EMAIL: '/k8s/judicial-system/PRISON_ADMIN_EMAIL',
PRISON_ADMIN_INDICTMENT_EMAILS:
'/k8s/judicial-system/PRISON_ADMIN_INDICTMENT_EMAILS',
AUTH_JWT_SECRET: '/k8s/judicial-system/AUTH_JWT_SECRET',
ADMIN_USERS: '/k8s/judicial-system/ADMIN_USERS',
BACKEND_ACCESS_TOKEN: '/k8s/judicial-system/BACKEND_ACCESS_TOKEN',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ export class DefendantService {
return message
}

private getMessagesForIndictmentToPrisonAdminChanges(
defendant: Defendant,
): Message {
const messageType =
defendant.isSentToPrisonAdmin === true
? DefendantNotificationType.INDICTMENT_SENT_TO_PRISON_ADMIN
: DefendantNotificationType.INDICTMENT_WITHDRAWN_FROM_PRISON_ADMIN

const message = {
type: MessageType.DEFENDANT_NOTIFICATION,
caseId: defendant.caseId,
elementId: defendant.id,
body: {
type: messageType,
},
}

return message
}

private getUpdatedDefendant(
numberOfAffectedRows: number,
defendants: Defendant[],
Expand Down Expand Up @@ -143,19 +163,19 @@ export class DefendantService {
return
}

const messages: Message[] = []

if (
updatedDefendant.isDefenderChoiceConfirmed &&
!oldDefendant.isDefenderChoiceConfirmed
) {
// Defender choice was just confirmed by the court
const messages: Message[] = [
{
type: MessageType.DELIVERY_TO_COURT_INDICTMENT_DEFENDER,
user,
caseId: theCase.id,
elementId: updatedDefendant.id,
},
]
messages.push({
type: MessageType.DELIVERY_TO_COURT_INDICTMENT_DEFENDER,
user,
caseId: theCase.id,
elementId: updatedDefendant.id,
})

if (
updatedDefendant.defenderChoice === DefenderChoice.CHOOSE ||
Expand All @@ -171,9 +191,20 @@ export class DefendantService {
})
}
}
} else if (
updatedDefendant.isSentToPrisonAdmin !== undefined &&
updatedDefendant.isSentToPrisonAdmin !== oldDefendant.isSentToPrisonAdmin
) {
messages.push(
this.getMessagesForIndictmentToPrisonAdminChanges(updatedDefendant),
)
}
unakb marked this conversation as resolved.
Show resolved Hide resolved

return this.messageService.sendMessagesToQueue(messages)
if (messages.length === 0) {
return
}

return this.messageService.sendMessagesToQueue(messages)
}

async createForNewCase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,58 @@ describe('DefendantController - Update', () => {
},
)

describe('defendant in indictment is sent to prison admin', () => {
const defendantUpdate = { isSentToPrisonAdmin: true }
const updatedDefendant = { ...defendant, ...defendantUpdate }

beforeEach(async () => {
const mockUpdate = mockDefendantModel.update as jest.Mock
mockUpdate.mockResolvedValueOnce([1, [updatedDefendant]])

await givenWhenThen(defendantUpdate, CaseType.INDICTMENT, caseId)
})

it('should queue messages', () => {
expect(mockMessageService.sendMessagesToQueue).toHaveBeenCalledWith([
{
type: MessageType.DEFENDANT_NOTIFICATION,
caseId,
elementId: defendantId,
body: {
type: DefendantNotificationType.INDICTMENT_SENT_TO_PRISON_ADMIN,
},
},
])
expect(mockMessageService.sendMessagesToQueue).toHaveBeenCalledTimes(1)
})
})

describe('defendant in indictment is withdrawn from prison admin', () => {
const defendantUpdate = { isSentToPrisonAdmin: false }
const updatedDefendant = { ...defendant, ...defendantUpdate }

beforeEach(async () => {
const mockUpdate = mockDefendantModel.update as jest.Mock
mockUpdate.mockResolvedValueOnce([1, [updatedDefendant]])

await givenWhenThen(defendantUpdate, CaseType.INDICTMENT, caseId)
})

it('should queue messages for indictment withdrawn from prison admin', () => {
expect(mockMessageService.sendMessagesToQueue).toHaveBeenCalledWith([
{
type: MessageType.DEFENDANT_NOTIFICATION,
caseId,
elementId: defendantId,
body: {
type: DefendantNotificationType.INDICTMENT_WITHDRAWN_FROM_PRISON_ADMIN,
},
},
])
expect(mockMessageService.sendMessagesToQueue).toHaveBeenCalledTimes(1)
})
})

describe('defendant update fails', () => {
let then: Then

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ import { InstitutionNotificationDto } from './dto/institutionNotification.dto'
import { NotificationDispatchDto } from './dto/notificationDispatch.dto'
import { SubpoenaNotificationDto } from './dto/subpoenaNotification.dto'
import { DeliverResponse } from './models/deliver.response'
import { CaseNotificationService } from './caseNotification.service'
import { CivilClaimantNotificationService } from './civilClaimantNotification.service'
import { DefendantNotificationService } from './defendantNotification.service'
import { InstitutionNotificationService } from './institutionNotification.service'
import { CaseNotificationService } from './services/caseNotification/caseNotification.service'
gudjong marked this conversation as resolved.
Show resolved Hide resolved
import { CivilClaimantNotificationService } from './services/civilClaimantNotification/civilClaimantNotification.service'
import { DefendantNotificationService } from './services/defendantNotification/defendantNotification.service'
import { InstitutionNotificationService } from './services/institutionNotification/institutionNotification.service'
import { SubpoenaNotificationService } from './services/subpoenaNotification/subpoenaNotification.service'
import { NotificationDispatchService } from './notificationDispatch.service'
import { SubpoenaNotificationService } from './subpoenaNotification.service'

@UseGuards(TokenGuard)
@Controller('api/internal')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export const notificationModuleConfig = defineConfig({
replyToName: env.required('EMAIL_REPLY_TO_NAME', 'Réttarvörslugátt'),
prisonEmail: env.required('PRISON_EMAIL', ''),
prisonAdminEmail: env.required('PRISON_ADMIN_EMAIL', ''),
prisonAdminIndictmentEmails: env.required(
'PRISON_ADMIN_INDICTMENT_EMAILS',
'',
),
unakb marked this conversation as resolved.
Show resolved Hide resolved
courtsEmails: env.requiredJSON('COURTS_EMAILS', {}) as {
[key: string]: string
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import {
UserModule,
} from '../index'
import { Notification } from './models/notification.model'
import { CaseNotificationService } from './caseNotification.service'
import { CivilClaimantNotificationService } from './civilClaimantNotification.service'
import { DefendantNotificationService } from './defendantNotification.service'
import { InstitutionNotificationService } from './institutionNotification.service'
import { CaseNotificationService } from './services/caseNotification/caseNotification.service'
import { CivilClaimantNotificationService } from './services/civilClaimantNotification/civilClaimantNotification.service'
import { DefendantNotificationService } from './services/defendantNotification/defendantNotification.service'
import { InstitutionNotificationService } from './services/institutionNotification/institutionNotification.service'
import { SubpoenaNotificationService } from './services/subpoenaNotification/subpoenaNotification.service'
import { InternalNotificationController } from './internalNotification.controller'
import { NotificationController } from './notification.controller'
import { NotificationService } from './notification.service'
import { NotificationDispatchService } from './notificationDispatch.service'
import { SubpoenaNotificationService } from './subpoenaNotification.service'

@Module({
imports: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ import {
formatProsecutorCourtDateEmailNotification,
formatProsecutorReadyForCourtEmailNotification,
formatProsecutorReceivedByCourtSmsNotification,
} from '../../formatters'
import { notifications } from '../../messages'
import { type Case, DateLog } from '../case'
import { CourtService } from '../court'
} from '../../../../formatters'
import { notifications } from '../../../../messages'
import { type Case, DateLog } from '../../../case'
import { CourtService } from '../../../court'
import {
type CivilClaimant,
type Defendant,
DefendantService,
} from '../defendant'
import { EventService } from '../event'
import { DeliverResponse } from './models/deliver.response'
import { Notification, Recipient } from './models/notification.model'
import { BaseNotificationService } from './baseNotification.service'
import { notificationModuleConfig } from './notification.config'
} from '../../../defendant'
import { EventService } from '../../../event'
import { BaseNotificationService } from '../../baseNotification.service'
import { DeliverResponse } from '../../models/deliver.response'
import { Notification, Recipient } from '../../models/notification.model'
import { notificationModuleConfig } from '../../notification.config'

interface Attachment {
filename: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import { DEFENDER_INDICTMENT_ROUTE } from '@island.is/judicial-system/consts'
import { capitalize } from '@island.is/judicial-system/formatters'
import { CivilClaimantNotificationType } from '@island.is/judicial-system/types'

import { Case } from '../case'
import { CivilClaimant } from '../defendant'
import { EventService } from '../event'
import { DeliverResponse } from './models/deliver.response'
import { Notification, Recipient } from './models/notification.model'
import { BaseNotificationService } from './baseNotification.service'
import { Case } from '../../../case'
import { CivilClaimant } from '../../../defendant'
import { EventService } from '../../../event'
import { BaseNotificationService } from '../../baseNotification.service'
import { DeliverResponse } from '../../models/deliver.response'
import { Notification, Recipient } from '../../models/notification.model'
import { notificationModuleConfig } from '../../notification.config'
import { strings } from './civilClaimantNotification.strings'
import { notificationModuleConfig } from './notification.config'

@Injectable()
export class CivilClaimantNotificationService extends BaseNotificationService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import {
isIndictmentCase,
} from '@island.is/judicial-system/types'

import { Case } from '../case'
import { Defendant } from '../defendant'
import { EventService } from '../event'
import { DeliverResponse } from './models/deliver.response'
import { Notification, Recipient } from './models/notification.model'
import { BaseNotificationService } from './baseNotification.service'
import { Case } from '../../../case'
import { Defendant } from '../../../defendant'
import { EventService } from '../../../event'
import { BaseNotificationService } from '../../baseNotification.service'
import { DeliverResponse } from '../../models/deliver.response'
import { Notification, Recipient } from '../../models/notification.model'
import { notificationModuleConfig } from '../../notification.config'
import { strings } from './defendantNotification.strings'
import { notificationModuleConfig } from './notification.config'

@Injectable()
export class DefendantNotificationService extends BaseNotificationService {
Expand Down Expand Up @@ -179,6 +179,80 @@ export class DefendantNotificationService extends BaseNotificationService {
return { delivered: true }
}

private sendIndictmentSentToPrisonAdminNotification(theCase: Case) {
const formattedSubject = this.formatMessage(
strings.indictmentSentToPrisonAdminSubject,
{
courtCaseNumber: theCase.courtCaseNumber,
},
)

const formattedBody = this.formatMessage(
strings.indictmentSentToPrisonAdminBody,
{
courtCaseNumber: theCase.courtCaseNumber,
linkStart: `<a href="${this.config.clientUrl}${ROUTE_HANDLER_ROUTE}/${theCase.id}">`,
linkEnd: '</a>',
},
)

// We want to send separate emails to each recipient
const to = this.config.email.prisonAdminIndictmentEmails
.split(',')
.map((email) => email.trim())
.map((email) => {
return {
name: 'Fangelsismálastofnun',
email,
}
})

return this.sendEmails(
theCase,
DefendantNotificationType.INDICTMENT_SENT_TO_PRISON_ADMIN,
formattedSubject,
formattedBody,
to,
)
}

private sendIndictmentWithdrawnFromPrisonAdminNotification(theCase: Case) {
const courtCaseNumber = theCase.courtCaseNumber

const formattedSubject = this.formatMessage(
strings.indictmentWithdrawnFromPrisonAdminSubject,
{
courtCaseNumber,
},
)

const formattedBody = this.formatMessage(
strings.indictmentWithdrawnFromPrisonAdminBody,
{
courtCaseNumber,
},
)

// We want to send separate emails to each recipient
const to = this.config.email.prisonAdminIndictmentEmails
.split(',')
.map((email) => email.trim())
.map((email) => {
return {
name: 'Fangelsismálastofnun',
email,
}
})

return this.sendEmails(
theCase,
DefendantNotificationType.INDICTMENT_WITHDRAWN_FROM_PRISON_ADMIN,
formattedSubject,
formattedBody,
to,
)
}

private sendNotification(
notificationType: DefendantNotificationType,
theCase: Case,
Expand All @@ -189,6 +263,10 @@ export class DefendantNotificationService extends BaseNotificationService {
return this.sendDefendantSelectedDefenderNotification(theCase)
case DefendantNotificationType.DEFENDER_ASSIGNED:
return this.sendDefenderAssignedNotification(theCase, defendant)
case DefendantNotificationType.INDICTMENT_SENT_TO_PRISON_ADMIN:
return this.sendIndictmentSentToPrisonAdminNotification(theCase)
case DefendantNotificationType.INDICTMENT_WITHDRAWN_FROM_PRISON_ADMIN:
return this.sendIndictmentWithdrawnFromPrisonAdminNotification(theCase)
default:
throw new InternalServerErrorException(
`Invalid notification type: ${notificationType}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,29 @@ export const strings = {
description:
'Body of the notification when a defender is assigned a confirmed as a defender in indictment cases',
}),
indictmentSentToPrisonAdminSubject: defineMessage({
id: 'judicial.system.backend:defendant_notifications.indictment_sent_to_prison_admin_subject',
defaultMessage: 'Mál {courtCaseNumber} til fullnustu',
description:
'Titill í tilkynningu til FMST þegar mál er sent til fullnustu',
}),
indictmentSentToPrisonAdminBody: defineMessage({
id: 'judicial.system.backend:defendant_notifications.indictment_sent_to_prison_admin_body',
defaultMessage:
'Ríkissaksóknari hefur sent mál {courtCaseNumber} til fullnustu.<br /><br />Skjöl málsins eru aðgengileg á {linkStart}yfirlitssíðu málsins í Réttarvörslugátt{linkEnd}.',
description: 'Texti í tilkynningu til FMST þegar mál er sent til fullnustu',
}),
indictmentWithdrawnFromPrisonAdminSubject: defineMessage({
id: 'judicial.system.backend:defendant_notifications.indictment_withdrawn_from_prison_admin_subject',
defaultMessage: 'Mál {courtCaseNumber} afturkallað úr fullnustu',
description:
'Titill í tilkynningu til FMST þegar mál er afturkallað úr fullnustu',
}),
indictmentWithdrawnFromPrisonAdminBody: defineMessage({
id: 'judicial.system.backend:defendant_notifications.indictment_withdrawn_from_prison_admin_body',
defaultMessage:
'Ríkissaksóknari hefur afturkallað mál {courtCaseNumber} úr fullnustu.',
description:
'Texti í tilkynningu til FMST þegar mál er afturkallað úr fullnustu',
}),
}
Loading
Loading