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

fix(j-s): Merge Case Access #16053

Merged
merged 15 commits into from
Sep 26, 2024
Merged

fix(j-s): Merge Case Access #16053

merged 15 commits into from
Sep 26, 2024

Conversation

gudjong
Copy link
Member

@gudjong gudjong commented Sep 18, 2024

Merge Case Access

Sameina mál - Verjandi/sækjandi á að sjá gögn úr sameinuðum málum

What

  • Allows prosecutors to access uploaded case files and generated pdf files in merged indictment cases even if the merged case was created by a different prosecutor's office.
  • Allows defenders to access uploaded case files and generated pdf files in merged indictment cases even if they are not assigend as defenders in the merged case.
  • Adds missing case file categories fo merged cases so they can be viewed by all in the client.
  • Limites the indictments accessible to the public prosecutors office to completed indictment cases that ended with a fine or a ruling and have been sent to the public prosecutors office for review.
  • Adds laws broken components to a few screen to follow design in Figma.
  • This PR does not handle merge chains, i.e. if a case is merged with another case which later is merged with another case and so on. This will be handled in a later PR.

Why

  • Verified bugs.

Screenshots / Gifs

Screen.Recording.2024-09-19.at.14.22.54.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

    • Enhanced API to support retrieval of signed URLs for merged cases.
    • Added new fields in GraphQL queries for more detailed case file information, including modified, type, and submittedBy.
    • Introduced MergedCaseExistsGuard for improved access control on merged cases.
  • Improvements

    • Expanded functionality of components to manage and display connected case files more effectively.
    • Updated UI logic to conditionally display information based on case attributes like laws broken and merged cases.
    • Enhanced data retrieval processes for cases, including support for indictment counts and filtering by case states.
  • Bug Fixes

    • Removed unnecessary props from components to streamline data handling.

Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

Walkthrough

The changes involve enhancements to the judicial system's API and frontend components to support the handling of merged cases. Key modifications include the introduction of optional parameters for merged case IDs in various service methods, controllers, and input types. Additionally, new guards have been implemented to validate requests related to merged cases, and the UI components have been updated to accommodate the display of connected case files and laws broken. These changes aim to improve the flexibility and functionality of case management processes.

Changes

File Path Change Summary
apps/judicial-system/api/src/app/modules/backend/backend.service.ts Added mergedCaseId as an optional parameter to getCaseFileSignedUrl and limitedAccessGetCaseFileSignedUrl methods.
apps/judicial-system/api/src/app/modules/file/limitedAccessFile.controller.ts Enhanced routes to include mergedCaseId for getCaseFilesRecordPdf and getIndictmentPdf.
apps/judicial-system/backend/src/app/modules/case/case.service.ts Added new case file categories and updated inclusion logic for event logs.
apps/judicial-system/backend/src/app/modules/case/guards/mergedCaseExists.guard.ts Implemented MergedCaseExistsGuard to validate requests related to merged cases.
apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.controller.ts Added MergedCaseExistsGuard and modified routes to accommodate merged cases.
apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts Enhanced data retrieval capabilities by including indictment counts and merged cases.
apps/judicial-system/web/src/components/AccordionItems/ConnectedCaseFilesAccordionItem.tsx Added connectedCaseParentId prop to enhance component functionality.
apps/judicial-system/web/src/components/FormProvider/case.graphql Added new fields to the caseFiles object in the GraphQL query.
apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql Expanded caseFiles and added indictmentCounts and mergedCases fields to the query structure.
apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx Modified RenderFiles component to accept connectedCaseParentId prop.
apps/judicial-system/web/src/components/PdfButton/PdfButton.tsx Made caseId optional and added connectedCaseParentId to the props interface.
apps/judicial-system/web/src/routes/Court/Indictments/Completed/Completed.tsx Introduced logic to handle laws broken and merged cases, modifying rendering logic accordingly.
apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx Added logic to display merged cases and laws broken, integrating ConnectedCaseFilesAccordionItem.
apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx Enhanced ConnectedCaseFilesAccordionItem to include connectedCaseParentId.
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx Modified to conditionally display merged cases and laws broken, enhancing the overview component.

Possibly related PRs

Suggested labels

automerge

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.

Copy link

codecov bot commented Sep 18, 2024

Codecov Report

Attention: Patch coverage is 12.26415% with 93 lines in your changes missing coverage. Please review.

Project coverage is 36.63%. Comparing base (651f337) to head (29f9d96).

Files with missing lines Patch % Lines
.../app/modules/case/guards/mergedCaseExists.guard.ts 21.05% 15 Missing ⚠️
...tem/api/src/app/modules/backend/backend.service.ts 0.00% 10 Missing ⚠️
...c/routes/Court/Indictments/Completed/Completed.tsx 0.00% 10 Missing ⚠️
...ackend/src/app/modules/case/filters/case.filter.ts 0.00% 8 Missing ⚠️
...outes/Prosecutor/Indictments/Overview/Overview.tsx 0.00% 8 Missing ⚠️
...s/Shared/IndictmentOverview/IndictmentOverview.tsx 0.00% 8 Missing ⚠️
...system/api/src/app/modules/file/file.controller.ts 0.00% 6 Missing ⚠️
...c/app/modules/file/limitedAccessFile.controller.ts 0.00% 6 Missing ⚠️
...b/src/routes/Court/Indictments/Summary/Summary.tsx 0.00% 5 Missing ⚠️
...-system/web/src/components/PdfButton/PdfButton.tsx 0.00% 4 Missing ⚠️
... and 7 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16053      +/-   ##
==========================================
- Coverage   36.68%   36.63%   -0.06%     
==========================================
  Files        6775     6770       -5     
  Lines      139587   139466     -121     
  Branches    39696    39680      -16     
==========================================
- Hits        51213    51098     -115     
+ Misses      88374    88368       -6     
Flag Coverage Δ
judicial-system-api 18.46% <0.00%> (-0.12%) ⬇️
judicial-system-web 28.15% <8.51%> (-0.05%) ⬇️

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

Files with missing lines Coverage Δ
...em/backend/src/app/modules/case/case.controller.ts 84.47% <100.00%> (+0.05%) ⬆️
...ystem/backend/src/app/modules/case/case.service.ts 90.64% <ø> (ø)
...ckend/src/app/modules/case/filters/cases.filter.ts 97.91% <ø> (ø)
...c/app/modules/case/limitedAccessCase.controller.ts 97.61% <100.00%> (+0.01%) ⬆️
.../src/app/modules/case/limitedAccessCase.service.ts 72.07% <100.00%> (+0.25%) ⬆️
...em/backend/src/app/modules/file/file.controller.ts 100.00% <100.00%> (ø)
...c/app/modules/file/limitedAccessFile.controller.ts 100.00% <100.00%> (ø)
...ppealCaseFilesOverview/AppealCaseFilesOverview.tsx 71.42% <ø> (ø)
...s/Prison/IndictmentOverview/IndictmentOverview.tsx 0.00% <ø> (ø)
...l-system/api/src/app/modules/file/file.resolver.ts 0.00% <0.00%> (ø)
... and 16 more

... and 31 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 651f337...29f9d96. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 18, 2024

Datadog Report

All test runs 9546d83 🔗

3 Total Test Services: 0 Failed, 3 Passed
🔻 Test Sessions change in coverage: 3 decreased

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 57 0 5.85s 1 decreased (-0.06%) Link
judicial-system-backend 0 0 0 21211 0 18m 2.17s 1 decreased (-0.04%) Link
judicial-system-web 0 0 0 338 0 1m 4.41s 1 decreased (-0.03%) Link

🔻 Code Coverage Decreases vs Default Branch (3)

  • judicial-system-api - jest 19.67% (-0.06%) - Details
  • judicial-system-backend - jest 58.2% (-0.04%) - Details
  • judicial-system-web - jest 32.38% (-0.03%) - Details

@gudjong gudjong marked this pull request as ready for review September 19, 2024 11:53
@gudjong gudjong requested a review from a team as a code owner September 19, 2024 11:53
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 (4)
apps/judicial-system/backend/src/app/modules/case/guards/mergedCaseExists.guard.ts (1)

1-44: Implementation of MergedCaseExistsGuard looks good!

The guard correctly checks for the existence of a merged case within a given case context and handles the following scenarios appropriately:

  • Missing Case object: Throws an InternalServerErrorException.
  • Missing mergedCaseId: Allows the request to proceed.
  • mergedCaseId not found: Throws a BadRequestException.
  • mergedCaseId found: Updates the request parameters and allows the request to proceed.

The guard adheres to the NestJS best practices by implementing the CanActivate interface and using dependency injection for CaseService.

Here are a few suggestions to further improve the code:

  1. Consider adding JSDoc comments to the canActivate method to provide a clear description of its functionality and parameters.

  2. Use optional chaining (?.) consistently when accessing mergedCases to avoid potential undefined errors:

const mergedCase = theCase.mergedCases?.find(
  (mergedCase) => mergedCase.id === mergedCaseId,
)
  1. Consider extracting the logic for finding the merged case into a separate private method to improve readability and maintainability:
private findMergedCase(theCase: Case, mergedCaseId: string) {
  return theCase.mergedCases?.find(
    (mergedCase) => mergedCase.id === mergedCaseId,
  )
}

Then, use this method in the canActivate method:

const mergedCase = this.findMergedCase(theCase, mergedCaseId)
apps/judicial-system/api/src/app/modules/file/file.resolver.ts (1)

88-96: LGTM! The code changes align with the PR objective and should improve data accessibility for merged cases.

The addition of the mergedCaseId parameter to the getSignedUrl method and the corresponding update to the backendService.getCaseFileSignedUrl method call should enable retrieving signed URLs for files associated with merged cases. This enhancement aligns with the PR objective of ensuring access to data from combined cases for both the defender and the applicant.

The code changes are focused and unlikely to introduce any breaking changes or negatively impact existing functionality.

Suggestions for further improvement:

  • Consider adding a brief comment explaining the purpose of the mergedCaseId parameter to improve code readability and maintainability.
  • Verify that the backendService.getCaseFileSignedUrl method has been updated to handle the mergedCaseId parameter correctly and that appropriate tests have been added to validate the behavior.
apps/judicial-system/backend/src/app/modules/case/case.service.ts (2)

Line range hint 1-1138: Consider refactoring the CaseService class to improve maintainability.

The CaseService class has grown quite large and has multiple responsibilities. Here are a few suggestions to improve its design and maintainability:

  1. Break down the class into smaller, more focused classes or services that adhere to the Single Responsibility Principle (SRP). This will make the codebase more modular and easier to understand, test, and maintain.

  2. Extract complex logic from large methods into separate methods or utility functions. This will improve code readability, reusability, and testability.

  3. Add more comments or documentation to explain the purpose and behavior of critical methods and decision points. This will help future maintainers understand the code flow and the rationale behind certain choices.

By applying these refactorings, the CaseService class can become more maintainable and easier to work with in the long run.


Line range hint 1-1138: Ensure comprehensive test coverage for the CaseService class.

Given the critical nature of the functionalities provided by the CaseService class, it is crucial to have a robust test suite in place. Here are a few recommendations:

  1. Write comprehensive unit tests to cover the various methods and scenarios in the CaseService class. This will help catch any regressions and ensure the expected behavior of each method.

  2. Develop integration tests to verify the interaction with external services and libraries, such as the SigningService, AwsS3Service, etc. These tests will give confidence that the integration points are working as expected.

  3. Test the queueing functionality to ensure that the correct messages are added to the queue for different case events and updates. This will help prevent any issues related to missed or incorrect notifications.

By having a strong test suite, you can maintain the reliability and correctness of the CaseService class as the codebase evolves.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3594b6d and 50ab201.

Files selected for processing (34)
  • apps/judicial-system/api/src/app/modules/backend/backend.service.ts (2 hunks)
  • apps/judicial-system/api/src/app/modules/file/dto/getSignedUrl.input.ts (2 hunks)
  • apps/judicial-system/api/src/app/modules/file/file.controller.ts (2 hunks)
  • apps/judicial-system/api/src/app/modules/file/file.resolver.ts (1 hunks)
  • apps/judicial-system/api/src/app/modules/file/limitedAccessFile.controller.ts (2 hunks)
  • apps/judicial-system/api/src/app/modules/file/limitedAccessFile.resolver.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/case.controller.ts (5 hunks)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/case/filters/case.filter.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/case/filters/cases.filter.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/case/filters/test/cases.filter.spec.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/case/guards/mergedCaseExists.guard.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.controller.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.service.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/case/test/caseController/getCaseFilesRecordPdfGuards.spec.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/case/test/caseController/getIndictmentPdfGuards.spec.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getCaseFilesRecordPdfGuards.spec.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getIndictmentPdfGuards.spec.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/file/file.controller.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/file/limitedAccessFile.controller.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/file/test/fileController/getCaseFileSignedUrlGuards.spec.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/getCaseFileSignedUrlGuards.spec.ts (2 hunks)
  • apps/judicial-system/web/src/components/AccordionItems/ConnectedCaseFilesAccordionItem/ConnectedCaseFilesAccordionItem.tsx (2 hunks)
  • apps/judicial-system/web/src/components/AppealCaseFilesOverview/AppealCaseFilesOverview.tsx (0 hunks)
  • apps/judicial-system/web/src/components/FormProvider/case.graphql (1 hunks)
  • apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql (2 hunks)
  • apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx (9 hunks)
  • apps/judicial-system/web/src/components/PdfButton/PdfButton.tsx (3 hunks)
  • apps/judicial-system/web/src/routes/Court/Indictments/Completed/Completed.tsx (4 hunks)
  • apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx (1 hunks)
  • apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx (3 hunks)
  • apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx (3 hunks)
  • apps/judicial-system/web/src/utils/hooks/useFileList/index.ts (2 hunks)
Files not reviewed due to no reviewable changes (1)
  • apps/judicial-system/web/src/components/AppealCaseFilesOverview/AppealCaseFilesOverview.tsx
Additional context used
Path-based instructions (33)
apps/judicial-system/api/src/app/modules/backend/backend.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/api/src/app/modules/file/dto/getSignedUrl.input.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/api/src/app/modules/file/file.controller.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/api/src/app/modules/file/file.resolver.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/api/src/app/modules/file/limitedAccessFile.controller.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/api/src/app/modules/file/limitedAccessFile.resolver.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/case.controller.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/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/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/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/case/guards/mergedCaseExists.guard.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/limitedAccessCase.controller.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/limitedAccessCase.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/test/caseController/getCaseFilesRecordPdfGuards.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/case/test/caseController/getIndictmentPdfGuards.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/case/test/limitedAccessCaseController/getCaseFilesRecordPdfGuards.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/case/test/limitedAccessCaseController/getIndictmentPdfGuards.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/file.controller.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/limitedAccessFile.controller.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/getCaseFileSignedUrlGuards.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/limitedAccessFileController/getCaseFileSignedUrlGuards.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/web/src/components/AccordionItems/ConnectedCaseFilesAccordionItem/ConnectedCaseFilesAccordionItem.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."
apps/judicial-system/web/src/components/FormProvider/case.graphql (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/FormProvider/limitedAccessCase.graphql (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/IndictmentCaseFilesList/IndictmentCaseFilesList.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."
apps/judicial-system/web/src/components/PdfButton/PdfButton.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."
apps/judicial-system/web/src/routes/Court/Indictments/Completed/Completed.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."
apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.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."
apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.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."
apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.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."
apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.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."
apps/judicial-system/web/src/utils/hooks/useFileList/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."
Learnings (1)
apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx (1)
Learnt from: unakb
PR: island-is/island.is#15378
File: apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx:86-100
Timestamp: 2024-06-27T14:37:07.823Z
Learning: User unakb prefers explicit case handling in switch statements for key functionalities like `getRulingDecisionTagColor` to ensure clarity and avoid assumptions that a case was overlooked.
Additional comments not posted (94)
apps/judicial-system/api/src/app/modules/file/dto/getSignedUrl.input.ts (1)

14-18: LGTM!

The addition of the optional mergedCaseId property to the GetSignedUrlInput class is a valuable enhancement that improves the flexibility of the input type. The use of the @IsOptional() decorator and the @Field decorator with nullable: true ensures that the property is correctly defined as an optional field that can be null in GraphQL queries.

The changes adhere to the existing coding style and conventions used in the file and are unlikely to introduce any breaking changes or compatibility issues. The expanded capabilities of the input type accommodate scenarios where a case may not be merged or where the merged case ID is not applicable, thereby improving the overall functionality and usability of the API.

Great work on this enhancement!

apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/getCaseFileSignedUrlGuards.spec.ts (3)

2-2: LGTM!

The import statement for MergedCaseExistsGuard is correctly added from the case module.


19-19: LGTM!

The test assertion is correctly updated to expect 4 guards instead of 3, reflecting the addition of the new MergedCaseExistsGuard.


21-23: Verify the impact of the change in the order of the guards.

The order of the guards is changed, with MergedCaseExistsGuard added as the second guard. This suggests that the existence of a merged case is now checked before verifying the existence of the case file.

Please ensure that this change in the order of the guards does not introduce any unintended consequences or break the access control logic for case files.

Run the following script to verify the impact of the change:

Verification successful

Verification: Guard order change is consistent and intentional

The change in the order of guards, specifically the addition of MergedCaseExistsGuard as an early check, is consistently implemented across different controllers in the codebase. This suggests that the change is a deliberate architectural decision rather than an isolated modification.

Key observations:

  1. In the LimitedAccessFileController, MergedCaseExistsGuard is the second guard, consistent with the original change.
  2. In the FileController, MergedCaseExistsGuard is also placed early in the guard chain (fourth out of six guards).

The consistent implementation across different controllers indicates that this change is unlikely to introduce unintended consequences. It appears to be a systematic update to the access control logic for case files, possibly to ensure that merged case scenarios are handled correctly before proceeding with other checks.

Given the consistency of the implementation and the absence of any apparent issues, the change in the order of guards seems to be a valid and intentional improvement to the system's architecture.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the change in the order of the guards.

# Test 1: Search for the usage of the guards in the codebase. 
# Expect: The order of the guards should be consistent across the codebase.
rg --type typescript -A 5 $'CaseReadGuard|MergedCaseExistsGuard|CaseFileExistsGuard|LimitedAccessViewCaseFileGuard'

# Test 2: Search for any potential issues or TODOs related to the change in the order of the guards.
# Expect: No potential issues or TODOs should be found.
rg --type typescript $'TODO|FIXME|XXX|HACK|BUG'

Length of output: 235


Script:

#!/bin/bash
# Description: Verify the impact of the change in the order of the guards.

# Test 1: Search for the usage of the guards in the codebase. 
# Expect: The order of the guards should be consistent across the codebase.
rg -g '*.ts' -A 5 'CaseReadGuard|MergedCaseExistsGuard|CaseFileExistsGuard|LimitedAccessViewCaseFileGuard'

# Test 2: Search for any potential issues or TODOs related to the change in the order of the guards.
# Expect: No potential issues or TODOs should be found.
rg -g '*.ts' 'TODO.*guard|FIXME.*guard|XXX.*guard|HACK.*guard|BUG.*guard'

# Test 3: Search for the specific file and surrounding context
# Expect: To see the implementation and usage of the guards in the relevant file
rg -g '*getCaseFileSignedUrlGuards.ts' -A 10 -B 10 'CaseReadGuard|MergedCaseExistsGuard|CaseFileExistsGuard|LimitedAccessViewCaseFileGuard'

Length of output: 77208


Script:

#!/bin/bash
# Description: Locate and display the content of getCaseFileSignedUrlGuards.ts file

# Search for the file
file_path=$(fd -t f getCaseFileSignedUrlGuards.ts)

if [ -n "$file_path" ]; then
    echo "File found at: $file_path"
    echo "File contents:"
    cat "$file_path"
else
    echo "File getCaseFileSignedUrlGuards.ts not found."
    echo "Searching for similar files:"
    fd -t f -e ts | grep -i "getCaseFileSignedUrl.*Guard"
fi

Length of output: 516


Script:

#!/bin/bash
# Description: Display relevant parts of the getCaseFileSignedUrlGuards test files

echo "Contents of limitedAccessFileController/getCaseFileSignedUrlGuards.spec.ts:"
awk '/describe.*Get case file signed url guards/,/^})/' apps/judicial-system/backend/src/app/modules/file/test/limitedAccessFileController/getCaseFileSignedUrlGuards.spec.ts

echo -e "\n\nContents of fileController/getCaseFileSignedUrlGuards.spec.ts:"
awk '/describe.*Get case file signed url guards/,/^})/' apps/judicial-system/backend/src/app/modules/file/test/fileController/getCaseFileSignedUrlGuards.spec.ts

Length of output: 2089

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

6-6: LGTM!

The import statement for MergedCaseExistsGuard is correctly added from the appropriate path in the case module.


22-29: Great job on improving the test case!

The updated test case is more comprehensive and efficient:

  • It checks for the correct configuration of all six guards in a single test case.
  • It ensures that each guard is instantiated correctly and is of the expected type.
  • The addition of MergedCaseExistsGuard to the test case is consistent with the changes mentioned in the PR summary.

This change enhances the clarity and maintainability of the guard verification process within the FileController tests.

apps/judicial-system/backend/src/app/modules/case/test/caseController/getCaseFilesRecordPdfGuards.spec.ts (2)

8-8: LGTM!

The import statement for the new guard MergedCaseExistsGuard follows the correct syntax and naming conventions. The relative import path also seems correct.


Line range hint 22-31: Test case updated correctly!

The test case has been updated correctly to include the new guard MergedCaseExistsGuard:

  • The expected number of guards has been increased from 5 to 6.
  • The new guard is instantiated and checked at the correct index (5) in the guards array.
  • The test case follows the existing pattern of instantiating and checking each guard.
apps/judicial-system/web/src/components/AccordionItems/ConnectedCaseFilesAccordionItem/ConnectedCaseFilesAccordionItem.tsx (3)

4-4: LGTM!

Importing UI components from a shared library is a good practice to maintain consistency across the application.


11-11: LGTM!

The new prop connectedCaseParentId is correctly typed and follows the naming convention.


Line range hint 15-41: Excellent structural enhancement!

Wrapping the AccordionItem inside an Accordion component is a great way to improve the organization of the accordion items. This change enhances the component's capability to manage and display connected case files more effectively.

Also, passing the connectedCaseParentId prop to the IndictmentCaseFilesList component ensures that the necessary data is available for its functionality.

The JSX structure follows React best practices and is syntactically correct.

apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getIndictmentPdfGuards.spec.ts (2)

7-7: LGTM!

The import statement for MergedCaseExistsGuard is correctly added, following the existing pattern.


Line range hint 22-31: LGTM!

The test configuration is correctly updated to include the new MergedCaseExistsGuard. The changes follow the existing pattern and the new expectation verifies that the guard is correctly instantiated.

apps/judicial-system/backend/src/app/modules/case/test/limitedAccessCaseController/getCaseFilesRecordPdfGuards.spec.ts (2)

7-7: LGTM!

The import statement for MergedCaseExistsGuard is correctly added, which aligns with the PR objective of handling merged cases.


22-22: Test case updated correctly!

The test case is correctly updated to:

  • Increase the expected number of guards from 5 to 6.
  • Add an assertion to check if the 6th guard is an instance of MergedCaseExistsGuard.

These changes ensure that the test case validates the presence and type of the newly added guard.

Also applies to: 31-31

apps/judicial-system/backend/src/app/modules/case/test/caseController/getIndictmentPdfGuards.spec.ts (2)

10-10: LGTM!

The import statement for MergedCaseExistsGuard is correctly added, following the existing import style and using the correct relative path.


23-33: Test case refactoring looks good!

The test case has been appropriately modified to accommodate the addition of MergedCaseExistsGuard. The test now checks for a total of 6 guards and verifies the instance types of each guard, including the new guard.

The refactoring also improves the clarity and efficiency of the test by consolidating the individual guard tests into a single test case. The test case name accurately reflects its purpose.

apps/judicial-system/web/src/components/PdfButton/PdfButton.tsx (4)

10-11: LGTM!

The changes to the Props interface enhance the flexibility of the PdfButton component by:

  • Making caseId optional, allowing for scenarios where a case ID may not be provided.
  • Adding connectedCaseParentId, which can be used to determine the URL structure when generating the PDF link.

These changes align with the PR objective of improving data accessibility in merged cases.


31-31: LGTM!

Adding connectedCaseParentId to the destructured props allows the component to access the new optional property, which is necessary to utilize it in the component's logic.


44-46: LGTM!

The updated logic for constructing the URL prefix allows the component to generate appropriate PDF links based on the provided properties by conditionally including a segment for mergedCase if connectedCaseParentId is present.

This change enhances the component's functionality in the judicial system application and aligns with the PR objective of improving data accessibility in merged cases.


49-51: LGTM!

The updated final URL construction ensures that the appropriate case ID is used in the generated PDF link by using connectedCaseParentId if it exists, falling back to caseId if it doesn't.

This change enhances the component's ability to handle cases where a parent case ID is relevant and aligns with the PR objective of improving data accessibility in merged cases.

apps/judicial-system/web/src/components/FormProvider/limitedAccessCase.graphql (4)

Line range hint 13-23: Approved: The new attributes enhance case file data granularity.

The addition of the modified, type, state, and size fields to the caseFiles field provides more detailed information about each case file. This enhancement enables advanced querying and filtering capabilities, such as:

  • Sorting files by their last modification date using the modified field.
  • Grouping files by their format using the type field.
  • Filtering out archived or inactive files using the state field.
  • Estimating storage requirements and optimizing file retrieval performance using the size field.

These improvements contribute to a better user experience and more efficient data management.


171-183: Approved: The indictmentCounts field provides valuable granular data.

The introduction of the indictmentCounts field is a significant enhancement to the case data model. By including attributes such as caseId, policeCaseNumber, offenses, substances, lawsBroken, incidentDescription, and legalArguments, this field enables users to access and analyze indictment data at a granular level.

The caseId and policeCaseNumber attributes establish a clear link between indictments and their associated cases, while the offenses, substances, and lawsBroken attributes provide crucial information about the nature of the indictments. Furthermore, the incidentDescription and legalArguments attributes allow for a more in-depth understanding of the circumstances surrounding each indictment.

This level of detail empowers users to make informed decisions and gain valuable insights into the legal proceedings associated with each case.


184-204: Approved: The mergedCases field provides a comprehensive view of related cases.

The introduction of the mergedCases field is a valuable addition to the case data model, as it allows users to retrieve information about related cases that have been merged with the primary case. The nested structure within mergedCases includes attributes such as id, courtCaseNumber, type, policeCaseNumbers, and indictmentSubtypes, providing a comprehensive view of each merged case.

The presence of the caseFiles field within the nested structure is particularly noteworthy, as it ensures that users can access detailed information about the files associated with each merged case. By mirroring the structure of the original caseFiles field, the query maintains consistency and familiarity for users, reducing cognitive load and promoting ease of use.

This holistic approach to representing merged cases empowers users to gain a thorough understanding of the relationships between cases and their associated documentation, ultimately facilitating more informed decision-making and analysis.


Line range hint 1-206: Approved: The file adheres to NextJS best practices and leverages GraphQL effectively.

Upon reviewing the entire file, it is evident that it adheres to the additional instructions provided for files matching the pattern apps/**/*. The use of GraphQL in this NextJS application follows best practices and offers several benefits:

  1. The structure of the query is well-defined, with a clear input type (CaseQueryInput) and a specific set of fields to be returned. This promotes maintainability and scalability.

  2. GraphQL allows for efficient data retrieval by enabling clients to request only the data they need, minimizing over-fetching or under-fetching of data. This can improve application performance by reducing the amount of data transferred over the network.

  3. The .graphql file extension suggests that the query is written in the GraphQL schema language, which is compatible with TypeScript. This compatibility allows for the generation of TypeScript types based on the GraphQL schema, enhancing type safety and catching potential errors during development.

While the query itself does not directly interact with state management or server-side rendering, it is important to note that proper implementation of these techniques in other parts of the NextJS application contributes to a smooth user experience and optimal performance.

Overall, the use of GraphQL in this NextJS application demonstrates adherence to best practices and sets the foundation for an efficient and maintainable system.

apps/judicial-system/web/src/utils/hooks/useFileList/index.ts (5)

17-17: LGTM!

The addition of the optional connectedCaseParentId property to the Parameters interface is a good change that will enable the useFileList hook to handle scenarios involving connected or merged cases. This aligns well with the PR objective of improving data visibility in such cases.


20-20: LGTM!

The destructuring of connectedCaseParentId from the Parameters object is consistent with the updated interface and will allow the hook to access the parent case ID when provided. The destructuring syntax is correct.


104-112: LGTM!

The updated query function call effectively leverages the connectedCaseParentId to determine the appropriate caseId and mergedCaseId values for the GraphQL query. This dynamic adjustment of query parameters based on the case relationship aligns well with the PR objective of improving data visibility in merged cases.

The conditional setting of mergedCaseId ensures that it is only included when both the parent and child case IDs are available, likely to handle specific merged case scenarios. The changes are logically sound and should enable the desired behavior.


114-120: LGTM!

The updated dependency array of the memoized onOpen function is comprehensive and should ensure that the function behaves correctly in response to changes in its dependencies.

The inclusion of caseId and connectedCaseParentId is crucial to ensure that the function always uses the most up-to-date case IDs when making the GraphQL query. This is important for maintaining the accuracy and relevance of the query in scenarios involving merged or connected cases.

The addition of getSignedUrl, limitedAccess, and limitedAccessGetSignedUrl to the dependency array is also necessary, as these values are used within the function body and any changes to them should trigger a re-creation of the memoized function.

Overall, the updated dependency array is well-constructed and should provide the desired behavior.


Line range hint 1-134: Overall assessment: LGTM!

The code changes in the useFileList hook are well-designed and effectively contribute to the PR objective of improving data visibility in merged cases. The introduction of the connectedCaseParentId parameter and the corresponding adjustments to the GraphQL query logic enable the hook to dynamically adapt its behavior based on the case relationship.

The changes are logically sound, maintainable, and align with the goal of enhancing the user experience in scenarios involving connected or merged cases. The updated dependency array of the memoized onOpen function ensures that it remains in sync with its dependencies, providing accurate and relevant behavior.

Overall, the code changes in this file are of high quality and are a positive contribution to the codebase.

apps/judicial-system/api/src/app/modules/file/limitedAccessFile.resolver.ts (1)

87-98: LGTM! Verify the backend service method.

The changes look good and align with the PR objective of improving data accessibility in merged cases. The addition of the mergedCaseId parameter enables the resolver method to handle requests involving merged cases.

Please ensure that:

  1. The backendService.limitedAccessGetCaseFileSignedUrl method signature has been updated to accept the new mergedCaseId parameter.
  2. The behavior of the backend service method has been thoroughly tested for both regular and merged cases.

You can use the following script to verify the backend service method signature:

Verification successful

Backend service method signature verified and updated correctly.

The limitedAccessGetCaseFileSignedUrl method in the backend service has been successfully updated to include the mergedCaseId parameter. Key points:

  1. Method location: ./apps/judicial-system/api/src/app/modules/backend/backend.service.ts
  2. Updated signature: limitedAccessGetCaseFileSignedUrl(caseId: string, id: string, mergedCaseId?: string): Promise<SignedUrl>
  3. The mergedCaseId parameter is optional, allowing the method to handle both merged and non-merged cases.

The resolver in limitedAccessFile.resolver.ts correctly calls this method with all three parameters.

Recommendation:

  • Ensure thorough testing for both merged and non-merged case scenarios, given the optional nature of the mergedCaseId parameter.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the signature of the `limitedAccessGetCaseFileSignedUrl` method in the backend service.

# Test: Search for the method declaration. Expect: The method accepts `caseId`, `id`, and `mergedCaseId` parameters.
rg --type typescript -A 5 $'limitedAccessGetCaseFileSignedUrl\(caseId, id, mergedCaseId\)'

Length of output: 126


Script:

#!/bin/bash
# Description: Verify the signature of the `limitedAccessGetCaseFileSignedUrl` method in the backend service.

# Attempt 1: Use rg without specifying file type
echo "Attempt 1: Using rg without file type specification"
rg -A 5 'limitedAccessGetCaseFileSignedUrl\(caseId, id, mergedCaseId\)'

# Attempt 2: Use ast-grep to search for the method
echo "Attempt 2: Using ast-grep"
ast-grep --lang typescript --pattern 'limitedAccessGetCaseFileSignedUrl($_,$_,$_) { $$$ }'

# Attempt 3: Use find and grep as a fallback
echo "Attempt 3: Using find and grep"
find . -type f -name "*.ts" -exec grep -n -A 5 'limitedAccessGetCaseFileSignedUrl' {} +

Length of output: 2204

apps/judicial-system/backend/src/app/modules/file/limitedAccessFile.controller.ts (2)

39-39: LGTM!

The import statement is correct and follows the project's conventions.


111-118: The changes align with the PR objectives and adhere to the project's best practices.

The addition of the MergedCaseExistsGuard and the modified endpoint route effectively extend the functionality to support merged cases while maintaining the existing security measures. The code segment follows the NextJS best practices, maintains a consistent structure, and leverages TypeScript for type safety.

Great work on enhancing the access control logic and providing flexibility for merged case scenarios!

apps/judicial-system/api/src/app/modules/file/limitedAccessFile.controller.ts (3)

55-58: LGTM!

The updated @Get decorator correctly defines the new route pattern for handling merged case requests. This change aligns with the PR objective of improving access to merged case data.


62-62: Looks good!

The addition of the mergedCaseId parameter and the conditional file path construction logic correctly handle requests for merged cases. This change aligns with the PR objective of improving access to merged case data.

Also applies to: 70-73, 78-78


152-152: Looks good!

The changes to the getIndictmentPdf method, including the updated @Get decorator, the new mergedCaseId parameter, and the conditional file path construction logic, correctly handle requests for merged cases. These changes align with the PR objective of improving access to merged case data and maintain consistency with the getCaseFilesRecordPdf method.

Also applies to: 156-156, 163-166, 171-171

apps/judicial-system/api/src/app/modules/file/file.controller.ts (4)

57-60: LGTM!

The updated @Get decorator for the getCaseFilesRecordPdf method now supports two URL patterns, allowing for retrieving case files associated with both standard and merged cases. The changes enhance the flexibility of the API while maintaining backward compatibility.


64-64: LGTM!

The introduction of the mergedCaseId parameter in the getCaseFilesRecordPdf method allows for handling requests for merged cases. The conditional logic ensures that the correct file path is constructed based on the presence of mergedCaseId, maintaining the existing functionality for standard cases while adding support for merged cases. The changes are backward compatible and do not break existing functionality.

Also applies to: 72-75, 80-80


154-154: LGTM!

The updated @Get decorator for the getIndictmentPdf method now supports two URL patterns, allowing for retrieving indictments associated with both standard and merged cases. The changes enhance the flexibility of the API while maintaining backward compatibility.


158-158: LGTM!

The introduction of the mergedCaseId parameter in the getIndictmentPdf method allows for handling requests for merged cases. The conditional logic ensures that the correct file path is constructed based on the presence of mergedCaseId, maintaining the existing functionality for standard cases while adding support for merged cases. The changes are backward compatible and do not break existing functionality.

Also applies to: 165-168, 173-173

apps/judicial-system/web/src/components/FormProvider/case.graphql (1)

302-311: LGTM! The additional fields enhance the case file data.

The newly added fields modified, type, category, userGeneratedFilename, displayDate, and submittedBy provide more comprehensive information about each case file in merged cases. This aligns well with the PR objective of improving data accessibility.

Specifically, the displayDate and submittedBy fields can help users better understand the context and timeline of the case files.

apps/judicial-system/web/src/routes/Court/Indictments/Summary/Summary.tsx (1)

133-136: Verify if the ConnectedCaseFilesAccordionItem component handles the new prop correctly.

The change looks good as it provides the parent case ID to the ConnectedCaseFilesAccordionItem component, which could enable better management of merged cases.

Please ensure that the ConnectedCaseFilesAccordionItem component is equipped to handle the new connectedCaseParentId prop to avoid any unintended behavior. You can use the following script to verify:

Verification successful

The new prop is correctly handled in the ConnectedCaseFilesAccordionItem component.

The connectedCaseParentId prop is properly defined in the component's interface and correctly passed down to the IndictmentCaseFilesList component. This implementation aligns with the intended use of providing the parent case ID for better management of merged cases.

  • The prop is defined in the Props interface
  • It's correctly destructured in the component's function parameters
  • The prop is passed down to the IndictmentCaseFilesList component as expected

The change has been successfully implemented and appears to work as intended.

Scripts executed

The following scripts were executed for the analysis:

Script:

# Search for the usage of `connectedCaseParentId` prop within the `ConnectedCaseFilesAccordionItem` component.
# Expect: The prop is being used correctly without any errors.
rg --type typescript -A 5 $'connectedCaseParentId' apps/judicial-system/web/src/components/ConnectedCaseFilesAccordionItem

Length of output: 156


Script:

#!/bin/bash

# Check if the file exists
echo "Checking if the file exists:"
fd ConnectedCaseFilesAccordionItem.tsx apps/judicial-system/web/src/components

# List TypeScript files in the components directory
echo -e "\nListing TypeScript files in the components directory:"
fd -e ts -e tsx . apps/judicial-system/web/src/components

# If the file exists, display its content
echo -e "\nDisplaying the content of ConnectedCaseFilesAccordionItem (if it exists):"
fd ConnectedCaseFilesAccordionItem.tsx apps/judicial-system/web/src/components -x cat {}

Length of output: 18635

apps/judicial-system/web/src/routes/Court/Indictments/Overview/Overview.tsx (1)

111-114: LGTM! The addition of connectedCaseParentId prop enhances data accessibility.

Passing the parent case ID to the ConnectedCaseFilesAccordionItem component through the connectedCaseParentId prop is a good approach. It provides the child component with additional context about the parent case, which can be leveraged for further logic or display purposes.

This change aligns with the PR objective of improving data accessibility in merged cases and facilitates better communication and understanding between the involved parties.

apps/judicial-system/web/src/routes/Shared/IndictmentOverview/IndictmentOverview.tsx (4)

13-13: LGTM!

The import statement for ConnectedCaseFilesAccordionItem is correctly added.


68-70: LGTM!

The introduction of hasLawsBroken and hasMergeCases constants improves code readability by abstracting the conditions for checking laws broken and merged cases. The logic for these checks is implemented correctly.


129-142: LGTM!

The conditional rendering logic for displaying the IndictmentsLawsBrokenAccordionItem and ConnectedCaseFilesAccordionItem based on the presence of laws broken and merged cases is implemented correctly. The mapping over workingCase.mergedCases and rendering a ConnectedCaseFilesAccordionItem for each merged case inside a Box with a unique key prop is also done correctly.


Line range hint 1-200: Code adheres to NextJS best practices and TypeScript usage.

The component follows the recommended functional component syntax, uses hooks correctly, and is properly typed using FC and imported types from the schema. The file is located in the routes directory, which aligns with the NextJS file structure for pages.

apps/judicial-system/backend/src/app/modules/file/file.controller.ts (2)

52-52: LGTM!

The import statement for the MergedCaseExistsGuard is syntactically correct. The purpose of the guard is clear based on its name.


Line range hint 132-148: Great work on enhancing the functionality to support merged cases!

The MergedCaseExistsGuard is used appropriately to ensure that a merged case exists before allowing access to the route. The modified route path follows the correct syntax and supports the required endpoints for both standard file requests and those associated with merged cases.

These changes align perfectly with the PR objective of improving data accessibility in merged cases, thereby facilitating better communication and understanding between the involved parties. Well done!

apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx (5)

35-35: LGTM!

The new optional prop connectedCaseParentId is a clear and logical addition to the Props interface. It follows the existing naming convention and its purpose is easily understandable.


43-43: Simplifies the component interface.

The removal of the unused workingCase prop and the modification of the RenderFiles component to only accept RenderFilesProps simplifies the component's interface and improves clarity.


Line range hint 119-130: Consistently passes down the connectedCaseParentId prop.

The connectedCaseParentId prop is consistently passed down to the RenderFiles and PdfButton components in multiple places. This ensures that the prop is available for any future functionality related to connected cases. The changes follow a consistent pattern and do not introduce any apparent issues.

Also applies to: 143-155, 163-171, 171-182, 199-204, 217-217


Line range hint 1-234: Adheres to NextJS best practices and optimally uses TypeScript.

The IndictmentCaseFilesList component follows NextJS best practices by:

  • Using a functional component with hooks for state management and side effects.
  • Placing the component file in the components directory, aligning with the recommended file structure.
  • Efficiently managing global state with the useContext hook.

The component also optimally uses TypeScript by:

  • Defining prop types and other type definitions to ensure type safety.
  • Catching potential type-related issues at compile time.

66-72: Prepares the component for future functionality.

The addition of the connectedCaseParentId prop to the IndictmentCaseFilesList component and its usage in the useFileList hook prepares the component for potential future functionality related to connected cases.

Verify that the useFileList hook correctly handles the connectedCaseParentId prop:

Verification successful

Verification successful: connectedCaseParentId is correctly handled

The useFileList hook in apps/judicial-system/web/src/utils/hooks/useFileList/index.ts correctly handles the connectedCaseParentId prop:

  • It's used as an optional parameter, maintaining backward compatibility.
  • The hook uses it to determine the correct case ID for fetching files, supporting both regular and merged cases.
  • It allows for fetching files from either the main case or the connected parent case.

The IndictmentCaseFilesList component correctly passes the connectedCaseParentId to the useFileList hook, and the usage is consistent across multiple components (e.g., PdfButton, ConnectedCaseFilesAccordionItem), indicating a well-integrated feature.

This change successfully prepares the component for future functionality related to connected cases.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the `useFileList` hook correctly handles the `connectedCaseParentId` prop.

# Test: Search for the usage of `connectedCaseParentId` in the `useFileList` hook. Expect: The prop is used to fetch files related to the connected parent case.
rg --type typescript -A 5 $'connectedCaseParentId' apps/judicial-system/web/src/utils/hooks

Length of output: 125


Script:

#!/bin/bash
# Description: Locate the useFileList hook and verify the usage of connectedCaseParentId

# Step 1: Find the file containing the useFileList hook
echo "Step 1: Locating useFileList hook"
fd -e ts -e tsx useFileList apps/judicial-system/web/src

# Step 2: Search for connectedCaseParentId in the found file(s)
echo "Step 2: Searching for connectedCaseParentId usage"
fd -e ts -e tsx useFileList apps/judicial-system/web/src | xargs rg -A 5 "connectedCaseParentId"

Length of output: 13895

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

80-92: LGTM!

The additional filter conditions enhance the specificity of the cases returned for public prosecution users by ensuring only cases with FINE or RULING decisions and INDICTMENT_SENT_TO_PUBLIC_PROSECUTOR event type are included.

Note: As mentioned in the comment, filtering out other event types should be acceptable for the public prosecutor's case list. However, it's worth verifying that the case list does not rely on any other event types to avoid unintended omissions.


206-206: Looks good!

The simplification of the case type filter condition for cases in the ACCEPTED state improves code readability while maintaining the intended functionality.


Line range hint 209-214: Looks good!

The explicit checks for indictment_ruling_decision as RULING and indictment_review_decision as ACCEPT provide clarity on the specific criteria for completed indictment cases returned for prison admin users.

Note: It's worth verifying that the additional conditions align with the intended behavior and do not exclude any necessary cases that may have different ruling or review decisions.

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

91-111: Excellent work on enhancing the access control for public prosecution users!

The additional checks for indictmentRulingDecision and the presence of the INDICTMENT_SENT_TO_PUBLIC_PROSECUTOR event log ensure that public prosecution users can only access cases that meet the necessary criteria. This strengthens the security and correctness of the access control mechanism.

The changes adhere to the principle of least privilege by granting access only when the required conditions are met, preventing unauthorized access to sensitive case information.

apps/judicial-system/web/src/routes/Court/Indictments/Completed/Completed.tsx (5)

21-21: LGTM!

The import statement looks good. It follows the correct naming convention and imports from the appropriate path.


27-27: LGTM!

The import statement for the custom hook useIndictmentsLawsBroken looks good. It follows the correct naming convention and imports from the appropriate path.


53-53: LGTM!

The lawsBroken constant is declared correctly using the useIndictmentsLawsBroken hook with the workingCase as an argument. The constant name is descriptive and conveys its purpose.


132-134: LGTM!

The hasLawsBroken and hasMergeCases constants are declared correctly with descriptive names. The conditions used to determine their values are logically sound and will help in conditionally rendering UI elements.


153-168: LGTM!

The conditional rendering block is implemented correctly. It uses the hasLawsBroken and hasMergeCases constants to determine whether to render the IndictmentsLawsBrokenAccordionItem and ConnectedCaseFilesAccordionItem components respectively. The rendering logic is clean and easy to understand.

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

267-276: LGTM!

The changes to getCaseFileSignedUrl correctly handle the optional mergedCaseId parameter and construct the URL path accordingly. This enhances the API's capability to retrieve signed URLs for files associated with merged cases while maintaining the existing functionality for standard cases.

The code adheres to NextJS best practices and efficiently uses TypeScript for type safety.


407-415: LGTM!

The changes to limitedAccessGetCaseFileSignedUrl correctly handle the optional mergedCaseId parameter and construct the URL path accordingly. This enhances the API's capability to retrieve signed URLs for files associated with merged cases in a limited access context while maintaining the existing functionality for standard cases.

The code adheres to NextJS best practices and efficiently uses TypeScript for type safety.

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

310-311: LGTM!

The filter conditions correctly select only completed indictment cases for the public prosecutor role.


313-316: Looks good!

The filter condition correctly selects only indictment cases with a ruling decision of either FINE or RULING for the public prosecutor role.


319-320: Looks good!

The filter condition correctly selects only indictment cases that have an event log of type INDICTMENT_SENT_TO_PUBLIC_PROSECUTOR for the public prosecutor role.


381-381: LGTM!

The filter condition correctly includes CaseType.PAROLE_REVOCATION in the list of restriction cases for the prison admin staff role.


384-384: Looks good!

The filter conditions correctly select only completed indictment cases with a ruling decision and an accepted review decision for the prison admin staff role.

apps/judicial-system/backend/src/app/modules/case/limitedAccessCase.controller.ts (11)

Line range hint 88-106: LGTM!

The function is well-structured and uses appropriate guards and interceptors to ensure proper access control and data transformation. The logic for updating the case when opened by the defender is correct.


Line range hint 108-132: LGTM!

The function is well-structured and uses appropriate guards to ensure proper access control and validation. The logic for updating the defendantStatementDate is correct.


Line range hint 134-178: LGTM!

The function is well-structured and uses appropriate guards to ensure proper access control and validation. The logic for updating the case state based on the provided transition is correct, including handling special cases for appeal-related transitions.


Line range hint 180-189: LGTM!

The function is simple and uses an appropriate guard to ensure proper access control. It correctly delegates the actual retrieval to the limitedAccessCaseService.


Line range hint 191-216: LGTM!

The function is well-structured and uses appropriate guards to ensure proper access control and validation. It correctly delegates the actual PDF generation to the pdfService.


Line range hint 218-255: LGTM!

The function is well-structured and uses appropriate guards to ensure proper access control and validation. It correctly validates that the provided police case number is associated with the case and delegates the actual PDF generation to the pdfService. The updated route definition allows handling requests for merged cases.


Line range hint 257-282: LGTM!

The function is well-structured and uses appropriate guards to ensure proper access control and validation. It correctly delegates the actual PDF generation to the pdfService.


Line range hint 284-308: LGTM!

The function is well-structured and uses appropriate guards to ensure proper access control and validation. It correctly delegates the actual PDF generation to the pdfService.


Line range hint 310-345: LGTM!

The function is well-structured and uses appropriate guards to ensure proper access control and validation. It correctly validates that the case is in the accepted state before generating the custody notice and delegates the actual PDF generation to the pdfService.


Line range hint 347-410: LGTM!

The function is well-structured and uses appropriate guards to ensure proper access control and validation. It correctly delegates the actual PDF generation to the pdfService. The updated route definition allows handling requests for merged cases.


Line range hint 412-440: LGTM!

The function is well-structured and uses appropriate guards to ensure proper access control and validation. It correctly delegates the actual ZIP generation to the limitedAccessCaseService.

apps/judicial-system/web/src/routes/Prosecutor/Indictments/Overview/Overview.tsx (3)

18-18: LGTM!

The import statement for ConnectedCaseFilesAccordionItem follows the project's naming convention and is correctly referenced from the @island.is/judicial-system-web/src/components directory.


157-159: LGTM!

The new variables hasLawsBroken and hasMergeCases are correctly implemented to check for the existence of broken laws and merged cases, respectively. The variable names are descriptive and follow the project's naming convention.


216-229: LGTM!

The conditional rendering logic for displaying the IndictmentsLawsBrokenAccordionItem and ConnectedCaseFilesAccordionItem components based on the hasLawsBroken and hasMergeCases variables is implemented correctly. The key prop is properly set for each rendered ConnectedCaseFilesAccordionItem, and the necessary props are passed correctly.

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

173-173: LGTM!

The additions to the include array enhance the data retrieval capabilities by fetching indictmentCounts and mergedCases along with the case data. This aligns with the PR objective of improving data accessibility in merged cases.

Also applies to: 223-252


Line range hint 288-380: Skipped review.

This function is not directly related to the changes made in this PR. Reviewing it is not necessary.


Line range hint 382-400: Skipped review.

This function is not directly related to the changes made in this PR. Reviewing it is not necessary.


Line range hint 402-434: Skipped review.

This function is not directly related to the changes made in this PR. Reviewing it is not necessary.


Line range hint 436-467: Skipped review.

This function is not directly related to the changes made in this PR. Reviewing it is not necessary.


Line range hint 469-516: Skipped review.

This function is not directly related to the changes made in this PR. Reviewing it is not necessary.

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

563-566: LGTM!

The changes to the getCaseFilesRecordPdf method look good. The addition of the MergedCaseExistsGuard enhances the validation and security of the endpoint by ensuring that the provided merged case ID exists and is associated with the given case ID.


723-726: LGTM!

The changes to the getIndictmentPdf method look good. The addition of the MergedCaseExistsGuard enhances the validation and security of the endpoint by ensuring that the provided merged case ID exists and is associated with the given case ID.

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

323-326: LGTM!

The addition of new case file categories to include for merged cases looks good. It aligns with the PR objective of enhancing data visibility for both parties in merged cases.


399-399: Looks good!

Including eventLogs in the listOrder array ensures that case list results are ordered considering the chronology of events. This can provide a useful view of case activities.

Copy link
Member

@oddsson oddsson left a comment

Choose a reason for hiding this comment

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

Nice, just a few wonderings ;)

@gudjong
Copy link
Member Author

gudjong commented Sep 25, 2024

Nice, just a few wonderings ;)

Good comments, I have addressed them all.

@gudjong gudjong requested a review from oddsson September 25, 2024 12:02
@oddsson oddsson added the automerge Merge this PR as soon as all checks pass label Sep 26, 2024
@kodiakhq kodiakhq bot merged commit d574949 into main Sep 26, 2024
33 checks passed
@kodiakhq kodiakhq bot deleted the j-s/merge-case-access branch September 26, 2024 09:33
thoreyjona pushed a commit that referenced this pull request Oct 2, 2024
* Fixes db queries

* Shows merged cases to prosecutors and defenders

* Only returns completed indictments that ended with a fine or a ruling and have been sent to the public prosecutor

* Updates unit tests

* Opens case files from merged cases

* Opens generated indictments and case files records of merged cases

* Updates unit tests

* Removes console log

* Fixes broken web build

* Fixes accordion declarations and adds comments

---------

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
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants