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

chore(j-s): Security&Integrity #16863

Merged
merged 54 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
7158dda
Throws proper exceptions from digital mailbox
gudjong Nov 12, 2024
a096bdf
Refactors code
gudjong Nov 14, 2024
fa15f76
Refactors code
gudjong Nov 14, 2024
8a01c17
Refactors code
gudjong Nov 14, 2024
c980bdf
Merge branch 'main' of github.com:island-is/island.is into j-s/improv…
gudjong Nov 14, 2024
d18b483
Removes unused imports
gudjong Nov 14, 2024
0e03bfe
Removes unused imports
gudjong Nov 14, 2024
adc77fe
Removes unused import
gudjong Nov 14, 2024
d6ab433
Removes redundant code
gudjong Nov 15, 2024
3f1b67b
Merge branch 'main' of github.com:island-is/island.is into j-s/improv…
gudjong Nov 15, 2024
7b824ed
Merge branch 'main' of github.com:island-is/island.is into j-s/improv…
gudjong Nov 22, 2024
c7d1d98
Rewrites internal indictment case endpoint
gudjong Nov 22, 2024
b815229
Adds unit tests
gudjong Nov 22, 2024
f6b70c2
Merge branch 'main' of github.com:island-is/island.is into j-s/improv…
gudjong Nov 22, 2024
c57154a
Reorders query conditions
gudjong Nov 22, 2024
7dd133f
Rewrites defendant indictment cases endpoint
gudjong Nov 22, 2024
c2df5f6
Merge branch 'main' of github.com:island-is/island.is into j-s/improv…
gudjong Nov 22, 2024
34d2a25
Adds civil claimant exists guard to update and delete civil claimant
gudjong Nov 22, 2024
976bdc4
Merge branch 'main' of github.com:island-is/island.is into j-s/improv…
gudjong Nov 22, 2024
1ca021b
Removes unused endpoint
gudjong Nov 22, 2024
a6cce51
Uses proper subpoena gueard for limited access subpoena controller
gudjong Nov 22, 2024
25b461a
Splits subpoena exists guard and reorders controller decorators
gudjong Nov 22, 2024
6d17832
Adds unit test
gudjong Nov 22, 2024
106114d
Renames variables for clarity
gudjong Nov 24, 2024
4be9a94
Merge branch 'main' of github.com:island-is/island.is into j-s/improv…
gudjong Nov 24, 2024
24783de
Uses correct http method when getting cases
gudjong Nov 24, 2024
a790864
Moves subpoena status updates to subpoena module
gudjong Nov 25, 2024
9a18f02
Merge branch 'main' of github.com:island-is/island.is into j-s/improv…
gudjong Nov 25, 2024
684327e
Removes comments
gudjong Nov 26, 2024
f8be4f9
Removes comments
gudjong Nov 26, 2024
ff843aa
Adds unit tests
gudjong Nov 26, 2024
764c1a6
Renames unit test
gudjong Nov 26, 2024
582784b
Updates unit tests
gudjong Nov 26, 2024
f7181f8
Refactors code
gudjong Nov 26, 2024
24b6c5e
Adds unit tests
gudjong Nov 26, 2024
8c757ec
Adds unit tests
gudjong Nov 26, 2024
720dada
Fixes subpoena refresh
gudjong Nov 26, 2024
1996260
Cleans up some code
gudjong Nov 26, 2024
51ab701
Removes unnecessary export
gudjong Nov 26, 2024
99de031
Rmoves console log.
gudjong Nov 26, 2024
62128a9
Update apps/judicial-system/backend/src/app/modules/case/guards/test/…
unakb Nov 27, 2024
b8526a5
Updates unit test
gudjong Nov 27, 2024
ae68416
Fixes type import
gudjong Nov 27, 2024
e86322d
Fixes typo
gudjong Nov 27, 2024
ea60915
Fixes typo
gudjong Nov 27, 2024
ca5cac9
Fixes type decorators
gudjong Nov 27, 2024
a6e0ae6
Fixes typo
gudjong Nov 27, 2024
427a190
Merge branch 'main' of github.com:island-is/island.is into j-s/improv…
gudjong Nov 27, 2024
f2a87ee
Merge branch 'main' of github.com:island-is/island.is into j-s/improv…
gudjong Nov 28, 2024
2d2cfde
Merge branch 'main' into j-s/improved-security
unakb Dec 2, 2024
a92bd7f
Refactors code
gudjong Dec 3, 2024
cce02a1
Merge branch 'main' into j-s/improved-security
gudjong Dec 3, 2024
7b92849
Rewrites subpoena info diff
gudjong Dec 3, 2024
ccef389
Merge branch 'main' into j-s/improved-security
kodiakhq[bot] Dec 3, 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
2 changes: 2 additions & 0 deletions apps/judicial-system/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
IndictmentCountModule,
InstitutionModule,
PoliceModule,
SubpoenaModule,
UserModule,
} from './modules'

