Skip to content

Commit

Permalink
Merge branch 'main' into j-s/judge-confirms-defense-choices
Browse files Browse the repository at this point in the history
  • Loading branch information
unakb committed Oct 21, 2024
2 parents f490663 + afc168b commit 061cc7d
Show file tree
Hide file tree
Showing 102 changed files with 3,382 additions and 1,358 deletions.
4 changes: 3 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ fi

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

source_env_if_exists .envrc.kube
24 changes: 24 additions & 0 deletions .envrc.kube
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -euo pipefail

for c in kubectx kubectl aws; do
if ! command -v "$c" >/dev/null; then
echo "$c not installed"
return
fi
done

set-kubectx() {
: "${AWS_PROFILE:=}"
if kubectx | grep -q "${AWS_PROFILE##islandis-}"; then
return
fi
echo "Setting kube context..." >&2
AWS_ACCOUNT_ID="$(aws sts get-caller-identity | jq -r '.Account')"
kubectx "$(kubectx | grep "${AWS_ACCOUNT_ID}")"
CLUSTER="$(kubectl config current-context | sed 's/.*\///')"
export CLUSTER
}

set-kubectx
4 changes: 2 additions & 2 deletions .env.podman → .envrc.podman
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ set -euo pipefail
if [[ -n "${DOCKER_HOST:-}" ]] ||
command -v docker >/dev/null &&
! (docker --version | grep -i podman); then
exit 0
return 0
fi

echo "🐳 Using podman"

SOCKET_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}"
if [[ -S /run/podman/podman.sock ]]; then
SOCKET_DIR="/run/podman"
exit 0
return 0
fi

export DOCKER_HOST=unix://$SOCKET_DIR/podman/podman.sock
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ TODO
*.todo
.env
.env.*
!.env.podman
.envrc.*
.envrc.private
.nvmrc
.node-version
# IDE - VSCode
Expand Down
2 changes: 2 additions & 0 deletions apps/application-system/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import { FriggClientConfig } from '@island.is/clients/mms/frigg'
import { smsModuleConfig } from '@island.is/nova-sms'
import { emailModuleConfig } from '@island.is/email-service'
import { sharedModuleConfig } from '@island.is/application/template-api-modules'
import { UserNotificationClientConfig } from '@island.is/clients/user-notification'

@Module({
imports: [
Expand Down Expand Up @@ -119,6 +120,7 @@ import { sharedModuleConfig } from '@island.is/application/template-api-modules'
smsModuleConfig,
emailModuleConfig,
sharedModuleConfig,
UserNotificationClientConfig,
],
}),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use strict'
const replaceEnum = require('sequelize-replace-enum-postgres').default

