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): Fixes to ServiceRequirement NOT_REQUIRED #16305

Merged
merged 15 commits into from
Oct 15, 2024
Merged

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Oct 7, 2024

Fixes to ServiceRequirement NOT_REQUIRED

Asana

What

Today, if district court users mark that a ruling is not required to be served and a prosecutor at the public prosecutors office has reviewed a case, it is directly sent to FMST. According to the public prosecutors office, this should not happen, but rather it should wait 28 days (like with rulings that are required to be served) before being sent to FMST.

Why

This is a request from the public prosecutors office, based on their needs.

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

    • Enhanced access control for prison admin users, clarifying conditions for case access based on indictment type and state.
  • Bug Fixes

    • Streamlined logic for determining verdict view dates in indictment cases.
  • Style

    • Adjusted layout styling in the Defendant Info component for improved responsiveness.
  • Refactor

    • Updated the rendering structure of the Section Heading component for better output consistency.

Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

Walkthrough

The pull request introduces several modifications across multiple files in the judicial system application. Key changes include updates to the logic for handling verdict information in the getIndictmentInfo function, adjustments to access control for prison admin users in case filters, simplifications in SQL queries for filtering cases, and minor updates to component styles and imports. These changes streamline the processing of indictment information, enhance access control logic, and refine user interface components.

Changes

File Change Summary
apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts Updated getIndictmentInfo logic to simplify verdictInfo array handling; modified transformIndictmentCase to include updated logic.
apps/judicial-system/backend/src/app/modules/case/filters/case.filter.ts Altered access control logic in canPrisonAdminUserAccessCase to clarify conditions for indictment cases; updated function signature for canUserAccessCase.
apps/judicial-system/backend/src/app/modules/case/filters/cases.filter.ts Modified getPrisonAdminUserCasesQueryFilter to remove service requirement condition from SQL query, simplifying filtering criteria.
apps/judicial-system/backend/src/app/modules/subpoena/limitedAccessSubpoena.controller.ts Removed unused Query import from LimitedAccessSubpoenaController.
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.css.ts Updated gridRow.withButton style from gridTemplateColumns: '5fr 1fr' to gridTemplateColumns: '5fr auto'.
apps/judicial-system/web/src/components/SectionHeading/SectionHeading.tsx Changed rendering of description prop from Text to Box component while maintaining margin styling.

Possibly related PRs

Suggested reviewers

  • unakb

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.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 7, 2024

Datadog Report

All test runs 9878d62 🔗

3 Total Test Services: 1 Failed, 2 Passed
➡️ Test Sessions change in coverage: 3 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
judicial-system-backend 1 0 0 21253 0 20m 32.74s 1 no change Link
judicial-system-api 0 0 0 57 0 6.79s 1 no change Link
judicial-system-web 0 0 0 338 0 1m 13.71s 1 no change Link