Expand Down Expand Up @@ -68,6 +69,7 @@ const autoSchemaFile = production
CaseListModule,
DefendantModule,
DefenderModule,
SubpoenaModule,
unakb marked this conversation as resolved.
Show resolved Hide resolved
IndictmentCountModule,
FileModule,
InstitutionModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ import { Institution } from '../institution'
import {
PoliceCaseFile,
PoliceCaseInfo,
SubpoenaStatus,
UploadPoliceCaseFileResponse,
} from '../police'
import { Subpoena } from '../subpoena'
import { backendModuleConfig } from './backend.config'

@Injectable()
Expand Down Expand Up @@ -326,13 +326,6 @@ export class BackendService extends DataSource<{ req: Request }> {
return this.get(`case/${caseId}/policeFiles`)
}

getSubpoenaStatus(
caseId: string,
subpoenaId: string,
): Promise<SubpoenaStatus> {
return this.get(`case/${caseId}/subpoenaStatus/${subpoenaId}`)
}

getPoliceCaseInfo(caseId: string): Promise<PoliceCaseInfo[]> {
return this.get(`case/${caseId}/policeCaseInfo`)
}
Expand Down Expand Up @@ -369,6 +362,16 @@ export class BackendService extends DataSource<{ req: Request }> {
return this.delete(`case/${caseId}/defendant/${defendantId}`)
}

getSubpoena(
caseId: string,
defendantId: string,
subpoenaId: string,
): Promise<Subpoena> {
return this.get(
`case/${caseId}/defendant/${defendantId}/subpoena/${subpoenaId}`,
)
}

createCivilClaimant(
caseId: string,
createCivilClaimant: unknown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ export { Defendant } from './models/defendant.model'
export { DeleteDefendantResponse } from './models/delete.response'
export { CivilClaimant } from './models/civilClaimant.model'
export { DeleteCivilClaimantResponse } from './models/deleteCivilClaimant.response'
export { Subpoena } from './models/subpoena.model'
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
SubpoenaType,
} from '@island.is/judicial-system/types'

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

registerEnumType(Gender, { name: 'Gender' })
registerEnumType(DefendantPlea, { name: 'DefendantPlea' })
Expand Down
1 change: 1 addition & 0 deletions apps/judicial-system/api/src/app/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export { EventLogModule } from './event-log/eventLog.module'
export { backendModuleConfig } from './backend/backend.config'
export { BackendService } from './backend/backend.service'
export { BackendModule } from './backend/backend.module'
export { SubpoenaModule } from './subpoena/subpoena.module'
1 change: 0 additions & 1 deletion apps/judicial-system/api/src/app/modules/police/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export { PoliceCaseInfo } from './models/policeCaseInfo.model'
export { SubpoenaStatus } from './models/subpoenaStatus.model'
export { PoliceCaseFile } from './models/policeCaseFile.model'
export { UploadPoliceCaseFileResponse } from './models/uploadPoliceCaseFile.response'

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ import type { User } from '@island.is/judicial-system/types'
import { BackendService } from '../backend'
import { PoliceCaseFilesQueryInput } from './dto/policeCaseFiles.input'
import { PoliceCaseInfoQueryInput } from './dto/policeCaseInfo.input'
import { SubpoenaStatusQueryInput } from './dto/subpoenaStatus.input'
import { UploadPoliceCaseFileInput } from './dto/uploadPoliceCaseFile.input'
import { PoliceCaseFile } from './models/policeCaseFile.model'
import { PoliceCaseInfo } from './models/policeCaseInfo.model'
import { SubpoenaStatus } from './models/subpoenaStatus.model'
import { UploadPoliceCaseFileResponse } from './models/uploadPoliceCaseFile.response'

@UseGuards(JwtGraphQlAuthGuard)
Expand Down Expand Up @@ -51,26 +49,6 @@ export class PoliceResolver {
)
}

@Query(() => SubpoenaStatus, { nullable: true })
subpoenaStatus(
@Args('input', { type: () => SubpoenaStatusQueryInput })
input: SubpoenaStatusQueryInput,
@CurrentGraphQlUser() user: User,
@Context('dataSources')
{ backendService }: { backendService: BackendService },
): Promise<SubpoenaStatus> {
this.logger.debug(
`Getting subpoena status for subpoena ${input.subpoenaId} of case ${input.caseId}`,
)

return this.auditTrailService.audit(
user.id,
AuditedAction.GET_SUBPOENA_STATUS,
backendService.getSubpoenaStatus(input.caseId, input.subpoenaId),
input.caseId,
)
}

@Query(() => [PoliceCaseInfo], { nullable: true })
policeCaseInfo(
@Args('input', { type: () => PoliceCaseInfoQueryInput })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { Allow } from 'class-validator'
import { Field, ID, InputType } from '@nestjs/graphql'

@InputType()
export class SubpoenaStatusQueryInput {
export class SubpoenaQueryInput {
@Allow()
@Field(() => ID)
readonly caseId!: string

@Allow()
@Field(() => ID)
readonly defendantId!: string

@Allow()
@Field(() => ID)
readonly subpoenaId!: string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Subpoena } from './models/subpoena.model'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common'

import { SubpoenaResolver } from './subpoena.resolver'

@Module({
providers: [SubpoenaResolver],
})
export class SubpoenaModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Inject, UseGuards } from '@nestjs/common'
import { Args, Context, Query, Resolver } from '@nestjs/graphql'

import type { Logger } from '@island.is/logging'
import { LOGGER_PROVIDER } from '@island.is/logging'

import {
AuditedAction,
AuditTrailService,
} from '@island.is/judicial-system/audit-trail'
import {
CurrentGraphQlUser,
JwtGraphQlAuthGuard,
} from '@island.is/judicial-system/auth'
import type { User } from '@island.is/judicial-system/types'

import { BackendService } from '../backend'
import { SubpoenaQueryInput } from './dto/subpoena.input'
import { Subpoena } from './models/subpoena.model'

@UseGuards(JwtGraphQlAuthGuard)
@Resolver()
export class SubpoenaResolver {
constructor(
private readonly auditTrailService: AuditTrailService,
@Inject(LOGGER_PROVIDER)
private readonly logger: Logger,
) {}

@Query(() => Subpoena, { nullable: true })
subpoena(
@Args('input', { type: () => SubpoenaQueryInput })
input: SubpoenaQueryInput,
@CurrentGraphQlUser() user: User,
@Context('dataSources')
{ backendService }: { backendService: BackendService },
): Promise<Subpoena> {
this.logger.debug(
`Getting subpoena ${input.subpoenaId} for defendant ${input.defendantId} of case ${input.caseId}`,
)
unakb marked this conversation as resolved.
Show resolved Hide resolved

return this.auditTrailService.audit(
user.id,
AuditedAction.GET_SUBPOENA,
backendService.getSubpoena(
input.caseId,
input.defendantId,
input.subpoenaId,
),
input.caseId,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export class CaseController {
)
@UseInterceptors(CompletedAppealAccessedInterceptor, CaseInterceptor)
@Get('case/:caseId')
@ApiOkResponse({ type: Case, description: 'Gets an existing case' })
@ApiOkResponse({ type: Case, description: 'Gets an existing case by id' })
getById(@Param('caseId') caseId: string, @CurrentCase() theCase: Case): Case {
this.logger.debug(`Getting case ${caseId} by id`)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ const getPrisonStaffUserCasesQueryFilter = (): WhereOptions => {
return {
[Op.and]: [
{ is_archived: false },
{ state: CaseState.ACCEPTED },
{
type: [
CaseType.CUSTODY,
CaseType.ADMISSION_TO_FACILITY,
CaseType.PAROLE_REVOCATION,
],
},
{ state: CaseState.ACCEPTED },
unakb marked this conversation as resolved.
Show resolved Hide resolved
{ decision: [CaseDecision.ACCEPTING, CaseDecision.ACCEPTING_PARTIALLY] },
],
}
Expand All @@ -205,8 +205,8 @@ const getPrisonAdminUserCasesQueryFilter = (): WhereOptions => {
is_archived: false,
[Op.or]: [
{
state: CaseState.ACCEPTED,
type: [...restrictionCases, CaseType.PAROLE_REVOCATION],
state: CaseState.ACCEPTED,
},
{
type: indictmentCases,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,14 @@ describe('getCasesQueryFilter', () => {
expect(res).toStrictEqual({
[Op.and]: [
{ is_archived: false },
{ state: CaseState.ACCEPTED },
{
type: [
CaseType.CUSTODY,
CaseType.ADMISSION_TO_FACILITY,
CaseType.PAROLE_REVOCATION,
],
},
{ state: CaseState.ACCEPTED },
{
decision: [CaseDecision.ACCEPTING, CaseDecision.ACCEPTING_PARTIALLY],
},
Expand Down Expand Up @@ -382,8 +382,8 @@ describe('getCasesQueryFilter', () => {

[Op.or]: [
{
state: CaseState.ACCEPTED,
type: [...restrictionCases, CaseType.PAROLE_REVOCATION],
state: CaseState.ACCEPTED,
},
{
type: indictmentCases,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
BadRequestException,
CanActivate,
ExecutionContext,
Injectable,
} from '@nestjs/common'

import { InternalCaseService } from '../internalCase.service'

@Injectable()
export class IndictmentCaseExistsForDefendantGuard implements CanActivate {
constructor(private readonly internalCaseService: InternalCaseService) {}

async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest()

const caseId = request.params.caseId

if (!caseId) {
throw new BadRequestException('Missing case id')
}

const defendantNationalId = request.params.defendantNationalId

if (!defendantNationalId) {
throw new BadRequestException('Missing defendant national id')
}

request.case =
await this.internalCaseService.findByIdAndDefendantNationalId(
caseId,
defendantNationalId,
)

return true
}
gudjong marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class MergedCaseExistsGuard implements CanActivate {
)

if (!mergedCase) {
throw new BadRequestException('Merged case not found')
throw new BadRequestException(`Merged case ${mergedCaseId} not found`)
}

request.mergedCaseParent = theCase
Expand Down
Loading
Loading