module.exports = {
up: (queryInterface) => {
// replaceEnum does not support transactions
return replaceEnum({
queryInterface,
tableName: 'notification',
columnName: 'type',
newValues: [
'HEADS_UP',
'READY_FOR_COURT',
'RECEIVED_BY_COURT',
'COURT_DATE',
'RULING',
'MODIFIED',
'REVOKED',
'DEFENDER_ASSIGNED',
'ADVOCATE_ASSIGNED',
'DEFENDANTS_NOT_UPDATED_AT_COURT',
'APPEAL_TO_COURT_OF_APPEALS',
'APPEAL_RECEIVED_BY_COURT',
'APPEAL_STATEMENT',
'APPEAL_COMPLETED',
'APPEAL_JUDGES_ASSIGNED',
'APPEAL_CASE_FILES_UPDATED',
'APPEAL_WITHDRAWN',
'INDICTMENT_DENIED',
'INDICTMENT_RETURNED',
'INDICTMENTS_WAITING_FOR_CONFIRMATION',
'SERVICE_SUCCESSFUL', // New value
'SERVICE_FAILED', // New value
'DEFENDANT_SELECTED_DEFENDER', // New value
],
enumName: 'enum_notification_type',
})
},

down: (queryInterface) => {
// replaceEnum does not support transactions
return replaceEnum({
queryInterface,
tableName: 'notification',
columnName: 'type',
newValues: [
'HEADS_UP',
'READY_FOR_COURT',
'RECEIVED_BY_COURT',
'COURT_DATE',
'RULING',
'MODIFIED',
'REVOKED',
'DEFENDER_ASSIGNED',
'DEFENDANTS_NOT_UPDATED_AT_COURT',
'APPEAL_TO_COURT_OF_APPEALS',
'APPEAL_RECEIVED_BY_COURT',
'APPEAL_STATEMENT',
'APPEAL_COMPLETED',
'APPEAL_JUDGES_ASSIGNED',
'APPEAL_CASE_FILES_UPDATED',
'APPEAL_WITHDRAWN',
'INDICTMENT_DENIED',
'INDICTMENT_RETURNED',
'INDICTMENTS_WAITING_FOR_CONFIRMATION',
],
enumName: 'enum_notification_type',
})
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,19 +289,19 @@ const canPrisonAdminUserAccessCase = (
) {
return false
}
}

// Check defendant verdict appeal deadline access
const canAppealVerdict = true
const verdictInfo = (theCase.defendants || []).map<
[boolean, Date | undefined]
>((defendant) => [canAppealVerdict, defendant.verdictViewDate])
// Check defendant verdict appeal deadline access
const canAppealVerdict = true
const verdictInfo = (theCase.defendants || []).map<
[boolean, Date | undefined]
>((defendant) => [canAppealVerdict, defendant.verdictViewDate])

const [_, indictmentVerdictAppealDeadlineExpired] =
getIndictmentVerdictAppealDeadlineStatus(verdictInfo)
const [_, indictmentVerdictAppealDeadlineExpired] =
getIndictmentVerdictAppealDeadlineStatus(verdictInfo)

if (!indictmentVerdictAppealDeadlineExpired) {
return false
if (!indictmentVerdictAppealDeadlineExpired) {
return false
}
}

return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,28 @@ export abstract class BaseNotificationService {
),
}
}

protected hasSentNotification(
type: NotificationType,
notifications?: Notification[],
) {
return notifications?.some((notification) => notification.type === type)
}

