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): Connect case files to defendant or civil claimants #17043

Merged
merged 101 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from 93 commits
Commits
Show all changes
101 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
bdeea4f
feat(j-s): Connect case files to defendant or civil claimant
unakb Nov 27, 2024
5bda7ff
Merge branch 'main' into j-s/defender-case-files-connection
unakb Nov 27, 2024
56b1a69
Merge branch 'main' into j-s/defender-case-files-connection
gudjong Nov 28, 2024
b193e65
Merge branch 'main' of github.com:island-is/island.is into j-s/defend…
gudjong Nov 29, 2024
7bd92e8
Fixes backend endpoints
gudjong Nov 29, 2024
e82c422
Changes wording
gudjong Nov 29, 2024
085f204
Removes duplicate notification types
gudjong Nov 29, 2024
4b21034
Blocks limited acces create civil claimant file for now
gudjong Nov 29, 2024
62ea777
Adds back category restiction guards when creating files for defendan…
gudjong Nov 29, 2024
ac48948
Removes redundant arguments
gudjong Nov 29, 2024
41dd5db
Removes unused imports
gudjong Nov 29, 2024
38e1e7b
Rewrites create case file api
gudjong Nov 29, 2024
4d50dd9
Rewrites use S3 upload
gudjong Dec 1, 2024
c526395
Fixes argument declarations
gudjong Dec 1, 2024
ecf1a74
Merge branch 'main' into j-s/defender-case-files-connection
gudjong Dec 1, 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 @@ -266,8 +266,19 @@ export class BackendService extends DataSource<{ req: Request }> {
return this.post(`case/${id}/file/url`, createPresignedPost)
}

