Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(j-s): Notifications sent when court officials are assigned #17169

Merged
merged 19 commits into from
Dec 16, 2024

Conversation

oddsson
Copy link
Member

@oddsson oddsson commented Dec 6, 2024

Notifications sent when court officials are assigned

Asana

What

Send notifications to judges and registrars when they are assigned to a case.

Why

This is done to inform those users about the cases they are responsible for.

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

  • New Features

    • Introduced new notification messages for court officials when assigned to cases.
    • Added notification methods for district court judges and registrars.
  • Enhancements

    • Updated notification rules to include new notification types for judges and registrars.
    • Enhanced notification service to support new assignment notifications.
  • Bug Fixes

    • Corrected a typo in notification rules.
  • Chores

    • Removed outdated notification type from the enum.

Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Walkthrough

This pull request introduces enhancements to the notification system within the judicial application. It adds a new message group for court official assignments, updates notification rules for judges and registrars, and introduces new methods to send notifications when these officials are assigned to cases. Additionally, new notification types are added to the relevant enums, ensuring that the system can correctly handle and dispatch notifications related to case assignments for district court judges and registrars.

Changes

File Change Summary
apps/judicial-system/backend/src/app/messages/notifications.ts Added new message group courtOfficialAssignedEmail with subject and body messages for notifications regarding case assignments.
apps/judicial-system/backend/src/app/modules/case/case.service.ts Introduced private methods: addMessagesForDistrictCourtJudgeAssignedToQueue and addMessagesForDistrictCourtRegistrarAssignedToQueue. Modified update method to check for changes in judge/registrar assignments for indictments.
apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts Updated dtoFieldValues for districtCourtJudgeNotificationRule and districtCourtRegistrarNotificationRule to include new notification types: DISTRICT_COURT_JUDGE_ASSIGNED and DISTRICT_COURT_REGISTRAR_ASSIGNED.
apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts Added methods: sendDistrictCourtJudgeAssignedNotifications and sendDistrictCourtRegistrarAssignedNotifications. Updated sendNotification method to handle new notification types.
libs/judicial-system/types/src/lib/notification.ts Added enum values DISTRICT_COURT_JUDGE_ASSIGNED and DISTRICT_COURT_REGISTRAR_ASSIGNED to CaseNotificationType. Updated NotificationType enum and marked ADVOCATE_ASSIGNED for removal.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • unakb
  • gudjong

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 54c8da5 and 270f8ea.

📒 Files selected for processing (3)
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts (5 hunks)
👮 Files not reviewed due to content moderation or server errors (3)
  • apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts
  • apps/judicial-system/backend/src/app/modules/case/case.service.ts
  • apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts
🧰 Additional context used
📓 Path-based instructions (3)
apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.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/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."
📓 Learnings (2)
apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts (1)
Learnt from: gudjong
PR: island-is/island.is#16556
File: apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts:13-16
Timestamp: 2024-11-12T15:15:26.274Z
Learning: In the `CaseNotificationType` enum in `libs/judicial-system/types/src/lib/notification.ts`, `APPEAL_CASE_FILES_UPDATED` and `CASE_FILES_UPDATED` are distinct notification types that need to remain separate, as they serve different purposes in the notification system.
apps/judicial-system/backend/src/app/modules/notification/services/caseNotification/caseNotification.service.ts (3)
Learnt from: oddsson
PR: island-is/island.is#16671
File: apps/judicial-system/web/src/routes/Shared/RouteHandler/RouteHandler.tsx:17-20
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In the `@island.is/judicial-system-web` project, `@island.is/judicial-system-web/src/components` is a shared index, and importing directly from it is acceptable.
Learnt from: gudjong
PR: island-is/island.is#16452
File: apps/judicial-system/backend/src/app/modules/notification/internalNotification.service.ts:1845-1854
Timestamp: 2024-11-12T15:15:11.835Z
Learning: In the `sendCaseFilesUpdatedNotifications` method within `internalNotification.service.ts`, when the `user` is a defence user, it is intended to send notifications to the prosecutor.
Learnt from: gudjong
PR: island-is/island.is#16556
File: apps/judicial-system/backend/src/app/modules/notification/guards/rolesRules.ts:13-16
Timestamp: 2024-11-12T15:15:26.274Z
Learning: In the `CaseNotificationType` enum in `libs/judicial-system/types/src/lib/notification.ts`, `APPEAL_CASE_FILES_UPDATED` and `CASE_FILES_UPDATED` are distinct notification types that need to remain separate, as they serve different purposes in the notification system.

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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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.

@oddsson oddsson marked this pull request as ready for review December 6, 2024 21:53
@oddsson oddsson requested a review from a team as a code owner December 6, 2024 21:53
@oddsson oddsson changed the title J s/court officials notifications feat(j-s): Notifications sent when court officials are assigned Dec 6, 2024
Copy link

codecov bot commented Dec 6, 2024

Codecov Report

Attention: Patch coverage is 31.03448% with 20 lines in your changes missing coverage. Please review.

Project coverage is 35.73%. Comparing base (4fcc879) to head (dcf4877).

Files with missing lines Patch % Lines
...vices/caseNotification/caseNotification.service.ts 0.00% 14 Missing ⚠️
...ystem/backend/src/app/modules/case/case.service.ts 53.84% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17169      +/-   ##
==========================================
- Coverage   35.74%   35.73%   -0.01%     
==========================================
  Files        6937     6937              
  Lines      148255   148284      +29     
  Branches    42297    42311      +14     