protected hasReceivedNotification(
type?: NotificationType | NotificationType[],
address?: string,
notifications?: Notification[],
) {
const types = type ? [type].flat() : Object.values(NotificationType)

return notifications?.some((notification) => {
return (
types.includes(notification.type) &&
notification.recipients.some(
(recipient) => recipient.address === address && recipient.success,
)
)
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IsEnum, IsNotEmpty } from 'class-validator'

import { ApiProperty } from '@nestjs/swagger'

import { NotificationType } from '@island.is/judicial-system/types'

import { Subpoena } from '../../subpoena'

export class SubpoenaNotificationDto {
@IsNotEmpty()
@IsEnum(NotificationType)
@ApiProperty({ enum: NotificationType })
readonly type!: NotificationType

@IsNotEmpty()
@ApiProperty({ type: Subpoena })
readonly subpoena!: Subpoena
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ export class InstitutionNotificationService extends BaseNotificationService {
}

private async sendIndictmentsWaitingForConfirmationNotification(
prosecutorsOfficeId: string,
prosecutorsOfficeId?: string,
): Promise<unknown> {
if (!prosecutorsOfficeId) {
return
}

const count =
await this.internalCaseService.countIndictmentsWaitingForConfirmation(
prosecutorsOfficeId,
Expand Down Expand Up @@ -87,7 +91,7 @@ export class InstitutionNotificationService extends BaseNotificationService {

async sendNotification(
type: NotificationType,
prosecutorsOfficeId: string,
prosecutorsOfficeId?: string,
): Promise<DeliverResponse> {
try {
switch (type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import {
import { Case, CaseHasExistedGuard, CurrentCase } from '../case'
import { CaseNotificationDto } from './dto/caseNotification.dto'
import { InstitutionNotificationDto } from './dto/institutionNotification.dto'
import { NotificationDto } from './dto/notification.dto'
import { SubpoenaNotificationDto } from './dto/subpoenaNotification.dto'
import { DeliverResponse } from './models/deliver.response'
import { InstitutionNotificationService } from './institutionNotification.service'
import { InternalNotificationService } from './internalNotification.service'
import { NotificationDispatchService } from './notificationDispatch.service'
import { SubpoenaNotificationService } from './subpoenaNotification.service'

@UseGuards(TokenGuard)
@Controller('api/internal')
Expand All @@ -34,6 +35,7 @@ export class InternalNotificationController {
private readonly internalNotificationService: InternalNotificationService,
private readonly notificationDispatchService: NotificationDispatchService,
private readonly institutionNotificationService: InstitutionNotificationService,
private readonly subpoenaNotificationService: SubpoenaNotificationService,
@Inject(LOGGER_PROVIDER) private readonly logger: Logger,
) {}

Expand Down Expand Up @@ -75,13 +77,29 @@ export class InternalNotificationController {
)
}

@Post(messageEndpoint[MessageType.SUBPOENA_NOTIFICATION])
@ApiCreatedResponse({
type: DeliverResponse,
description: 'Sends a new notification',
})
sendSubpoenaNotification(
@Body() notificationDto: SubpoenaNotificationDto,
): Promise<DeliverResponse> {
this.logger.debug(`Sending ${notificationDto.type} notification`)

return this.subpoenaNotificationService.sendNotification(
notificationDto.type,
notificationDto.subpoena,
)
}

@Post(messageEndpoint[MessageType.NOTIFICATION_DISPATCH])
@ApiCreatedResponse({
type: DeliverResponse,
description: 'Dispatches notifications',
})
dispatchNotification(
@Body() notificationDto: NotificationDto,
@Body() notificationDto: InstitutionNotificationDto,
): Promise<DeliverResponse> {
this.logger.debug(`Dispatching ${notificationDto.type} notification`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,30 +118,6 @@ export class InternalNotificationService extends BaseNotificationService {
)
}

private hasSentNotification(
type: NotificationType,
notifications?: Notification[],
) {
return notifications?.some((notification) => notification.type === type)
}

private hasReceivedNotification(
type?: NotificationType | NotificationType[],
address?: string,
notifications?: Notification[],
) {
const types = type ? [type].flat() : Object.values(NotificationType)

return notifications?.some((notification) => {
return (
types.includes(notification.type) &&
notification.recipients.some(
(recipient) => recipient.address === address && recipient.success,
)
)
})
}

private async shouldSendNotificationToPrison(
theCase: Case,
): Promise<boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
DefendantModule,
EventModule,
InstitutionModule,
SubpoenaModule,
UserModule,
} from '../index'
import { Notification } from './models/notification.model'
Expand All @@ -22,6 +23,7 @@ import { InternalNotificationService } from './internalNotification.service'
import { NotificationController } from './notification.controller'
import { NotificationService } from './notification.service'
import { NotificationDispatchService } from './notificationDispatch.service'
import { SubpoenaNotificationService } from './subpoenaNotification.service'

@Module({
imports: [
Expand All @@ -31,6 +33,7 @@ import { NotificationDispatchService } from './notificationDispatch.service'
MessageModule,
InstitutionModule,
UserModule,
forwardRef(() => SubpoenaModule),
forwardRef(() => CaseModule),
forwardRef(() => CourtModule),
forwardRef(() => EventModule),
Expand All @@ -43,6 +46,7 @@ import { NotificationDispatchService } from './notificationDispatch.service'
InternalNotificationService,
NotificationDispatchService,
InstitutionNotificationService,
SubpoenaNotificationService,
],
})
export class NotificationModule {}
Loading

0 comments on commit 061cc7d

Please sign in to comment.