createCaseFile(id: string, createFile: unknown): Promise<CaseFile> {
return this.post(`case/${id}/file`, createFile)
createCaseFile(
id: string,
createFile: unknown,
defendantId?: string,
civilClaimantId?: string,
): Promise<CaseFile> {
gudjong marked this conversation as resolved.
Show resolved Hide resolved
const connectionInjection = defendantId
? `/defendant/${defendantId}`
: civilClaimantId
? `/civilClaimant/${civilClaimantId}`
: ''

return this.post(`case/${id}${connectionInjection}/file`, createFile)
gudjong marked this conversation as resolved.
Show resolved Hide resolved
}

getCaseFileSignedUrl(
Expand Down Expand Up @@ -435,8 +446,15 @@ export class BackendService extends DataSource<{ req: Request }> {
limitedAccessCreateCaseFile(
id: string,
createFile: unknown,
civilClaimantId?: string,
): Promise<CaseFile> {
return this.post(`case/${id}/limitedAccess/file`, createFile)
const connectionInjection = civilClaimantId
? `/civilClaimant/${civilClaimantId}`
: ''
return this.post(
`case/${id}/limitedAccess${connectionInjection}/file`,
createFile,
)
gudjong marked this conversation as resolved.
Show resolved Hide resolved
}

limitedAccessGetCaseFileSignedUrl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ export class CreateFileInput {
@IsOptional()
@Field(() => String, { nullable: true })
readonly userGeneratedFilename?: string

@Allow()
@IsOptional()
@Field(() => ID, { nullable: true })
readonly defendantId?: string

@Allow()
@IsOptional()
@Field(() => ID, { nullable: true })
readonly civilClaimantId?: string
gudjong marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,19 @@ export class FileResolver {
@Context('dataSources')
{ backendService }: { backendService: BackendService },
): Promise<CaseFile> {
const { caseId, ...createFile } = input
const { caseId, defendantId, civilClaimantId, ...createFile } = input
gudjong marked this conversation as resolved.
Show resolved Hide resolved

this.logger.debug(`Creating a file for case ${caseId}`)

return this.auditTrailService.audit(
user.id,
AuditedAction.CREATE_FILE,
backendService.createCaseFile(caseId, createFile),
backendService.createCaseFile(
caseId,
createFile,
defendantId,
civilClaimantId,
),
(file) => file.id,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ export class LimitedAccessFileResolver {
@Context('dataSources')
{ backendService }: { backendService: BackendService },
): Promise<CaseFile> {
const { caseId, ...createFile } = input
const { caseId, civilClaimantId, ...createFile } = input

this.logger.debug(`Creating a file for case ${caseId}`)

return this.auditTrailService.audit(
user.id,
AuditedAction.CREATE_FILE,
backendService.limitedAccessCreateCaseFile(caseId, createFile),
backendService.limitedAccessCreateCaseFile(
caseId,
createFile,
civilClaimantId,
),
gudjong marked this conversation as resolved.
Show resolved Hide resolved
(file) => file.id,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict'

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(async (t) => {
await queryInterface.addColumn(
'case_file',
'defendant_id',
{
type: Sequelize.UUID,
references: {
model: 'defendant',
key: 'id',
},
allowNull: true,
},
{ transaction: t },
)
await queryInterface.addColumn(
'case_file',
'civil_claimant_id',
{
type: Sequelize.UUID,
references: {
model: 'civil_claimant',
key: 'id',
},
allowNull: true,
},
{ transaction: t },
)
})
},
down: (queryInterface) => {
return queryInterface.sequelize.transaction(async (t) => {
await queryInterface.removeColumn('case_file', 'civil_claimant_id', {
transaction: t,
})
await queryInterface.removeColumn('case_file', 'defendant_id', {
transaction: t,
})
})
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ import {
CurrentCase,
} from '../case'
import { MergedCaseExistsGuard } from '../case/guards/mergedCaseExists.guard'
import {
CivilClaimant,
CivilClaimantExistsGuard,
CurrentCivilClaimant,
CurrentDefendant,
Defendant,
DefendantExistsGuard,
} from '../defendant'
import { CreateFileDto } from './dto/createFile.dto'
import { CreatePresignedPostDto } from './dto/createPresignedPost.dto'
import { UpdateFilesDto } from './dto/updateFile.dto'
Expand Down Expand Up @@ -126,6 +134,61 @@ export class FileController {
return this.fileService.createCaseFile(theCase, createFile, user)
}

@UseGuards(RolesGuard, CaseExistsGuard, DefendantExistsGuard, CaseWriteGuard)
@RolesRules(publicProsecutorStaffRule)
@Post('defendant/:defendantId/file')
@ApiCreatedResponse({
type: CaseFile,
description: 'Creates a new case file connected to a defendant',
})
async createDefendantCaseFile(
@Param('caseId') caseId: string,
@Param('defendantId') defendantId: string,
@CurrentHttpUser() user: User,
@CurrentCase() theCase: Case,
@CurrentDefendant() defendant: Defendant,
@Body() createFile: CreateFileDto,
): Promise<CaseFile> {
this.logger.debug(
`Creating a file for case ${caseId} for defendant ${defendantId}`,
)

return this.fileService.createCaseFile(theCase, createFile, user, defendant)
}

@UseGuards(
RolesGuard,
CaseExistsGuard,
CivilClaimantExistsGuard,
CaseWriteGuard,
)
@RolesRules() // This endpoint is not used by any role at the moment
@Post('civilClaimant/:civilClaimantId/file')
@ApiCreatedResponse({
type: CaseFile,
description: 'Creates a new case file connected to a civil claimant',
})
async createCivilClaimantCaseFile(
@Param('caseId') caseId: string,
@Param('civilClaimantId') civilClaimantId: string,
@CurrentHttpUser() user: User,
@CurrentCase() theCase: Case,
@CurrentCivilClaimant() civilClaimant: CivilClaimant,
@Body() createFile: CreateFileDto,
): Promise<CaseFile> {
this.logger.debug(
`Creating a file for case ${caseId} for civil claimant ${civilClaimantId}`,
)

return this.fileService.createCaseFile(
theCase,
createFile,
user,
undefined,
civilClaimant,
)
}

@UseGuards(
RolesGuard,
CaseExistsGuard,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { createConfirmedPdf } from '../../formatters'
import { AwsS3Service } from '../aws-s3'
import { Case } from '../case'
import { CourtDocumentFolder, CourtService } from '../court'
import { CivilClaimant, Defendant } from '../defendant'
import { UserService } from '../user'
import { CreateFileDto } from './dto/createFile.dto'
import { CreatePresignedPostDto } from './dto/createPresignedPost.dto'
Expand Down Expand Up @@ -339,6 +340,8 @@ export class FileService {
theCase: Case,
createFile: CreateFileDto,
user: User,
defendant?: Defendant,
civilClaimant?: CivilClaimant,
gudjong marked this conversation as resolved.
Show resolved Hide resolved
): Promise<CaseFile> {
const { key } = createFile

Expand All @@ -360,6 +363,8 @@ export class FileService {
userGeneratedFilename:
createFile.userGeneratedFilename ?? fileName.replace(/\.pdf$/, ''),
submittedBy: user.name,
defendantId: defendant?.id,
civilClaimantId: civilClaimant?.id,
})

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('LimitedAccess Write Case File Guard', () => {
})

describe.each(allowedCaseFileCategories)(
'a defender can view %s',
'a defender can write %s',
(category) => {
describe('when creating a case file', () => {
let then: Then
Expand Down Expand Up @@ -93,7 +93,7 @@ describe('LimitedAccess Write Case File Guard', () => {
(category) =>
!allowedCaseFileCategories.includes(category as CaseFileCategory),
),
)('a defender can not view %s', (category) => {
)('a defender can not write %s', (category) => {
describe('when creating a case file', () => {
let then: Then

Expand Down Expand Up @@ -137,7 +137,7 @@ describe('LimitedAccess Write Case File Guard', () => {
Object.keys(UserRole).filter((role) => role !== UserRole.DEFENDER),
)('role %s', (role) => {
describe.each(Object.keys(CaseFileCategory))(
'can not view %s',
'can not write %s',
(category) => {
describe('when creating a case file', () => {
let then: Then
Expand Down Expand Up @@ -225,7 +225,7 @@ describe('LimitedAccess Write Case File Guard', () => {
})
})

describe('a defender can view DEFENDANT_CASE_FILE in indictment cases', () => {
describe('a defender can write DEFENDANT_CASE_FILE in indictment cases', () => {
describe('when creating a case file', () => {
let then: Then

Expand Down Expand Up @@ -265,7 +265,7 @@ describe('LimitedAccess Write Case File Guard', () => {

describe.each(
Object.keys(CaseType).filter((ct) => ct !== CaseType.INDICTMENT),
)('a defender can not view DEFENDANT_CASE_FILE in %s cases', (caseType) => {
)('a defender can not write DEFENDANT_CASE_FILE in %s cases', (caseType) => {
describe('when creating a case file', () => {
let then: Then

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ import {
LimitedAccessCaseExistsGuard,
} from '../case'
import { MergedCaseExistsGuard } from '../case/guards/mergedCaseExists.guard'
import {
CivilClaimant,
CivilClaimantExistsGuard,
CurrentCivilClaimant,
} from '../defendant'
import { CreateFileDto } from './dto/createFile.dto'
import { CreatePresignedPostDto } from './dto/createPresignedPost.dto'
import { CurrentCaseFile } from './guards/caseFile.decorator'
Expand Down Expand Up @@ -108,6 +113,39 @@ export class LimitedAccessFileController {
return this.fileService.createCaseFile(theCase, createFile, user)
}

@UseGuards(
gudjong marked this conversation as resolved.
Show resolved Hide resolved
new CaseTypeGuard([...indictmentCases]),
CivilClaimantExistsGuard,
CaseWriteGuard,
LimitedAccessWriteCaseFileGuard,
)
@RolesRules(defenderRule)
@Post('civilClaimant/:civilClaimantId/file')
@ApiCreatedResponse({
type: CaseFile,
description: 'Creates a new case file for a civil claimant',
})
createCivilClaimantCaseFile(
@Param('caseId') caseId: string,
@Param('civilClaimantId') civilClaimantId: string,
@CurrentHttpUser() user: User,
@CurrentCase() theCase: Case,
@CurrentCivilClaimant() civilClaimant: CivilClaimant,
@Body() createFile: CreateFileDto,
): Promise<CaseFile> {
this.logger.debug(
`Creating a file for case ${caseId} and civil claimant ${civilClaimantId}`,
)

return this.fileService.createCaseFile(
theCase,
createFile,
user,
undefined,
civilClaimant,
)
}
gudjong marked this conversation as resolved.
Show resolved Hide resolved

@UseGuards(
CaseReadGuard,
MergedCaseExistsGuard,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {

// TODO Find a way to import from an index file
import { Case } from '../../case/models/case.model'
import { CivilClaimant, Defendant } from '../../defendant'

@Table({
tableName: 'case_file',
Expand Down Expand Up @@ -45,6 +46,16 @@ export class CaseFile extends Model {
@ApiProperty({ type: String })
caseId!: string

@ForeignKey(() => Defendant)
@Column({ type: DataType.UUID, allowNull: true })
@ApiProperty({ type: String })
defendantId?: string

@ForeignKey(() => CivilClaimant)
@Column({ type: DataType.UUID, allowNull: true })
@ApiProperty({ type: String })
civilClaimantId?: string

@Column({ type: DataType.STRING, allowNull: false })
@ApiProperty({ type: String })
name!: string
Expand Down
Loading
Loading