-
Notifications
You must be signed in to change notification settings - Fork 61
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): Add punishment type to indictment overview #17198
base: main
Are you sure you want to change the base?
Changes from 21 commits
67a2110
3858838
6676277
58479b4
1d65fb5
aad341a
0e43e2c
fb4fee0
dfedd76
92d77b9
bd07dcd
f30ac12
a72ba2a
5676d31
35d42c0
86b4ae4
caa07e6
768de8b
aa1ca4f
527b33b
f2198b6
60bd3a0
c26df00
96cb79f
ae5dfd5
449581e
0b994d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Inject, UseGuards } from '@nestjs/common' | ||
import { Args, Context, Mutation, 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 { UpdateDefendantInput } from './dto/updateDefendant.input' | ||
import { Defendant } from './models/defendant.model' | ||
|
||
@UseGuards(JwtGraphQlAuthGuard) | ||
@Resolver() | ||
export class LimitedAccessDefendantResolver { | ||
constructor( | ||
private readonly auditTrailService: AuditTrailService, | ||
@Inject(LOGGER_PROVIDER) | ||
private readonly logger: Logger, | ||
) {} | ||
|
||
@Mutation(() => Defendant, { nullable: true }) | ||
limitedAccessUpdateDefendant( | ||
@Args('input', { type: () => UpdateDefendantInput }) | ||
input: UpdateDefendantInput, | ||
@CurrentGraphQlUser() user: User, | ||
@Context('dataSources') | ||
{ backendService }: { backendService: BackendService }, | ||
): Promise<Defendant> { | ||
const { caseId, defendantId, ...updateDefendant } = input | ||
this.logger.debug( | ||
`Updating limitedAccess defendant ${defendantId} for case ${caseId}`, | ||
) | ||
|
||
return this.auditTrailService.audit( | ||
user.id, | ||
AuditedAction.UPDATE_DEFENDANT, | ||
backendService.limitedAccessUpdateDefendant( | ||
caseId, | ||
defendantId, | ||
updateDefendant, | ||
), | ||
defendantId, | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
async up(queryInterface, Sequelize) { | ||
return queryInterface.sequelize.transaction((t) => | ||
Promise.all([ | ||
queryInterface.addColumn( | ||
'defendant', | ||
'punishment_type', | ||
{ | ||
type: Sequelize.STRING, | ||
allowNull: true, | ||
}, | ||
{ transaction: t }, | ||
), | ||
]), | ||
) | ||
}, | ||
async down(queryInterface, Sequelize) { | ||
return queryInterface.sequelize.transaction((t) => | ||
queryInterface.removeColumn('defendant', 'punishment_type', { | ||
transaction: t, | ||
}), | ||
) | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { RolesRule, RulesType } from '@island.is/judicial-system/auth' | ||
import { UserRole } from '@island.is/judicial-system/types' | ||
|
||
import { UpdateDefendantDto } from '../dto/updateDefendant.dto' | ||
|
||
const limitedAccessFields: (keyof UpdateDefendantDto)[] = ['punishmentType'] | ||
|
||
// Allows prison staff to update a specific set of fields for defendant | ||
export const prisonSystemStaffUpdateRule: RolesRule = { | ||
role: UserRole.PRISON_SYSTEM_STAFF, | ||
type: RulesType.FIELD, | ||
dtoFields: limitedAccessFields, | ||
} | ||
thorhildurt marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Inject, | ||
Param, | ||
Patch, | ||
UseGuards, | ||
} from '@nestjs/common' | ||
import { ApiOkResponse, ApiTags } from '@nestjs/swagger' | ||
|
||
import type { Logger } from '@island.is/logging' | ||
import { LOGGER_PROVIDER } from '@island.is/logging' | ||
|
||
import { | ||
CurrentHttpUser, | ||
JwtAuthGuard, | ||
RolesGuard, | ||
RolesRules, | ||
} from '@island.is/judicial-system/auth' | ||
import { User } from '@island.is/judicial-system/types' | ||
|
||
import { Case, CaseExistsGuard, CurrentCase } from '../case' | ||
import { UpdateDefendantDto } from './dto/updateDefendant.dto' | ||
import { CurrentDefendant } from './guards/defendant.decorator' | ||
import { DefendantExistsGuard } from './guards/defendantExists.guard' | ||
import { prisonSystemStaffUpdateRule } from './guards/rolesRules' | ||
import { Defendant } from './models/defendant.model' | ||
import { DefendantService } from './defendant.service' | ||
|
||
interface LimitedAccessUpdateDefendant | ||
extends Pick<UpdateDefendantDto, 'punishmentType'> {} | ||
thorhildurt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
@Controller('api/case/:caseId/limitedAccess/defendant') | ||
@ApiTags('limited access defendant') | ||
@UseGuards(JwtAuthGuard, RolesGuard) | ||
export class LimitedAccessDefendantController { | ||
constructor( | ||
private readonly defendantService: DefendantService, | ||
@Inject(LOGGER_PROVIDER) private readonly logger: Logger, | ||
) {} | ||
|
||
@UseGuards(CaseExistsGuard, DefendantExistsGuard) | ||
@RolesRules(prisonSystemStaffUpdateRule) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will ensure that prison staff can only pass in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only added tests that check the Roles rules config but not a test that enforces the logic it applies. |
||
@Patch(':defendantId') | ||
@ApiOkResponse({ | ||
type: Defendant, | ||
description: 'Updates a defendant', | ||
}) | ||
updateDefendant( | ||
@Param('caseId') caseId: string, | ||
@Param('defendantId') defendantId: string, | ||
@CurrentHttpUser() user: User, | ||
@CurrentCase() theCase: Case, | ||
@CurrentDefendant() defendant: Defendant, | ||
@Body() updateDto: LimitedAccessUpdateDefendant, | ||
thorhildurt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): Promise<Defendant> { | ||
this.logger.debug( | ||
`Updating limitedAccess defendant ${defendantId} of case ${caseId}`, | ||
) | ||
|
||
return this.defendantService.updateRequestCaseDefendant( | ||
theCase, | ||
defendant, | ||
updateDto, | ||
user, | ||
) | ||
thorhildurt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the same value for the general update endpoint