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): Send to prison admin #16831

Merged
merged 78 commits into from
Nov 25, 2024
Merged

feat(j-s): Send to prison admin #16831

merged 78 commits into from
Nov 25, 2024

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Nov 13, 2024

Send to prison admin

Asana

What

This is the first draft of our "Send to prison admin" functionality. In this first version, public prosecutor staff can send (and revoke) cases to/from prison admins.

What comes later is being able to upload a document that commonly is sent with these types of requests.

Why

Sometimes, defendants want to start their sentence earlier. This change enables PP to do so.

Screenshots / Gifs

Screen.Recording.2024-11-18.at.14.34.46.mov

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

Release Notes

  • New Features

    • Added optional fields isSentToPrisonAdmin and sentToPrisonAdminDate to the defendant and case models, enhancing tracking of defendants sent to prison administration.
    • Introduced DefendantEventLog model to log events related to defendants.
    • New UI components and strings for sending information to prison administration.
    • Enhanced role-based access control for file handling, allowing public prosecutors to create presigned posts and case files.
    • Added loading state to modal components for improved user experience.
    • Introduced a new route for public prosecutors to send indictments to prison administration.
  • Bug Fixes

    • Improved loading state management in modal components.
  • Documentation

    • Expanded error messages for file upload failures.
  • Style

    • Updated localization strings for better clarity and context.
  • Tests

    • Added new test cases for access permissions based on defendant status and refined notification logic for email sending scenarios.

Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

Walkthrough

The pull request introduces several enhancements to the judicial system's backend and frontend components. Key changes include the addition of new fields related to defendants, specifically concerning their status with the prison administration. New models, migrations, and GraphQL schema updates are implemented to support these features. Additionally, various components and services are updated to integrate event logging and improve role-based access control. This update aims to streamline the handling of defendant information and enhance the overall functionality of the judicial system application.

Changes

File Change Summary
apps/judicial-system/api/src/app/modules/defendant/dto/updateDefendant.input.ts Added optional field isSentToPrisonAdmin to UpdateDefendantInput class.
apps/judicial-system/api/src/app/modules/defendant/models/defendant.model.ts Added fields isSentToPrisonAdmin and sentToPrisonAdminDate to Defendant class.
apps/judicial-system/backend/migrations/20241112125245-update-defendant.js Created migration to add is_sent_to_prison_admin column to defendant table.
apps/judicial-system/backend/migrations/20241114123528-create-defendant-event-log.js Created migration for defendant_event_log table with multiple fields including foreign keys.
apps/judicial-system/backend/src/app/modules/case/case.service.ts Updated UpdateCase interface to include defendantWaivesRightToCounsel. Integrated DefendantEventLog in Sequelize queries.
apps/judicial-system/backend/src/app/modules/case/filters/case.filter.ts Modified access check logic to focus on defendants sent to prison admin.
apps/judicial-system/backend/src/app/modules/case/filters/cases.filter.ts Updated SQL query to filter cases based on is_sent_to_prison_admin instead of date fields.
apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts Removed VERDICT_APPEAL_WINDOW_DAYS constant and updated test logic for prison admin access.
apps/judicial-system/backend/src/app/modules/case/filters/test/prisonAdminUserFilter.spec.ts Added new test cases to verify access based on defendant status regarding prison admin.
apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts Updated to include DefendantEventLog in include array for Sequelize queries.
apps/judicial-system/backend/src/app/modules/defendant/defendant.module.ts Added DefendantEventLog model to Sequelize feature imports.
apps/judicial-system/backend/src/app/modules/defendant/defendant.service.ts Enhanced updateIndictmentCaseDefendant to log events when isSentToPrisonAdmin is true.
apps/judicial-system/backend/src/app/modules/defendant/dto/updateDefendant.dto.ts Added optional property isSentToPrisonAdmin to UpdateDefendantDto class.
apps/judicial-system/web/messages/Core/errors.ts Added new error message uploadFailed for file upload failures.
apps/judicial-system/web/pages/rikissaksoknari/akaera/senda-til-fmst/[id]/[defendantId].ts Introduced a new file that exports SendToPrisonAdmin component.
apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.strings.ts Updated localization strings and added new messages related to sending to prison admin.
apps/judicial-system/web/src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx Refactored state management for dates and added functions for sending and revoking prison admin actions.
apps/judicial-system/web/src/components/FormProvider/case.graphql Added fields isSentToPrisonAdmin and sentToPrisonAdminDate to the defendants object in the Case query.
apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql Added fields isSentToPrisonAdmin and sentToPrisonAdminDate to the defendants object in the LimitedAccessCase query.
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.strings.ts Added new message sendToPrisonAdminDate for displaying when a case was sent for enforcement.
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.tsx Added optional property displaySentToPrisonAdminDate to conditionally render the prison admin date.
apps/judicial-system/web/src/components/InfoCard/InfoCardClosedIndictment.tsx Added optional property displaySentToPrisonAdminDate to handle display logic.
apps/judicial-system/web/src/components/InfoCard/useInfoCardItems.tsx Updated defendants function to accept displaySentToPrisonAdminDate parameter.
apps/judicial-system/web/src/components/Modal/Modal.tsx Added loading property to manage modal loading state.
apps/judicial-system/web/src/components/SectionHeading/SectionHeading.tsx Updated description prop type to accept both ReactNode and string.
apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/Overview/Overview.tsx Updated props for components to reflect changes in data structure.
apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/SendToPrisonAdmin/SendToPrisonAdmin.strings.ts Introduced new localization strings for sending to prison admin feature.
apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/SendToPrisonAdmin/SendToPrisonAdmin.tsx Added a new component for handling the sending of defendant information to prison admin.
apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesReviewed.strings.ts Added new message tagVerdictViewSentToPrisonAdmin for case review tags.
apps/judicial-system/web/src/routes/PublicProsecutor/Tables/CasesReviewed.tsx Updated logic for verdict view tags based on defendants sent to prison admin.
apps/judicial-system/web/src/routes/Shared/Cases/cases.graphql Added isSentToPrisonAdmin field to the defendants object in the Cases query.
apps/judicial-system/web/src/utils/hooks/useDefendants/index.ts Added loading state for updateDefendantMutation.
apps/judicial-system/web/src/utils/hooks/useEventLog/index.ts Restructured return statement for clarity in useEventLog hook.
libs/judicial-system/consts/src/lib/consts.ts Added constant for public prosecutor route to send to prison admin.
libs/judicial-system/types/src/index.ts Updated exports to include DefendantEventType and defendantEventTypes.
libs/judicial-system/types/src/lib/eventLog.ts Introduced DefendantEventType enum and defendantEventTypes constant.
libs/judicial-system/types/src/lib/file.ts Added SENT_TO_PRISON_ADMIN_FILE value to CaseFileCategory enum.
apps/judicial-system/backend/src/app/modules/case/interceptors/case.interceptor.ts Added transformDefendants function to process defendants with additional details.
apps/judicial-system/backend/src/app/modules/case/interceptors/caseList.interceptor.ts Updated to use transformDefendants for processing defendants in case list.
apps/judicial-system/backend/src/app/modules/defendant/index.ts Exported DefendantEventLog entity from the module.
apps/judicial-system/backend/src/app/modules/defendant/models/defendantEventLog.model.ts Introduced DefendantEventLog model with properties and methods for event logging.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • oddsson

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Nov 13, 2024

