-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(j-s): Add punishment type to indictment overview (#17198)
* feat: add labels for new punishment type in indictment overview * feat(j-s): add punishment type ts type and remaining radio buttons * chore: nx format:write update dirty files * feat(j-s): add punishment type ts type and remaining radio buttons * fix * chore: nx format:write update dirty files * feat(j-s): add field to relevant models and fetch prop via graphql schema * chore: nx format:write update dirty files * refactor(j-s): add punishmentType to defendant update model * feat(j-s): Update defendant for fmst * feat(j-s): Add limited access defendant endpoint * fix(f-j): add roles rules to limited access defendant controller * feat(j-s): add new punishment type field to defendant * chore: nx format:write update dirty files * fix(j-s): clean-up after self-review * fix(j-s): formatting * fix(j-s): eslint and unsused imports * chore: nx format:write update dirty files * fix(j-s): linter * refactor(j-s): add tests and small fixes * fix(j-s): type import * fix(j-s): remove test case since the controller bypasses the decorator logic * chore: nx format:write update dirty files * fix(f-s): address feedback * fix(j-s): update the defendant state in working case --------- Co-authored-by: Thorhildur Thorleiksdottir <[email protected]> Co-authored-by: andes-it <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
c4bc9c4
commit e6a12da
Showing
22 changed files
with
507 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
apps/judicial-system/api/src/app/modules/defendant/limitedAccessDefendant.resolver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
apps/judicial-system/backend/migrations/20241211095654-update-defendant.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}), | ||
) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
apps/judicial-system/backend/src/app/modules/defendant/guards/rolesRules.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
64 changes: 64 additions & 0 deletions
64
apps/judicial-system/backend/src/app/modules/defendant/limitedAccessDefendant.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
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 { type 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' | ||
|
||
@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) | ||
@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: Pick<UpdateDefendantDto, 'punishmentType'>, | ||
): Promise<Defendant> { | ||
this.logger.debug( | ||
`Updating limitedAccess defendant ${defendantId} of case ${caseId}`, | ||
) | ||
return this.defendantService.updateRequestCaseDefendant( | ||
theCase, | ||
defendant, | ||
updateDto, | ||
user, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.