❌ Failed Tests (1)

  • getCasesQueryFilter should get prison admin staff filter - apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts - Details

    Expand for error
     expect(received).toStrictEqual(expected) // deep equality
     
     - Expected  - 2
     + Received  + 1
     
     @@ -14,12 +14,11 @@
             "id": Object {
               Symbol(notIn): Literal {
                 "val": "
                   (SELECT case_id
     ...
    

Copy link

codecov bot commented Oct 7, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 36.72%. Comparing base (e3e51fc) to head (9835907).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ackend/src/app/modules/case/filters/case.filter.ts 66.66% 2 Missing ⚠️
...b/src/components/SectionHeading/SectionHeading.tsx 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16305      +/-   ##
==========================================
- Coverage   36.73%   36.72%   -0.01%     
==========================================
  Files        6809     6801       -8     
  Lines      141086   139985    -1101     
  Branches    40224    39848     -376     
==========================================
- Hits        51825    51411     -414     
+ Misses      89261    88574     -687     
Flag Coverage Δ
judicial-system-api 18.39% <100.00%> (ø)
judicial-system-backend 55.18% <66.66%> (+<0.01%) ⬆️
judicial-system-web 27.93% <50.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
.../app/modules/case/interceptors/case.transformer.ts 100.00% <100.00%> (ø)
...ckend/src/app/modules/case/filters/cases.filter.ts 97.91% <ø> (ø)
...dules/subpoena/limitedAccessSubpoena.controller.ts 100.00% <ø> (ø)
...b/src/components/SectionHeading/SectionHeading.tsx 90.00% <50.00%> (-10.00%) ⬇️
...ackend/src/app/modules/case/filters/case.filter.ts 86.36% <66.66%> (+0.08%) ⬆️

... and 230 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 e3e51fc...9835907. Read the comment docs.

@oddsson oddsson changed the title J s/public prosec chore(j-s): Fixes to ServiceRequirement NOT_REQUIRED Oct 7, 2024
@unakb unakb marked this pull request as ready for review October 10, 2024 14:39
@unakb unakb requested a review from a team as a code owner October 10, 2024 14:39
@oddsson oddsson added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Oct 11, 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: 2

🧹 Outside diff range and nitpick comments (1)
apps/judicial-system/web/src/components/SectionHeading/SectionHeading.tsx (1)

32-36: Consider simplifying the description rendering

The change from rendering the description directly to wrapping it in a Box component provides more flexibility for styling and layout. However, there's a potential for optimization:

  1. The component="span" prop on the Box might be unnecessary unless there's a specific reason for rendering as a span.
  2. Ensure that this change doesn't unintentionally affect text styling that might have been inherited from the previous Text component usage.

Consider simplifying the code as follows:

 {description && (
-  <Box component="span" marginTop={1}>
+  <Box marginTop={1}>
     {description}
   </Box>
 )}

This change maintains the added flexibility while simplifying the component structure.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b8b850d and 3e5d7ff.

📒 Files selected for processing (6)
  • apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.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/cases.filter.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/subpoena/limitedAccessSubpoena.controller.ts (0 hunks)
  • apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.css.ts (1 hunks)
  • apps/judicial-system/web/src/components/SectionHeading/SectionHeading.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/judicial-system/backend/src/app/modules/subpoena/limitedAccessSubpoena.controller.ts
🧰 Additional context used
📓 Path-based instructions (5)
apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.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/case.filter.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/cases.filter.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/web/src/components/InfoCard/DefendantInfo/DefendantInfo.css.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/web/src/components/SectionHeading/SectionHeading.tsx (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 (5)
apps/judicial-system/web/src/components/InfoCard/DefendantInfo/DefendantInfo.css.ts (1)

11-11: Improved layout flexibility with auto-sized second column

The change from '5fr 1fr' to '5fr auto' for the gridTemplateColumns property in the withButton variant is a good improvement. This modification allows the second column (likely containing a button) to automatically size based on its content, rather than being fixed to 1/6 of the available space. This change enhances the layout's flexibility and responsiveness, particularly when the button's width may vary.

apps/judicial-system/api/src/app/modules/case/interceptors/case.transformer.ts (1)

150-153: Verify alignment with PR objectives and consider additional logic

The changes align with the PR objectives by modifying how cases marked as "NOT_REQUIRED" are handled. However, the 28-day waiting period mentioned in the PR objectives is not directly implemented in this function.

Consider adding logic to implement the 28-day waiting period for cases marked as "NOT_REQUIRED" before they are sent to FMST. This could involve:

  1. Adding a new field to track when a "NOT_REQUIRED" case was reviewed by a prosecutor.
  2. Implementing a check to ensure 28 days have passed since the review date before further processing.

To ensure the changes align with the PR objectives, let's check for any related logic elsewhere in the codebase:

Would you like assistance in implementing the 28-day waiting period logic?

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

Line range hint 1-365: Overall assessment: Change aligns with PR objectives, but requires verification.

The modification to the getPrisonAdminUserCasesQueryFilter function aligns with the PR objectives by implementing a 28-day waiting period for cases marked as not required to be served. The change is localized and doesn't affect other parts of the file.

To ensure the change meets all requirements and maintains code clarity:

  1. Verify that the new logic exactly matches the requirements from the public prosecutors office.
  2. Add a comment explaining the 28-day waiting period logic.
  3. Run the suggested verification script to check for any potential impacts on other parts of the codebase.

217-217: Verify alignment with PR objectives and add explanatory comment.

The removal of the service_requirement <> 'NOT_REQUIRED' condition aligns with the PR objective to include a 28-day waiting period for cases marked as not required to be served. This change simplifies the query and potentially includes more cases in the result set.

To ensure clarity and maintainability:

  1. Verify that this change exactly meets the requirements stated in the PR objectives, particularly regarding the handling of cases marked as "NOT_REQUIRED".
  2. Add a comment explaining the 28-day logic and its purpose. For example:
// Filter out cases viewed within the last 28 days to allow for the waiting period
// requested by the public prosecutors office before sending to FMST

To verify the impact of this change, please run the following query:

This will help ensure that removing the service_requirement condition doesn't have unintended consequences elsewhere in the codebase.

apps/judicial-system/backend/src/app/modules/case/filters/case.filter.ts (1)

301-302: Verify access denial logic based on appeal deadline expiration

The condition if (!indictmentVerdictAppealDeadlineExpired) returns false, denying access if the indictment verdict appeal deadline has not expired. Please confirm that this logic aligns with the intended business rules for prison admin users accessing cases.

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 (2)
apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts (2)

Line range hint 269-277: Ensure correct user role for prison admin staff

In the test case for the prison admin staff filter, the role is set to UserRole.PRISON_SYSTEM_STAFF, while the institution.type is InstitutionType.PRISON_ADMIN. This could lead to confusion or incorrect behavior if the role does not align with the institution type.

Consider updating the role to a more specific value that matches InstitutionType.PRISON_ADMIN, such as UserRole.PRISON_ADMIN_STAFF, if it exists. This ensures consistency and clarity in the test setup.


Line range hint 313-316: Simplify redundant array in defender national ID condition

In the defender filter, the condition for defender_national_id is specified as:

{
  defender_national_id: [user.nationalId, user.nationalId],
},

Listing the same national ID twice in the array is redundant. Simplify the condition by using a single value:

Apply this diff to fix the redundancy:

{
- defender_national_id: [user.nationalId, user.nationalId],
+ defender_national_id: user.nationalId,
},
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 016b327 and 9835907.

📒 Files selected for processing (1)
  • apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
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."
🔇 Additional comments (2)
apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts (2)

Line range hint 285-308: Validate the subquery logic for the 28-day waiting period

The subquery in the id condition filters out cases where the verdict_view_date is either NULL or within the last 28 days:

(SELECT case_id
  FROM defendant
  WHERE (verdict_view_date IS NULL OR verdict_view_date > NOW() - INTERVAL '28 days'))

This aims to include cases that have been viewed more than 28 days ago or not viewed at all. Confirm that this logic correctly implements the 28-day waiting period before cases are sent to FMST, as specified in the PR objectives.

Additionally, ensure that the verdict_view_date field is correctly populated elsewhere in the application and that there are no timezone-related issues that could affect the date comparisons.


Line range hint 108-124: Reevaluate assistant filter case types

In the assistant filter for district court roles, only indictmentCases are included:

{ type: indictmentCases },

Verify whether assistants should have access exclusively to indictment cases. If assistants are supposed to access other case types, such as restriction or investigation cases, consider including those in the filter to align with their role requirements.

@kodiakhq kodiakhq bot merged commit 7a37f44 into main Oct 15, 2024
34 checks passed
@kodiakhq kodiakhq bot deleted the j-s/public-prosec branch October 15, 2024 21:38
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.

2 participants