Codecov Report

Attention: Patch coverage is 25.45455% with 123 lines in your changes missing coverage. Please review.

Project coverage is 35.82%. Comparing base (e0596d3) to head (0932693).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...src/components/BlueBoxWithIcon/BlueBoxWithDate.tsx 0.00% 50 Missing ⚠️
...ndictments/SendToPrisonAdmin/SendToPrisonAdmin.tsx 0.00% 33 Missing ⚠️
...c/routes/PublicProsecutor/Tables/CasesReviewed.tsx 0.00% 15 Missing ⚠️
...odules/defendant/models/defendantEventLog.model.ts 70.58% 5 Missing ⚠️
...rc/app/modules/defendant/models/defendant.model.ts 0.00% 4 Missing ⚠️
.../app/modules/case/interceptors/case.interceptor.ts 40.00% 3 Missing ⚠️
...app/modules/defendant/dto/updateDefendant.input.ts 0.00% 2 Missing ⚠️
...rc/app/modules/defendant/models/defendant.model.ts 60.00% 2 Missing ⚠️
...b/src/components/SectionHeading/SectionHeading.tsx 0.00% 2 Missing ⚠️
...kend/src/app/modules/defendant/defendant.module.ts 0.00% 1 Missing ⚠️
... and 6 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16831      +/-   ##
==========================================
+ Coverage   35.59%   35.82%   +0.22%     
==========================================
  Files        6920     6910      -10     
  Lines      146146   145992     -154     
  Branches    41516    41616     +100     
==========================================
+ Hits        52021    52295     +274     
+ Misses      94125    93697     -428     
Flag Coverage Δ
judicial-system-api 20.01% <60.00%> (+0.15%) ⬆️
judicial-system-backend 55.58% <76.47%> (+0.01%) ⬆️
judicial-system-formatters 79.54% <100.00%> (+0.19%) ⬆️
judicial-system-message 67.05% <ø> (ø)
judicial-system-message-handler 48.08% <ø> (ø)
judicial-system-scheduler 70.99% <100.00%> (+0.19%) ⬆️
judicial-system-types 42.94% <11.11%> (-0.38%) ⬇️
judicial-system-web 27.08% <3.66%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...al-system/backend/src/app/formatters/formatters.ts 97.53% <ø> (ø)
...ystem/backend/src/app/modules/case/case.service.ts 90.75% <100.00%> (ø)
...ackend/src/app/modules/case/filters/case.filter.ts 89.93% <100.00%> (+1.04%) ⬆️
...ckend/src/app/modules/case/filters/cases.filter.ts 97.91% <ø> (ø)
.../modules/case/interceptors/caseList.interceptor.ts 46.66% <100.00%> (+3.80%) ⬆️
.../src/app/modules/case/limitedAccessCase.service.ts 72.56% <ø> (ø)
...c/app/modules/defendant/dto/updateDefendant.dto.ts 93.10% <100.00%> (+0.24%) ⬆️
...-system/backend/src/app/modules/defendant/index.ts 100.00% <100.00%> (ø)
...les/defendant/test/createTestingDefendantModule.ts 100.00% <100.00%> (ø)
...em/backend/src/app/modules/file/file.controller.ts 100.00% <ø> (ø)
... and 30 more

... and 65 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e0596d3...0932693. Read the comment docs.

---- 🚨 Try these New Features:

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 13, 2024

Datadog Report

