Skip to content

Commit

Permalink
Merge branch 'main' into efs_calculatewithshare
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Sep 5, 2024
2 parents 9f5d2fc + 5c1b2c2 commit 48587c3
Show file tree
Hide file tree
Showing 22 changed files with 228 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.addColumn('institution', 'address', {
type: Sequelize.STRING,
allowNull: true,
})

const institutionsToUpdate = [
{
name: 'Héraðsdómur Reykjavíkur',
address: 'Dómhúsið við Lækjartorg, Reykjavík',
},
{ name: 'Héraðsdómur Reykjaness', address: 'Fjarðargata 9, Hafnarfirði' },
{
name: 'Héraðsdómur Vesturlands',
address: 'Bjarnarbraut 8, Borgarnesi',
},
{ name: 'Héraðsdómur Vestfjarða', address: 'Hafnarstræti 9, Ísafirði' },
{
name: 'Héraðsdómur Norðurlands vestra',
address: 'Skagfirðingabraut 21, Sauðárkróki',
},
{
name: 'Héraðsdómur Norðurlands eystra',
address: 'Hafnarstræti 107, 4. hæð, Akureyri',
},
{ name: 'Héraðsdómur Austurlands', address: 'Lyngás 15, Egilsstöðum' },
{ name: 'Héraðsdómur Suðurlands', address: 'Austurvegur 4, Selfossi' },
]

await queryInterface.sequelize.transaction(async (transaction) => {
for (const institution of institutionsToUpdate) {
await queryInterface.bulkUpdate(
'institution',
{ address: institution.address },
{ name: institution.name },
{ transaction },
)
}
})
},

down: async (queryInterface) => {
await queryInterface.removeColumn('institution', 'address')
},
}
24 changes: 1 addition & 23 deletions apps/judicial-system/backend/src/app/formatters/subpoenaPdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,6 @@ import {
setTitle,
} from './pdfHelpers'

type DistrictCourts =
| 'Héraðsdómur Reykjavíkur'
| 'Héraðsdómur Reykjaness'
| 'Héraðsdómur Vesturlands'
| 'Héraðsdómur Vestfjarða'
| 'Héraðsdómur Norðurlands vestra'
| 'Héraðsdómur Norðurlands eystra'
| 'Héraðsdómur Austurlands'
| 'Héraðsdómur Suðurlands'

// TODO: Move to databas
const DistrictCourtLocation: Record<DistrictCourts, string> = {
'Héraðsdómur Reykjavíkur': 'Dómhúsið við Lækjartorg, Reykjavík',
'Héraðsdómur Reykjaness': 'Fjarðargata 9, Hafnarfirði',
'Héraðsdómur Vesturlands': 'Bjarnarbraut 8, Borgarnesi',
'Héraðsdómur Vestfjarða': 'Hafnarstræti 9, Ísafirði',
'Héraðsdómur Norðurlands vestra': 'Skagfirðingabraut 21, Sauðárkróki',
'Héraðsdómur Norðurlands eystra': 'Hafnarstræti 107, 4. hæð, Akureyri',
'Héraðsdómur Austurlands': 'Lyngás 15, Egilsstöðum',
'Héraðsdómur Suðurlands': 'Austurvegur 4, Selfossi',
}

export const createSubpoena = (
theCase: Case,
defendant: Defendant,
Expand Down Expand Up @@ -86,7 +64,7 @@ export const createSubpoena = (
if (theCase.court?.name) {
addNormalText(
doc,
DistrictCourtLocation[theCase.court.name as DistrictCourts],
theCase.court.address || 'Ekki skráð', // the latter shouldn't happen, if it does we have an problem with the court data
'Times-Roman',
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ import {
prosecutorUpdateRule,
publicProsecutorStaffUpdateRule,
} from './guards/rolesRules'
import { CaseInterceptor } from './interceptors/case.interceptor'
import { CaseListInterceptor } from './interceptors/caseList.interceptor'
import { CompletedAppealAccessedInterceptor } from './interceptors/completedAppealAccessed.interceptor'
import { Case } from './models/case.model'
import { SignatureConfirmationResponse } from './models/signatureConfirmation.response'
import { transitionCase } from './state/case.state'
Expand Down Expand Up @@ -465,7 +465,7 @@ export class CaseController {
)
@Get('case/:caseId')
@ApiOkResponse({ type: Case, description: 'Gets an existing case' })
@UseInterceptors(CaseInterceptor)
@UseInterceptors(CompletedAppealAccessedInterceptor)
getById(@Param('caseId') caseId: string, @CurrentCase() theCase: Case): Case {
this.logger.debug(`Getting case ${caseId} by id`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class LimitedAccessCaseExistsGuard implements CanActivate {
async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest()

const caseId = request.params.caseId
const caseId: string = request.params.caseId

if (!caseId) {
throw new BadRequestException('Missing case id')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Observable } from 'rxjs'
import { map } from 'rxjs/operators'

import {
CallHandler,
ExecutionContext,
Injectable,
NestInterceptor,
} from '@nestjs/common'

import {
CaseAppealState,
CaseFileCategory,
isDefenceUser,
isPrisonStaffUser,
isPrisonSystemUser,
User,
} from '@island.is/judicial-system/types'

import { Case } from '../models/case.model'

@Injectable()
export class CaseFileInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<Case> {
const request = context.switchToHttp().getRequest()
const user: User = request.user

return next.handle().pipe(
map((data: Case) => {
if (isDefenceUser(user)) {
return data
}

if (
isPrisonStaffUser(user) ||
data.appealState !== CaseAppealState.COMPLETED
) {
data.caseFiles?.splice(0, data.caseFiles.length)
} else if (isPrisonSystemUser(user)) {
data.caseFiles?.splice(
0,
data.caseFiles.length,
...data.caseFiles.filter(
(cf) => cf.category === CaseFileCategory.APPEAL_RULING,
),
)
}

return data
}),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { EventLogService } from '../../event-log'
import { Case } from '../models/case.model'

@Injectable()
export class CaseInterceptor implements NestInterceptor {
export class CompletedAppealAccessedInterceptor implements NestInterceptor {
constructor(private readonly eventLogService: EventLogService) {}

intercept(context: ExecutionContext, next: CallHandler): Observable<Case> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ import { CaseWriteGuard } from './guards/caseWrite.guard'
import { LimitedAccessCaseExistsGuard } from './guards/limitedAccessCaseExists.guard'
import { RequestSharedWithDefenderGuard } from './guards/requestSharedWithDefender.guard'
import { defenderTransitionRule, defenderUpdateRule } from './guards/rolesRules'
import { CaseInterceptor } from './interceptors/case.interceptor'
import { CaseFileInterceptor } from './interceptors/caseFile.interceptor'
import { CompletedAppealAccessedInterceptor } from './interceptors/completedAppealAccessed.interceptor'
import { Case } from './models/case.model'
import { transitionCase } from './state/case.state'
import {
Expand Down Expand Up @@ -85,7 +86,7 @@ export class LimitedAccessCaseController {
type: Case,
description: 'Gets a limited set of properties of an existing case',
})
@UseInterceptors(CaseInterceptor)
@UseInterceptors(CompletedAppealAccessedInterceptor, CaseFileInterceptor)
async getById(
@Param('caseId') caseId: string,
@CurrentCase() theCase: Case,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ export const defenderCaseFileCategoriesForIndictmentCases = [
CaseFileCategory.PROSECUTOR_CASE_FILE,
CaseFileCategory.DEFENDANT_CASE_FILE,
]

export const prisonAdminCaseFileCategories = [CaseFileCategory.APPEAL_RULING]
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import {
} from '@nestjs/common'

import {
CaseFileCategory,
isCompletedCase,
isDefenceUser,
isIndictmentCase,
isPrisonSystemUser,
isPrisonAdminUser,
isRequestCase,
User,
} from '@island.is/judicial-system/types'
Expand All @@ -21,6 +20,7 @@ import { CaseFile } from '../models/file.model'
import {
defenderCaseFileCategoriesForIndictmentCases,
defenderCaseFileCategoriesForRestrictionAndInvestigationCases,
prisonAdminCaseFileCategories,
} from './caseFileCategory'

@Injectable()
Expand Down Expand Up @@ -65,14 +65,13 @@ export class LimitedAccessViewCaseFileGuard implements CanActivate {
}
}

if (isPrisonSystemUser(user)) {
if (
isCompletedCase(theCase.state) &&
caseFile.category &&
caseFile.category === CaseFileCategory.APPEAL_RULING
) {
return true
}
if (
caseFile.category &&
isCompletedCase(theCase.state) &&
isPrisonAdminUser(user) &&
prisonAdminCaseFileCategories.includes(caseFile.category)
) {
return true
}

throw new ForbiddenException(`Forbidden for ${user.role}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,19 @@ describe('Limited Access View Case File Guard', () => {
describe.each(allowedCaseFileCategories)(
'prison system users can view %s',
(category) => {
let thenPrison: Then
let thenPrisonAdmin: Then

beforeEach(() => {
mockRequest.mockImplementationOnce(() => ({
user: prisonUser,
case: { type, state },
caseFile: { category },
}))
mockRequest.mockImplementationOnce(() => ({
user: prisonAdminUser,
case: { type, state },
caseFile: { category },
}))

thenPrison = givenWhenThen()
thenPrisonAdmin = givenWhenThen()
})

it('should activate', () => {
expect(thenPrison.result).toBe(true)
expect(thenPrisonAdmin.result).toBe(true)
})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,8 @@ export class Institution extends Model {
@Column({ type: DataType.STRING, allowNull: true })
@ApiPropertyOptional({ type: String })
nationalId?: string

@Column({ type: DataType.STRING, allowNull: true })
@ApiPropertyOptional({ type: String })
address?: string
}
1 change: 1 addition & 0 deletions apps/services/regulations-admin-backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ bootstrap({
appModule: AppModule,
name: 'regulations-admin-backend',
openApi,
jsonBodyLimit: '300kb',
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { TemplateApiModuleActionProps } from '../../../types'
import { BaseTemplateApiService } from '../../base-template-api.service'
import {
ApplicationTypes,
ApplicationWithAttachments,
NationalRegistryIndividual,
} from '@island.is/application/types'

Expand All @@ -23,7 +22,10 @@ import {
CreateApplicationDtoEducationOptionEnum,
} from '@island.is/clients/university-gateway-api'

import { UniversityAnswers } from '@island.is/application/templates/university'
import {
UniversityAnswers,
UniversityGatewayProgram,
} from '@island.is/application/templates/university'
import { Auth, AuthMiddleware } from '@island.is/auth-nest-tools'
import { InnaClientService } from '@island.is/clients/inna'

Expand Down Expand Up @@ -120,6 +122,14 @@ export class UniversityService extends BaseTemplateApiService {
email: userFromAnswers.email,
phone: userFromAnswers.phone,
}
const programs = externalData.programs
?.data as Array<UniversityGatewayProgram>
const modesOfDeliveryFromChosenProgram = programs.find(
(x) => x.id === answers.programInformation.program,
)
const defaultModeOfDelivery = modesOfDeliveryFromChosenProgram
?.modeOfDelivery[0]
.modeOfDelivery as CreateApplicationDtoModeOfDeliveryEnum

//all possible types of education data from the application answers
const educationOptionChosen =
Expand Down Expand Up @@ -235,7 +245,8 @@ export class UniversityService extends BaseTemplateApiService {
universityId: answers.programInformation.university,
programId: answers.programInformation.program,
modeOfDelivery: mapStringToEnum(
answers.modeOfDeliveryInformation.chosenMode,
answers.modeOfDeliveryInformation?.chosenMode ||
defaultModeOfDelivery,
CreateApplicationDtoModeOfDeliveryEnum,
'CreateApplicationDtoModeOfDeliveryEnum',
),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { FieldBaseProps } from '@island.is/application/types'
import { FC, useEffect } from 'react'
import { useFormContext } from 'react-hook-form'
import { calculateTotalAssets } from '../../../lib/utils/calculateTotalAssets'

export const SetTotalAssets: FC<React.PropsWithChildren<FieldBaseProps>> = ({
application,
}) => {
const { answers } = application
const { setValue } = useFormContext()

const total = calculateTotalAssets(answers)

useEffect(() => {
setValue('assets.assetsTotal', total)
}, [total, setValue])

return null
}

export default SetTotalAssets
Loading

0 comments on commit 48587c3

Please sign in to comment.