==========================================
+ Hits        52989    52995       +6     
- Misses      95266    95289      +23     
Flag Coverage Δ
api 3.33% <ø> (ø)
api-domains-auth-admin 48.49% <ø> (ø)
api-domains-communications 39.41% <ø> (ø)
application-system-api 38.75% <ø> (+<0.01%) ⬆️
application-template-api-modules 27.81% <ø> (ø)
cms 0.39% <ø> (ø)
cms-translations 38.74% <ø> (ø)
judicial-system-api 20.20% <100.00%> (+0.04%) ⬆️
judicial-system-formatters 78.33% <100.00%> (+0.04%) ⬆️
judicial-system-message 66.48% <ø> (ø)
judicial-system-message-handler 48.16% <ø> (ø)
judicial-system-scheduler 70.92% <100.00%> (+0.04%) ⬆️
judicial-system-types 42.09% <0.00%> (-0.13%) ⬇️
judicial-system-web 27.93% <ø> (ø)
services-user-notification 46.54% <ø> (ø)
web 2.41% <ø> (ø)

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

Files with missing lines Coverage Δ
...l-system/backend/src/app/messages/notifications.ts 100.00% <ø> (ø)
.../src/app/modules/notification/guards/rolesRules.ts 100.00% <ø> (ø)
libs/judicial-system/types/src/lib/notification.ts 100.00% <100.00%> (ø)
...ystem/backend/src/app/modules/case/case.service.ts 89.45% <53.84%> (-0.84%) ⬇️
...vices/caseNotification/caseNotification.service.ts 79.51% <0.00%> (-1.44%) ⬇️

... and 1 file 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 4fcc879...dcf4877. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Dec 6, 2024

Datadog Report

All test runs 137fa0f 🔗

18 Total Test Services: 0 Failed, 17 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.15%), 4 increased, 33 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 2.98s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 13.5s 1 no change Link
api-domains-communications 0 0 0 5 0 36.66s 1 no change Link
api-domains-license-service 0 0 0 0 0 458.13ms 1 no change Link
application-system-api 0 0 0 46 0 2m 13.06s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 4.85s 1 no change Link
cms-translations 0 0 0 3 0 35.1s 1 no change Link
judicial-system-api 0 0 0 61 0 6.62s 1 increased (+0.05%) Link
judicial-system-backend 0 0 0 19363 0 0s N/A Link
judicial-system-formatters 0 0 0 38 0 5.62s 1 increased (+0.02%) Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • judicial-system-types - jest 44.81% (-0.15%) - Details

Copy link
Member

@thorhildurt thorhildurt left a comment

Choose a reason for hiding this comment

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

Looks good! I noticed one small content buggy but otherwise I just left few schmall nits and refactoring suggestion/thoughts ☺️

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 (1)
apps/judicial-system/backend/src/app/modules/case/case.service.ts (1)

1415-1437: Consider using more descriptive boolean variable names

The boolean variables could be more descriptive by using the "is" prefix to better indicate their purpose.

Apply this diff to improve variable naming:

-      const judgeChanged =
+      const isJudgeChanged =
         updatedCase.judge?.nationalId !== theCase.judge?.nationalId
-      const registrarChanged =
+      const isRegistrarChanged =
         updatedCase.registrar?.nationalId !== theCase.registrar?.nationalId

-      if (judgeChanged) {
+      if (isJudgeChanged) {
         await this.addMessagesForDistrictCourtJudgeAssignedToQueue(
           updatedCase,
           user,
         )
       }

-      if (registrarChanged) {
+      if (isRegistrarChanged) {
         await this.addMessagesForDistrictCourtRegistrarAssignedToQueue(
           updatedCase,
           user,
         )
       }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1f1fe4 and 54c8da5.

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

689-701: LGTM! Clean implementation of judge notification

The method follows the established pattern for notification handling and uses the correct notification type.


703-715: LGTM! Clean implementation of registrar notification

The method follows the established pattern for notification handling and uses the correct notification type.

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

859-873: LGTM with a minor formatting suggestion!

The new message group for court official notifications is well-structured and properly internationalized. The implementation:

  • Uses correct message ID namespacing
  • Provides clear descriptions for translators
  • Handles role-specific text appropriately
  • Maintains consistency with existing message patterns

Consider adding a space before the link text for better readability:

-        'Héraðsdómur hefur skráð þig sem {role, select, DISTRICT_COURT_JUDGE {dómara} DISTRICT_COURT_REGISTRAR {dómritara} other {óþekkt}} í máli {courtCaseNumber}. Hægt er að nálgast gögn málsins á {linkStart}yfirlitssíðu málsins í Réttarvörslugátt{linkEnd}',
+        'Héraðsdómur hefur skráð þig sem {role, select, DISTRICT_COURT_JUDGE {dómara} DISTRICT_COURT_REGISTRAR {dómritara} other {óþekkt}} í máli {courtCaseNumber}. Hægt er að nálgast gögn málsins á {linkStart}yfirlitssíðu málsins í Réttarvörslugátt {linkEnd}',

Copy link
Member

@thorhildurt thorhildurt left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link
Member

@gudjong gudjong left a comment

Choose a reason for hiding this comment

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

Nice, except for some redundant code. The new notification types do not come from the client, but rather the case service, and therefore should not be included in client facing enpoints.

@oddsson oddsson added the automerge Merge this PR as soon as all checks pass label Dec 16, 2024
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