All test runs 399e7c0 🔗

9 Total Test Services: 0 Failed, 9 Passed
🔻 Test Sessions change in coverage: 2 decreased, 5 increased, 5 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
judicial-system-api 0 0 0 59 0 5.26s 1 increased (+0.16%) Link
judicial-system-backend 0 0 0 21321 0 17m 4.39s 1 increased (+0.04%) Link
judicial-system-formatters 0 0 0 38 0 4.87s 1 increased (+0.13%) Link
judicial-system-message 0 0 0 36 0 9.44s 1 no change Link
judicial-system-message-handler 0 0 0 4 0 3.19s 1 no change Link
judicial-system-scheduler 0 0 0 4 0 3.82s 1 increased (+0.17%) Link
judicial-system-types 0 0 0 23 0 6.01s 1 decreased (-0.44%) Link
judicial-system-web 0 0 0 333 0 56.77s 1 decreased (-0.17%) Link
judicial-system-xrd-api 0 0 0 6 0 4.83s 1 increased (+0.15%) Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • judicial-system-types - jest 45.9% (-0.44%) - Details
  • judicial-system-web - jest 31.3% (-0.17%) - Details

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (9)
apps/judicial-system/backend/src/app/modules/defendant/index.ts (1)

5-5: Consider grouping related exports together.

The new DefendantEventLog export should be grouped with other defendant-related exports for better code organization and maintainability.

Consider this reorganization:

 export { Defendant } from './models/defendant.model'
+export { DefendantEventLog } from './models/defendantEventLog.model'
 export { DefendantService } from './defendant.service'
 export { DefendantExistsGuard } from './guards/defendantExists.guard'
 export { CurrentDefendant } from './guards/defendant.decorator'
-export { DefendantEventLog } from './models/defendantEventLog.model'

 export { CivilClaimant } from './models/civilClaimant.model'
 export { CivilClaimantService } from './civilClaimant.service'
libs/judicial-system/types/src/lib/eventLog.ts (1)

15-20: Consider documenting the event types

Since these event types are used across different parts of the judicial system, it would be helpful to add JSDoc comments explaining when each event type is triggered and its significance.

Example documentation:

 export enum DefendantEventType {
+  /** Logged when a case is sent to prison administration for early sentence processing */
   SENT_TO_PRISON_ADMIN = 'SENT_TO_PRISON_ADMIN',
 }
apps/judicial-system/backend/src/app/modules/defendant/models/defendantEventLog.model.ts (2)

57-64: Consider adding a default value for the eventType enum.

While the column configuration is correct, consider adding a default value to ensure consistent behavior during record creation.

 @Column({
   type: DataType.ENUM,
   allowNull: false,
   values: Object.values(DefendantEventType),
+  defaultValue: DefendantEventType.SENT_TO_PRISON_ADMIN,
 })
 @ApiProperty({ enum: DefendantEventType })
 eventType!: DefendantEventType

1-64: Consider adding indexes for performance optimization.

Given that this model will be queried to find the latest prison admin status, consider adding indexes to improve query performance.

Add the following to your migration file:

  1. Index on (defendantId, eventType) for efficient status lookups
  2. Index on (caseId, eventType) if you need to query by case
apps/judicial-system/backend/src/app/modules/case/interceptors/caseList.interceptor.ts (2)

Line range hint 26-28: Document the security review process for new fields

The warning comment highlights the importance of careful consideration when exposing data. Consider enhancing this comment to:

  1. Document the security review process for adding new fields
  2. List which fields are considered sensitive
  3. Reference the relevant security policies

Line range hint 20-71: Consider paginating the case list response

The interceptor transforms the entire cases array at once. Given that this endpoint returns a list of cases with substantial data per case, consider implementing pagination to:

  1. Improve performance for large datasets
  2. Reduce memory usage
  3. Enhance response times
apps/judicial-system/backend/src/app/modules/defendant/models/defendant.model.ts (1)

204-206: Well-structured relationship definition!

The HasMany relationship to DefendantEventLog is correctly implemented and follows best practices by allowing efficient access to event logs through the model relationship instead of direct database queries.

This implementation improves performance by enabling eager loading of event logs when needed, reducing the number of database queries.

apps/judicial-system/backend/src/app/modules/case/case.service.ts (2)

43-43: Consider adding validation for the new field

The defendantWaivesRightToCounsel field is added to track whether a defendant has waived their right to counsel. Consider adding validation to ensure this field can only be set under appropriate conditions.

Consider adding a validation check:

if (update.defendantWaivesRightToCounsel !== undefined) {
  // Validate that this can only be set in appropriate case states
  if (![CaseState.NEW, CaseState.DRAFT].includes(theCase.state)) {
    throw new BadRequestException('Cannot modify right to counsel waiver in current case state')
  }
}

294-301: Consider adding an index on eventType

The query filters on eventType column. Adding an index would improve query performance, especially as the number of event logs grows.

Consider adding an index in your database migration:

// In your migration file
await queryInterface.addIndex('defendant_event_log', ['event_type'], {
  name: 'idx_defendant_event_log_event_type'
});
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a303e84 and 402f584.

📒 Files selected for processing (11)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/case/interceptors/case.interceptor.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/interceptors/caseList.interceptor.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/defendant.module.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/defendant.service.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/index.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/models/defendant.model.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/models/defendantEventLog.model.ts (1 hunks)
  • libs/judicial-system/types/src/index.ts (1 hunks)
  • libs/judicial-system/types/src/lib/eventLog.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts
  • apps/judicial-system/backend/src/app/modules/defendant/defendant.module.ts
  • apps/judicial-system/backend/src/app/modules/defendant/defendant.service.ts
  • libs/judicial-system/types/src/index.ts
🧰 Additional context used
📓 Path-based instructions (7)
apps/judicial-system/backend/src/app/modules/case/case.service.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/case/interceptors/case.interceptor.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/case/interceptors/caseList.interceptor.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/defendant/index.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/defendant/models/defendant.model.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/defendant/models/defendantEventLog.model.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
libs/judicial-system/types/src/lib/eventLog.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
📓 Learnings (4)
apps/judicial-system/backend/src/app/modules/case/case.service.ts (1)
Learnt from: oddsson
PR: island-is/island.is#16831
File: apps/judicial-system/api/src/app/modules/case/models/defendantEventLog.model.ts:6-22
Timestamp: 2024-11-18T21:50:40.004Z
Learning: In `apps/judicial-system/api/src/app/modules`, new models should be created following the existing patterns used in the API to maintain consistency.
apps/judicial-system/backend/src/app/modules/defendant/index.ts (2)
Learnt from: oddsson
PR: island-is/island.is#16831
File: apps/judicial-system/api/src/app/modules/case/models/defendantEventLog.model.ts:6-22
Timestamp: 2024-11-18T21:50:40.004Z
Learning: In `apps/judicial-system/api/src/app/modules`, new models should be created following the existing patterns used in the API to maintain consistency.
Learnt from: oddsson
PR: island-is/island.is#16831
File: apps/judicial-system/backend/src/app/modules/defendant/models/defendant.model.ts:0-0
Timestamp: 2024-11-19T09:04:44.520Z
Learning: Additional documentation is not required when the code is clear and self-explanatory.
apps/judicial-system/backend/src/app/modules/defendant/models/defendant.model.ts (1)
Learnt from: oddsson
PR: island-is/island.is#16831
File: apps/judicial-system/api/src/app/modules/case/models/defendantEventLog.model.ts:6-22
Timestamp: 2024-11-18T21:50:40.004Z
Learning: In `apps/judicial-system/api/src/app/modules`, new models should be created following the existing patterns used in the API to maintain consistency.
apps/judicial-system/backend/src/app/modules/defendant/models/defendantEventLog.model.ts (2)
Learnt from: oddsson
PR: island-is/island.is#16831
File: apps/judicial-system/api/src/app/modules/case/models/defendantEventLog.model.ts:6-22
Timestamp: 2024-11-18T21:50:40.004Z
Learning: In `apps/judicial-system/api/src/app/modules`, new models should be created following the existing patterns used in the API to maintain consistency.
Learnt from: oddsson
PR: island-is/island.is#16831
File: apps/judicial-system/backend/migrations/20241114123528-create-defendant-event-log.js:0-0
Timestamp: 2024-11-18T21:57:03.051Z
Learning: In the `apps/judicial-system/backend` codebase, validations are not typically included in Sequelize migration files.
🔇 Additional comments (12)
libs/judicial-system/types/src/lib/eventLog.ts (1)

16-18: LGTM!

The new DefendantEventType enum follows TypeScript best practices and maintains consistency with existing naming patterns.

apps/judicial-system/backend/src/app/modules/case/interceptors/case.interceptor.ts (3)

10-10: LGTM: Imports are properly structured

The new imports for Defendant and DefendantEventLog are correctly added and align with the new prison admin functionality.


26-26: LGTM: Case transformation properly integrated

The integration of transformDefendants into the case transformation is clean and aligns with the PR objectives for prison admin functionality.


Line range hint 35-41: Verify interceptor behavior with transformed data

Please ensure that the interceptor correctly handles all edge cases with the new defendant transformation.

apps/judicial-system/backend/src/app/modules/defendant/models/defendantEventLog.model.ts (3)

1-17: LGTM! Well-organized imports.

The imports are properly organized, with clear separation between external dependencies and internal modules.


18-22: LGTM! Proper table configuration.

The table configuration follows best practices with appropriate naming convention and audit trail support through timestamps.


30-56: LGTM! Well-structured model properties.

The model properties are well-defined with appropriate types, constraints, and documentation.

apps/judicial-system/backend/src/app/modules/case/interceptors/caseList.interceptor.ts (1)

15-15: Verify the security implications of defendant data transformation

The change introduces a new way of processing defendant data. Given the PR's context about prison administration functionality:

  1. Ensure the transformDefendants function properly sanitizes sensitive prison-related information
  2. Verify that the transformed data aligns with role-based access control requirements

Also applies to: 33-33

✅ Verification successful

Let's examine the implementation of transformDefendants more closely to understand its security implications.


Based on the code analysis, I can now provide a definitive response about the security implications of the defendant data transformation.

The defendant data transformation is safe and properly scoped

The transformDefendants function performs a simple and secure transformation that:

  1. Only exposes already existing defendant data through toJSON()
  2. Adds a single timestamp field setnToPrisonAdminDate from event logs
  3. Does not expose any sensitive prison-related information beyond what's already authorized

The transformation is used consistently in both the case and list interceptors, maintaining the same level of data access control across the application.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Analyze the transformDefendants implementation and its security implications

# Check the implementation of transformDefendants
ast-grep --pattern 'function transformDefendants($_) {
  $$$
}'

# Look for security-related tests
rg -l "describe.*transformDefendants" -g "*.spec.ts"

# Check for role-based access control tests
rg "isSentToPrisonAdmin|transformDefendants" -g "*.(spec|test).ts" -A 5

Length of output: 343


Script:

#!/bin/bash
# Let's try a different approach to locate and analyze the transformDefendants function

# Find the file containing transformDefendants
rg -l "transformDefendants" --type ts

# Once found, examine its implementation and usage
rg "transformDefendants" --type ts -A 5

# Look for any security or access control related code nearby
rg "transformDefendants|security|access|permission|role" --type ts -C 5

Length of output: 103588


Script:

#!/bin/bash
# Let's look at the case.interceptor.ts file content to analyze the transformDefendants function
rg -A 10 "transformDefendants" apps/judicial-system/backend/src/app/modules/case/interceptors/case.interceptor.ts

# Check for any security-related tests
rg -l "transformDefendants.*test|test.*transformDefendants" -g "*.spec.ts"

# Look for DefendantEventLog usage to understand what data is being transformed
rg "DefendantEventLog" -A 5 apps/judicial-system/backend/src/app/modules/case

Length of output: 4984

apps/judicial-system/backend/src/app/modules/defendant/models/defendant.model.ts (2)

26-26: LGTM!

The import follows the established pattern for model imports.


200-202: LGTM!

The column definition follows the established pattern and correctly implements the "Send to prison admin" feature with appropriate type and decorators.

apps/judicial-system/backend/src/app/modules/case/case.service.ts (2)

43-43: LGTM: Import changes are well-organized

The new imports for defendant event types and models are properly organized and support the prison admin feature requirements.

Also applies to: 63-68


294-301: LGTM: Well-implemented event logs inclusion

The DefendantEventLog inclusion is properly implemented with performance considerations (separate: true) and correct ordering.

coderabbitai[bot]
coderabbitai bot previously requested changes Nov 21, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
apps/judicial-system/backend/src/app/modules/case/interceptors/case.interceptor.ts (1)

14-26: Consider implementing event-driven updates

The current implementation handles the prison admin status through data transformation. For a more scalable solution, consider:

  1. Implementing an event-driven system for status updates
  2. Adding a caching layer for frequently accessed defendant statuses
  3. Creating a dedicated service for prison admin-related operations

This would improve maintainability and prepare the system for future features mentioned in the PR objectives (e.g., document uploads).

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 402f584 and 719bfbd.

📒 Files selected for processing (3)
  • apps/judicial-system/backend/src/app/modules/case/filters/cases.filter.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/interceptors/case.interceptor.ts (1 hunks)
  • libs/judicial-system/types/src/lib/eventLog.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/judicial-system/backend/src/app/modules/case/filters/cases.filter.ts
  • libs/judicial-system/types/src/lib/eventLog.ts
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/backend/src/app/modules/case/interceptors/case.interceptor.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (2)
apps/judicial-system/backend/src/app/modules/case/interceptors/case.interceptor.ts (2)

10-10: LGTM: Imports are correctly structured

The new imports for Defendant and DefendantEventLog models are necessary and properly organized.


26-26: LGTM: Proper integration of transformDefendants

The transformCase function correctly integrates the new transformDefendants function while maintaining its existing structure.

Copy link
Member

@unakb unakb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one thought and a test that needs fixing

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (5)
apps/judicial-system/backend/src/app/modules/notification/test/createTestingNotificationModule.ts (2)

Line range hint 42-56: Consider extending test utilities for prison admin functionality.

Given that this PR introduces "Send to prison admin" functionality, consider extending the createTestUsers utility to include prison administrator roles and related test data.

Example enhancement:

 export const createTestUsers = (
   roles: string[],
 ): Record<
   string,
   {
     id: string
     name: string
     email: string
     mobile: string
     nationalId: string
+    isPrisonAdmin?: boolean
   }
 > =>

Line range hint 127-129: Extend DefendantService mock for prison admin functionality.

The DefendantService mock should be extended to include methods related to the new prison admin functionality, such as sending cases to prison admin and revoking them.

Update the mock implementation:

 {
   provide: DefendantService,
-  useValue: { isDefendantInActiveCustody: jest.fn() },
+  useValue: {
+    isDefendantInActiveCustody: jest.fn(),
+    sendToPrisonAdmin: jest.fn(),
+    revokePrisonAdmin: jest.fn(),
+  },
 },
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts (1)

Missing test coverage for prison admin notifications

Based on the verification:

  • The codebase has prison admin user filters and access controls implemented
  • The CaseNotificationType enum doesn't include any prison admin related notifications
  • No prison admin notification tests exist in the notification module

This confirms the review comment's concern about missing test coverage for prison admin functionality in the notification system.

Specific areas needing test coverage:

  • Notification scenarios when a defendant is sent to prison admin (isSentToPrisonAdmin: true)
  • Email notification content and recipients for prison admin cases
  • Integration with prison admin access controls
🔗 Analysis chain

Line range hint 1-180: Ensure test coverage for new prison admin functionality.

While these tests thoroughly cover defender assignment notifications, they don't include scenarios related to the new "Send to prison admin" feature mentioned in the PR objectives.

Consider organizing prison admin related tests in a separate test file like prisonAdminNotifications.spec.ts to maintain clear separation of concerns.


Let me gather more information about the prison admin functionality to verify the review comment.


Let me check for the notification types and implementation to complete the verification.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other test files that might cover prison admin functionality
fd -e spec.ts -e test.ts . | grep -i "prison"

# Look for prison admin related types/interfaces
ast-grep --pattern 'interface $name {
  $$$
  isSentToPrisonAdmin?: boolean
  $$$
}'

Length of output: 318


Script:

#!/bin/bash
# Check content of prison admin related test files
cat apps/judicial-system/backend/src/app/modules/case/filters/test/prisonAdminUserFilter.spec.ts
cat apps/judicial-system/backend/src/app/modules/case/filters/test/prisonStaffUserFilter.spec.ts

# Look for prison admin notification types
ast-grep --pattern 'enum $_ {
  $$$
  PRISON_$_ = $_,
  $$$
}'

# Search for prison admin related notification code
rg -l "prison.*admin.*notification" -g "*.ts"

Length of output: 9300


Script:

#!/bin/bash
# Check for notification types
rg "enum.*CaseNotificationType" -A 10

# Check the implementation of prison admin notifications
rg "PRISON_ADMIN.*notification" -A 5 -g "*.ts"

# Look for any prison admin related code in notification module
fd . "apps/judicial-system/backend/src/app/modules/notification" -t f -e ts | xargs rg -l "prison.*admin"

Length of output: 2390

apps/judicial-system/backend/src/app/formatters/formatters.ts (2)

Line range hint 632-651: LGTM! Well-structured prison administration notification.

The function properly handles both new and modified rulings, includes necessary context in notifications, and maintains consistent formatting patterns. The court name transformation from "dómur" to "dómi" ensures grammatically correct messages in the target language.

Consider implementing a reusable helper function for court name transformations, as this pattern appears in multiple places throughout the codebase.


Line range hint 1-1183: Well-structured formatting module with room for optimization.

The code demonstrates good practices in terms of type safety and separation of concerns. However, there are opportunities for improvement:

  1. Consider extracting repeated string transformations (e.g., court name formatting, date formatting) into utility functions.
  2. The error messages and default values ('NONE') could be centralized in constants.

Example utility function for court name transformation:

const transformCourtName = (courtName?: string, format: 'domi' | 'doms' = 'domi'): string => {
  if (!courtName) return 'NONE';
  const replacement = format === 'domi' ? 'dómi' : 'dóms';
  return courtName.replace('dómur', replacement);
};
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 719bfbd and 2f368e2.

📒 Files selected for processing (11)
  • apps/judicial-system/backend/src/app/formatters/formatters.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/filters/case.filter.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/interceptors/case.interceptor.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/test/civilClaimantController/update.spec.ts (0 hunks)
  • apps/judicial-system/backend/src/app/modules/defendant/test/internalDefendantController/internalDefendantControllerGuards.spec.ts (0 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/caseNotification.service.ts (0 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/test/createTestingNotificationModule.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts (2 hunks)
  • apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/SendToPrisonAdmin/SendToPrisonAdmin.tsx (1 hunks)
💤 Files with no reviewable changes (3)
  • apps/judicial-system/backend/src/app/modules/defendant/test/civilClaimantController/update.spec.ts
  • apps/judicial-system/backend/src/app/modules/defendant/test/internalDefendantController/internalDefendantControllerGuards.spec.ts
  • apps/judicial-system/backend/src/app/modules/notification/caseNotification.service.ts
✅ Files skipped from review due to trivial changes (1)
  • apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • apps/judicial-system/backend/src/app/modules/case/filters/case.filter.ts
  • apps/judicial-system/backend/src/app/modules/case/interceptors/case.interceptor.ts
  • apps/judicial-system/web/src/routes/PublicProsecutor/Indictments/SendToPrisonAdmin/SendToPrisonAdmin.tsx
🧰 Additional context used
📓 Path-based instructions (4)
apps/judicial-system/backend/src/app/formatters/formatters.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/notification/test/createTestingNotificationModule.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (6)
apps/judicial-system/backend/src/app/modules/notification/test/createTestingNotificationModule.ts (2)

7-7: LGTM! Clean import optimization.

The removal of unused FormatMessage import while maintaining the necessary internationalization functionality through IntlService is a good cleanup.


Line range hint 156-182: Verify notification test coverage for prison admin events.

The testing context should ensure proper coverage of notifications related to prison admin events (sending/revoking cases).

✅ Verification successful

Test context properly handles prison admin notifications

The test context in createTestingNotificationModule.ts includes all necessary components for testing prison admin notifications:

  • The module includes NotificationService, CaseNotificationService, and other required notification services
  • Prison-related email configuration is properly handled through notificationModuleConfig
  • The context exposes notification controllers and services needed for testing prison admin scenarios

Key evidence from codebase:

  • Prison admin notifications are implemented in CaseNotificationService with dedicated methods for:
    • Sending rulings to prison admin (prisonAdminEmail)
    • Handling custody notifications (prisonEmail)
    • Managing case revocations
  • Test module provides all required dependencies including email service mocks and configuration
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for prison admin-related test coverage

# Search for prison admin-related test cases
rg -l "prison.*admin.*test" --type ts

# Check for notification handlers related to prison admin
ast-grep --pattern 'class $_ implements NotificationHandler {
  $$$
  handle($_, $_) {
    $$$
    prison
    $$$
  }
}'

Length of output: 162


Script:

#!/bin/bash
# Let's try a broader search for prison-related notifications and tests

# Search for prison-related notification tests
rg -l "prison.*notification" --type ts

# Search for notification handler implementations
ast-grep --pattern 'class $_ implements NotificationHandler'

# Check the test file content
cat "apps/judicial-system/backend/src/app/modules/notification/test/createTestingNotificationModule.ts"

# Look for prison-related notification types or interfaces
rg "prison" --type ts -C 2

Length of output: 94438

apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendAdvocateAssignedNotifications.spec.ts (1)

Line range hint 42-180: LGTM: Well-structured test cases.

The test cases are well organized with clear setup, execution, and verification phases. They properly test different scenarios of defender assignment notifications.

apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts (2)

Line range hint 1-585: LGTM! Well-structured test suite

The test file maintains a consistent pattern for testing role-based filters, with clear separation of concerns and explicit test cases for each user role. The prison admin filter test aligns well with this structure.


394-397: Verify test coverage for prison admin case visibility

The filter correctly checks for cases where is_sent_to_prison_admin = true, but consider adding additional test cases to verify:

  1. Cases that are not sent to prison admin are filtered out
  2. Edge cases when is_sent_to_prison_admin is null or false
✅ Verification successful

Let me check the test files more thoroughly to verify the test coverage.


Test coverage for prison admin case visibility is comprehensive

The test coverage is complete with both positive and negative test cases:

  • Tests verify that cases are not accessible when is_sent_to_prison_admin is false or missing (defendants: [{}])
  • Tests verify that cases are accessible when is_sent_to_prison_admin is true (defendants: [{ isSentToPrisonAdmin: true }])
  • Tests cover different case types, states, and decisions for prison admin access
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for comprehensive test coverage of prison admin filtering

# Look for related test files
fd -e spec.ts -e test.ts prison

# Check for test cases covering different states of is_sent_to_prison_admin
rg -A 10 "is_sent_to_prison_admin" -g "*.spec.ts" -g "*.test.ts"

Length of output: 1397


Script:

#!/bin/bash
# Check content of prison admin filter test files
cat apps/judicial-system/backend/src/app/modules/case/filters/test/prisonAdminUserFilter.spec.ts
cat apps/judicial-system/backend/src/app/modules/case/filters/test/prisonStaffUserFilter.spec.ts

# Look for test cases with different states of is_sent_to_prison_admin
rg -B 5 -A 15 "describe.*prison" -g "*.spec.ts"

Length of output: 23983

apps/judicial-system/backend/src/app/formatters/formatters.ts (1)

16-16: LGTM! Clean import statement.

The import statement has been simplified to include only the necessary types (Gender and UserRole), improving code maintainability.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2f368e2 and cbbc2e2.

📒 Files selected for processing (1)
  • apps/judicial-system/backend/src/app/modules/defendant/test/createTestingDefendantModule.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/judicial-system/backend/src/app/modules/defendant/test/createTestingDefendantModule.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
📓 Learnings (1)
apps/judicial-system/backend/src/app/modules/defendant/test/createTestingDefendantModule.ts (1)
Learnt from: oddsson
PR: island-is/island.is#16831
File: apps/judicial-system/api/src/app/modules/case/models/defendantEventLog.model.ts:6-22
Timestamp: 2024-11-18T21:50:40.004Z
Learning: In `apps/judicial-system/api/src/app/modules`, new models should be created following the existing patterns used in the API to maintain consistency.
🔇 Additional comments (1)
apps/judicial-system/backend/src/app/modules/defendant/test/createTestingDefendantModule.ts (1)

23-23: LGTM!

The import follows the established pattern for model imports in the codebase.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
apps/judicial-system/backend/src/app/modules/file/test/fileController/createCaseFileRolesRules.spec.ts (1)

Line range hint 26-35: Consider adding negative test cases.

While the current test verifies the presence of authorized roles, consider adding test cases to ensure that unauthorized roles cannot access the file creation functionality. This would provide more comprehensive test coverage.

Example addition:

it('should not give permission to unauthorized roles', () => {
  const unauthorizedRole = { name: 'unauthorized' }
  expect(rules).not.toContain(unauthorizedRole)
})
apps/judicial-system/backend/src/app/modules/file/test/fileController/createPresignedPostRolesRules.spec.ts (1)

Line range hint 14-36: Consider adding specific test cases for prison admin functionality.

While the basic role permission is tested, consider adding test cases that specifically validate the permissions related to the "Send to prison admin" feature, such as:

  • Access to prison admin related files
  • Permissions for sending/revoking cases to prison administrators

Would you like me to help create these additional test cases?

apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRulingNotifications.spec.ts (1)

Line range hint 1-350: Consider adding test cases for new prison admin functionality

Given that this PR introduces the "Send to prison admin" feature, consider adding test cases for:

  1. Sending cases to prison admin
  2. Revoking cases from prison admin
  3. Edge cases around the timing of sending/revoking

Additionally, the test suite would benefit from:

  1. Testing error scenarios (e.g., failed email delivery)
  2. Validating email content for prison admin notifications
  3. Testing concurrent modifications to case status
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cbbc2e2 and b461207.

📒 Files selected for processing (3)
  • apps/judicial-system/backend/src/app/modules/file/test/fileController/createCaseFileRolesRules.spec.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/file/test/fileController/createPresignedPostRolesRules.spec.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRulingNotifications.spec.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
apps/judicial-system/backend/src/app/modules/file/test/fileController/createCaseFileRolesRules.spec.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/file/test/fileController/createPresignedPostRolesRules.spec.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRulingNotifications.spec.ts (1)

Pattern apps/**/*: "Confirm that the code adheres to the following:

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
📓 Learnings (2)
apps/judicial-system/backend/src/app/modules/file/test/fileController/createCaseFileRolesRules.spec.ts (1)
Learnt from: gudjong
PR: island-is/island.is#16389
File: apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getCaseFilesRecordPdfRolesRules.spec.ts:1-1
Timestamp: 2024-11-12T15:15:20.157Z
Learning: The usage of `defenderRule` in the following test files is intentional and should remain unchanged:

- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createPresignedPostRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/deleteCaseFileRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createCaseFileRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/getCaseFileSignedUrlRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getRulingPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getRequestPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getCourtRecordPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getByIdRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getAllFilesZipRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/caseController/getAllRolesRules.spec.ts`
apps/judicial-system/backend/src/app/modules/file/test/fileController/createPresignedPostRolesRules.spec.ts (1)
Learnt from: gudjong
PR: island-is/island.is#16389
File: apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getCaseFilesRecordPdfRolesRules.spec.ts:1-1
Timestamp: 2024-11-12T15:15:20.157Z
Learning: The usage of `defenderRule` in the following test files is intentional and should remain unchanged:

- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createPresignedPostRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/deleteCaseFileRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/createCaseFileRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/getCaseFileSignedUrlRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getRulingPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getRequestPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getCourtRecordPdfRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getByIdRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getAllFilesZipRolesRules.spec.ts`
- `apps/judicial-system/backend/src/app/modules/case/test/caseController/getAllRolesRules.spec.ts`
🔇 Additional comments (4)
apps/judicial-system/backend/src/app/modules/file/test/fileController/createCaseFileRolesRules.spec.ts (1)

10-10: LGTM! The role addition follows best practices.

The addition of publicProsecutorStaffRule and its corresponding test expectations are well-structured and align with the PR objectives for the "Send to prison admin" feature.

Also applies to: 26-26, 35-35

apps/judicial-system/backend/src/app/modules/file/test/fileController/createPresignedPostRolesRules.spec.ts (1)

10-10: LGTM! Verify role scope alignment with requirements.

The addition of publicProsecutorStaffRule and its test assertions are correctly implemented. The changes align with the PR's objective of enabling public prosecutor staff to manage prison admin cases.

Let's verify if this role is consistently applied across related endpoints:

Also applies to: 26-26, 35-35

✅ Verification successful

The search results show that publicProsecutorStaffRule is consistently applied across all relevant file-related endpoints in both the main controllers (file.controller.ts, limitedAccessFile.controller.ts) and their corresponding test files. The role is also properly integrated into other related modules like case, defendant, and subpoena controllers, indicating a comprehensive implementation.

Role scope is properly aligned with requirements

The publicProsecutorStaffRule is correctly applied to:

  • File operations (create, get signed URLs)
  • Case management endpoints
  • Defendant-related operations
  • Subpoena handling
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if publicProsecutorStaffRule is consistently applied across related controllers
# Expected: Find all endpoints where this role should be applied for the prison admin feature

# Search for other controller files that might need this role
rg -l "createPresignedPost|getCaseFileSignedUrl|createCaseFile" apps/judicial-system/backend/src/app/modules

# Check existing usage of the role
rg "publicProsecutorStaffRule" apps/judicial-system/backend/src/app

Length of output: 7196

apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendRulingNotifications.spec.ts (2)

178-178: ⚠️ Potential issue

Confirm notification behavior for modified rulings

Similar to the restriction case, the test for modified rulings now expects one email instead of two. This change should be validated against the notification requirements for modified rulings.


144-144: ⚠️ Potential issue

Verify the reduction in email notifications

The test now expects only one email to be sent to the prosecutor instead of two. Please verify that this change aligns with the business requirements and doesn't accidentally drop important notifications.

@gudjong gudjong added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Nov 25, 2024
@kodiakhq kodiakhq bot merged commit 78bdd5b into main Nov 25, 2024
37 checks passed
@kodiakhq kodiakhq bot deleted the j-s/send-to-fmst branch November 25, 2024 10:54
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
* Add a send to fmst button that routes to a page

* Remove unused code

* Add UI

* Create event log when indictment is sent to FMSt

* Create event log when indictment is sent to FMSt

* Create event log when indictment is sent to FMSt

* Refactor

* Refactor

* Refactor

* Updates FMST queries

* Refactor

* Refactor

* Refactor

* Refactor

* Add DefendantEventLog table

* Refactor

* Send sentToPrisonAdminDate to client

* Show sent to prison admin date on info cards

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Frontend: Upload file to prison admin

* Frontend: Upload file to prison admin

* Add SentToPrisonAdmin tag in cases list for PP

* Merge

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Remove caseId from defendant event log table

* Remove caseId from defendant event log table

* Revert

* Remove unused code

* Refactor

* Removes unused event type

* Removes the defendant event log from the api

* Moves defendant event log to defendant model

* Fixes backend case retrieval

* Updates unit test

* Sets the sent to prison admin date to undefined it the defendant has not been sent to prison admin

* Fixes linting issues

* Updates unit tests

* Updates unit tests

* Updates unit tests

* Updates unit tests

---------

Co-authored-by: Guðjón Guðjónsson <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants