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 to prosecutors office in completed indictments #17174

Merged
merged 11 commits into from
Dec 10, 2024

Conversation

unakb
Copy link
Member

@unakb unakb commented Dec 9, 2024

Tilkynning til lögreglu að máli hafi verið lokið með dóm

What

Send notifications to prosecutors office when indictment has been completed with a judgement

Why

So they can react accordingly if verdict needs servicing

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

    • Added support for police institution email configuration.
    • Introduced new notification types for indictment cases and event dispatch.
    • New endpoints for sending indictment case notifications and event notifications.
  • Bug Fixes

    • Updated whitelisted email domains to include new entries.
  • Documentation

    • Enhanced API documentation for new notification types and endpoints.
  • Tests

    • Added unit tests for the IndictmentCaseNotificationService and InternalNotificationController.
  • Chores

    • Updated configuration files across development, staging, and production environments to include new secrets and resource allocations.

Copy link
Contributor

coderabbitai bot commented Dec 9, 2024

Walkthrough

The pull request introduces several changes across multiple files in the judicial system application. Key modifications include the addition of a new secret for police institution emails, updates to notification handling classes and methods, the introduction of new Data Transfer Objects (DTOs), and enhancements to notification types. Additionally, configuration files for different environments are updated to include the new secret. Overall, these changes aim to improve the notification system and its integration with various components of the application.

Changes

File Path Change Summary
apps/judicial-system/backend/infra/judicial-system-backend.ts New secret added: POLICE_INSTITUTIONS_EMAILS: '/k8s/judicial-system/POLICE_INSTITUTIONS_EMAILS'
apps/judicial-system/backend/src/app/messages/notifications.ts Property updated: defaultMessage in emailWhitelistDomains from 'omnitrix.is,kolibri.is' to 'omnitrix.is,kolibri.is,dummy.dd'
apps/judicial-system/backend/src/app/modules/event-log/eventLog.module.ts Method added: forwardRef(() => MessageModule) in the imports array of EventLogModule
apps/judicial-system/backend/src/app/modules/event-log/eventLog.service.ts Constructor updated to include private readonly messageService: MessageService; Method added: private addEventNotificationToQueue(...)
apps/judicial-system/backend/src/app/modules/notification/dto/indictmentCaseNotification.dto.ts New class added: IndictmentCaseNotificationDto with property readonly type!: IndictmentCaseNotificationType
apps/judicial-system/backend/src/app/modules/notification/dto/notificationDispatch.dto.ts New class added: EventNotificationDispatchDto with property readonly type!: EventNotificationType
apps/judicial-system/backend/src/app/modules/notification/internalNotification.controller.ts Methods added: sendIndictmentCaseNotification(...), dispatchEventNotification(...); Method signature updates for existing methods
apps/judicial-system/backend/src/app/modules/notification/notification.config.ts Property added: policeInstitutionEmails in the email object of notificationModuleConfig
apps/judicial-system/backend/src/app/modules/notification/notification.module.ts New service added: IndictmentCaseNotificationService
apps/judicial-system/backend/src/app/modules/notification/notificationDispatch.service.ts Methods added: async dispatchEventNotification(...), private async dispatchIndictmentSentToPublicProsecutorNotifications(...)
apps/judicial-system/backend/src/app/modules/notification/services/indictmentCaseNotification/indictmentCaseNotification.service.ts New class added: IndictmentCaseNotificationService with multiple methods for sending notifications
apps/judicial-system/backend/src/app/modules/notification/services/indictmentCaseNotification/indictmentCaseNotification.strings.ts New constant exported: strings for localized message strings
apps/judicial-system/backend/src/app/modules/notification/test/createTestingNotificationModule.ts Service added: IndictmentCaseNotificationService in the testing module
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/eventNotificationDispatch/eventNotificationDispatch.spec.ts New test suite for InternalNotificationController focusing on event notifications
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/indictmentCaseNotification/sendIndictmentVerdictInfoNotification.spec.ts New test suite for IndictmentCaseService focusing on sending verdict information notifications
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentsWaitingForConfirmationNotifications.spec.ts Method signature updated: sendNotification renamed to sendInstitutionNotification
charts/judicial-system/values.dev.yaml New secret added: POLICE_INSTITUTIONS_EMAILS; HPA metric updated; Resource limits updated
charts/judicial-system/values.prod.yaml New secret added: POLICE_INSTITUTIONS_EMAILS; HPA settings updated; Replica count standardized
charts/judicial-system/values.staging.yaml New secret added: POLICE_INSTITUTIONS_EMAILS; HPA settings updated; Resource limits updated
charts/services/judicial-system-backend/values.dev.yaml New secret added: POLICE_INSTITUTIONS_EMAILS
charts/services/judicial-system-backend/values.prod.yaml New secret added: POLICE_INSTITUTIONS_EMAILS
charts/services/judicial-system-backend/values.staging.yaml New secret added: POLICE_INSTITUTIONS_EMAILS
libs/judicial-system/message/src/lib/message.ts Enum values added: INDICTMENT_CASE_NOTIFICATION, EVENT_NOTIFICATION_DISPATCH
libs/judicial-system/types/src/index.ts New exports added: IndictmentCaseNotificationType, EventNotificationType, CrimeScene, CrimeSceneMap, IndictmentSubtypeMap
libs/judicial-system/types/src/lib/notification.ts New enums added: IndictmentCaseNotificationType, EventNotificationType; Modifications to NotificationType enum

Possibly related PRs

Suggested reviewers

  • oddsson
  • unakb

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 675f413 and 1447591.

📒 Files selected for processing (2)
  • charts/judicial-system/values.prod.yaml (1 hunks)
  • charts/judicial-system/values.staging.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • charts/judicial-system/values.prod.yaml
🔇 Additional comments (3)
charts/judicial-system/values.staging.yaml (3)

228-228: LGTM! HPA metric standardization improves consistency.

The nginxRequestsIrate metric has been standardized to 5 across all services, which enhances maintainability.


228-228: LGTM! The new secret for prosecutor notifications is properly configured.

The secret path follows the established pattern for email-related secrets in the system.

Let's verify the secret is consistently configured across environments:

✅ Verification successful

✅ Secret configuration is consistent across all environments

The POLICE_INSTITUTIONS_EMAILS secret is properly configured with the same path /k8s/judicial-system/POLICE_INSTITUTIONS_EMAILS in all three environments:

  • Development (values.dev.yaml)
  • Staging (values.staging.yaml)
  • Production (values.prod.yaml)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the secret is configured consistently across environments
rg "POLICE_INSTITUTIONS_EMAILS" charts/judicial-system/values.*.yaml

Length of output: 521


228-228: Verify the increased resource allocation for the backend service.

The significant increase in memory (512Mi → 1024Mi) and CPU (350m → 400m) limits suggests higher resource requirements for the new notification feature.

Let's analyze the resource usage patterns:

Also applies to: 228-228


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.

@datadog-island-is
Copy link

datadog-island-is bot commented Dec 9, 2024

Datadog Report

All test runs e320e6d 🔗

17 Total Test Services: 0 Failed, 16 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.58%), 7 increased, 31 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.86s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 13.2s 1 no change Link
api-domains-communications 0 0 0 5 0 32.55s 1 no change Link
api-domains-license-service 0 0 0 0 0 561.99ms 1 no change Link
application-system-api 0 0 0 46 0 2m 27.56s 1 no change Link
application-template-api-modules 0 0 0 118 0 2m 45.04s 1 no change Link
cms-translations 0 0 0 3 0 30.6s 1 no change Link
judicial-system-api 0 0 0 61 0 6.27s 1 increased (+0.2%) Link
judicial-system-backend 0 0 0 21345 0 24m 14.29s 1 increased (+0.1%) Link
judicial-system-formatters 0 0 0 38 0 5.33s 1 increased (+0.12%) Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • judicial-system-types - jest 45.03% (-0.58%) - Details

Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 84.39716% with 22 lines in your changes missing coverage. Please review.

Project coverage is 35.76%. Comparing base (b3e0878) to head (1447591).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...kend/src/app/modules/event-log/eventLog.service.ts 33.33% 8 Missing ⚠️
...dules/notification/notificationDispatch.service.ts 69.23% 4 Missing ⚠️
...Notification/indictmentCaseNotification.service.ts 91.83% 4 Missing ⚠️
...ckend/src/app/modules/event-log/eventLog.module.ts 0.00% 3 Missing ⚠️
...es/notification/internalNotification.controller.ts 92.30% 2 Missing ⚠️
...rc/app/modules/notification/notification.module.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17174      +/-   ##
==========================================
+ Coverage   35.73%   35.76%   +0.03%     
==========================================
  Files        6928     6931       +3     
  Lines      147830   147875      +45     
  Branches    42130    42131       +1     
==========================================
+ Hits        52827    52893      +66     
+ Misses      95003    94982      -21     
Flag Coverage Δ
api 3.33% <ø> (ø)
api-domains-communications 39.42% <ø> (ø)
api-domains-education 31.22% <ø> (ø)
application-api-files 61.73% <ø> (ø)
application-system-api 38.76% <ø> (+0.01%) ⬆️
application-template-api-modules 27.80% <ø> (+<0.01%) ⬆️
file-storage 45.86% <ø> (ø)
judicial-system-api 20.16% <100.00%> (+0.18%) ⬆️
judicial-system-backend 55.88% <84.39%> (+0.13%) ⬆️
judicial-system-formatters 78.28% <100.00%> (+0.17%) ⬆️
judicial-system-message 66.47% <100.00%> (+0.12%) ⬆️
judicial-system-message-handler 48.23% <100.00%> (+0.17%) ⬆️
judicial-system-scheduler 70.97% <100.00%> (+0.23%) ⬆️
judicial-system-types 42.22% <0.00%> (-0.51%) ⬇️
judicial-system-web 27.89% <ø> (ø)
nest-aws 51.93% <ø> (ø)

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% <ø> (ø)
...notification/dto/indictmentCaseNotification.dto.ts 100.00% <100.00%> (ø)
...dules/notification/dto/notificationDispatch.dto.ts 100.00% <100.00%> (ø)
...Notification/indictmentCaseNotification.strings.ts 100.00% <100.00%> (ø)
...tification/test/createTestingNotificationModule.ts 100.00% <100.00%> (ø)
libs/judicial-system/message/src/lib/message.ts 100.00% <100.00%> (ø)
libs/judicial-system/types/src/index.ts 100.00% <100.00%> (ø)
libs/judicial-system/types/src/lib/notification.ts 100.00% <100.00%> (ø)
...rc/app/modules/notification/notification.module.ts 0.00% <0.00%> (ø)
...es/notification/internalNotification.controller.ts 95.06% <92.30%> (-1.87%) ⬇️
... and 4 more

... and 15 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 b3e0878...1447591. Read the comment docs.

@unakb unakb marked this pull request as ready for review December 9, 2024 12:18
@unakb unakb requested review from a team as code owners December 9, 2024 12:18
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Outside diff range and nitpick comments (12)
charts/services/judicial-system-backend/values.dev.yaml (1)

Line range hint 1-6: Note: This is an auto-generated file.

As indicated by the header comment, this file should not be edited manually. Instead, use the "yarn charts" command to regenerate it.

charts/judicial-system/values.dev.yaml (1)

228-228: Consider updating documentation

Since this is a new configuration for prosecutor notifications, consider updating the relevant documentation to reflect this addition and its purpose.

Would you like me to help create a documentation update task or PR?

apps/judicial-system/backend/src/app/modules/notification/services/indictmentCaseNotification/indictmentCaseNotification.service.ts (1)

108-108: Simplify access using optional chaining

The expression theCase.defendants && theCase.defendants[0].serviceRequirement can be simplified using optional chaining for better readability and to handle cases where defendants might be undefined or empty.

Apply this diff to simplify the code:

- serviceRequirement:
-   theCase.defendants && theCase.defendants[0].serviceRequirement,
+ serviceRequirement: theCase.defendants?.[0]?.serviceRequirement,
🧰 Tools
🪛 Biome (1.9.4)

[error] 108-108: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

apps/judicial-system/backend/src/app/modules/notification/dto/indictmentCaseNotification.dto.ts (1)

7-12: LGTM! Consider enhancing API documentation.

The DTO implementation follows best practices with proper validation and type safety.

Consider adding a description to the API property for better documentation:

-  @ApiProperty({ enum: IndictmentCaseNotificationType })
+  @ApiProperty({
+    enum: IndictmentCaseNotificationType,
+    description: 'The type of indictment case notification to be sent to prosecutors'
+  })
apps/judicial-system/backend/src/app/modules/notification/dto/notificationDispatch.dto.ts (1)

17-22: LGTM! Consider reducing decorator duplication.

The implementation is correct and follows established patterns.

Consider creating a decorator factory to reduce duplication between NotificationDispatchDto and EventNotificationDispatchDto:

// Create a utility function for common decorators
function createEnumValidation(enumType: any) {
  return function (target: any, propertyKey: string) {
    IsNotEmpty()(target, propertyKey);
    IsEnum(enumType)(target, propertyKey);
    ApiProperty({ enum: enumType })(target, propertyKey);
  };
}

// Usage in DTOs
export class EventNotificationDispatchDto {
  @createEnumValidation(EventNotificationType)
  readonly type!: EventNotificationType
}
apps/judicial-system/backend/src/app/modules/notification/services/indictmentCaseNotification/indictmentCaseNotification.strings.ts (1)

4-18: Consider adding more context in notification messages

While the messages are well-structured for i18n, consider enhancing them with additional context that might be valuable for prosecutors:

  • Include judgment date in the subject
  • Add case type or category in the body
  • Consider including a direct link to the case in LÖKE system
 indictmentCompletedWithRuling: defineMessages({
   subject: {
     id: 'judicial.system.backend:indictment_case_notifications.verdict_service.subject',
-    defaultMessage: 'Máli lokið {courtCaseNumber}',
+    defaultMessage: 'Máli lokið {courtCaseNumber} - {judgmentDate}',
     description:
       'Notað sem titill í tilkynningu um stöðu birtingar dóms í lokinni ákæru',
   },
   body: {
     id: 'judicial.system.backend:indictment_case_notifications.verdict_service.body',
     defaultMessage:
-      'Máli {courtCaseNumber} hjá {courtName} hefur verið lokið.\n\nNiðurstaða: Dómur\n\n{serviceRequirement, select, REQUIRED {Birta skal dómfellda dóminn} NOT_REQUIRED {Birting dóms ekki þörf} NOT_APPLICABLE {Dómfelldi var viðstaddur dómsuppkvaðningu} other {}}\n\n{caseOrigin, select, LOKE {Dómur er aðgengilegur í LÖKE.} other {}}',
+      'Máli {courtCaseNumber} ({caseType}) hjá {courtName} hefur verið lokið.\n\nNiðurstaða: Dómur\n\n{serviceRequirement, select, REQUIRED {Birta skal dómfellda dóminn} NOT_REQUIRED {Birting dóms ekki þörf} NOT_APPLICABLE {Dómfelldi var viðstaddur dómsuppkvaðningu} other {}}\n\n{caseOrigin, select, LOKE {Dómur er aðgengilegur í LÖKE: {lokeUrl}} other {}}',
     description:
       'Notað sem body í tilkynningu um stöðu birtingar dóms í lokinni ákæru',
   },
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/eventNotificationDispatch/eventNotificationDispatch.spec.ts (2)

15-15: Add type validation for the case ID

The case ID is created using uuid() but used without type validation. Consider using a proper type assertion or validation.

- const theCase = { id: uuid() } as Case
+ const theCase = { id: uuid(), type: 'INDICTMENT' } as Case & { id: string }

65-76: Enhance the validation test for notification types

The validation test could be more informative by:

  • Providing specific error messages
  • Logging which types are missing
  • Validating the count of notification types
 it('will fail if a new EventNotificationType is missing from the tests', () => {
   const allNotificationTypes = Object.values(EventNotificationType)
   const testedNotificationTypes = notificationScenarios.map(
     (scenario) => scenario.notificationType,
   )

   const missingNotificationTypes = allNotificationTypes.filter(
     (type) => !testedNotificationTypes.includes(type),
   )

-  expect(missingNotificationTypes).toEqual([])
+  expect(missingNotificationTypes).toEqual(
+    [],
+    `Missing test scenarios for notification types: ${missingNotificationTypes.join(', ')}`,
+  )
+  
+  // Ensure we're testing all notification types
+  expect(testedNotificationTypes.length).toBe(
+    allNotificationTypes.length,
+    'Number of test scenarios does not match number of notification types',
+  )
 })
libs/judicial-system/types/src/lib/notification.ts (1)

Line range hint 9-9: Remove or update the ADVOCATE_ASSIGNED comment

The comment indicates this will be removed, but it's still being used in the NotificationType enum. Either remove it now or create a tracking issue for its future removal.

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

1-62: LGTM! Consider extracting test data setup

The test setup is well-structured with proper mocking and test utilities. However, the test data setup could be moved to a separate helper file for better reusability across test suites.

Consider creating a separate helper file like indictmentTestData.ts to store test case data:

// indictmentTestData.ts
export const createTestCase = (overrides = {}) => ({
  id: uuid(),
  court: { name: uuid() },
  origin: CaseOrigin.LOKE,
  defendants: [/* default test data */],
  prosecutor: {/* default test data */},
  ...overrides
});

86-95: Improve test description clarity

While the test logic is correct, the test description could be more explicit about the business rule being tested.

Consider renaming the test to better reflect the business rule:

-    it('should not send a notification if indictment ruling decision is not RULING', async () => {
+    it('should mark notification as delivered without sending email when indictment ruling decision is not RULING', async () => {
apps/judicial-system/backend/src/app/modules/notification/test/createTestingNotificationModule.ts (1)

36-36: Enhance type safety for notification services

The integration of IndictmentCaseNotificationService follows the established pattern, but we can improve type safety.

Consider creating a type for the context object:

interface NotificationTestContext {
  userService: UserService;
  emailService: EmailService;
  // ... other services
  indictmentCaseNotificationService: IndictmentCaseNotificationService;
}

export const createTestingNotificationModule = async (): Promise<NotificationTestContext> => {
  // ... existing implementation
}

Also applies to: 134-134, 163-165

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fb234b4 and af5c738.

📒 Files selected for processing (25)
  • apps/judicial-system/backend/infra/judicial-system-backend.ts (1 hunks)
  • apps/judicial-system/backend/src/app/messages/notifications.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/event-log/eventLog.module.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/event-log/eventLog.service.ts (4 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/dto/indictmentCaseNotification.dto.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/dto/notificationDispatch.dto.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/internalNotification.controller.ts (5 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/notification.config.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/notification.module.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/notificationDispatch.service.ts (2 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/services/indictmentCaseNotification/indictmentCaseNotification.service.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/services/indictmentCaseNotification/indictmentCaseNotification.strings.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/test/createTestingNotificationModule.ts (3 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/eventNotificationDispatch/eventNotificationDispatch.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/indictmentCaseNotification/sendIndictmentVerdictInfoNotification.spec.ts (1 hunks)
  • apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/sendIndictmentsWaitingForConfirmationNotifications.spec.ts (1 hunks)
  • charts/judicial-system/values.dev.yaml (1 hunks)
  • charts/judicial-system/values.prod.yaml (1 hunks)
  • charts/judicial-system/values.staging.yaml (1 hunks)
  • charts/services/judicial-system-backend/values.dev.yaml (1 hunks)
  • charts/services/judicial-system-backend/values.prod.yaml (1 hunks)
  • charts/services/judicial-system-backend/values.staging.yaml (1 hunks)
  • libs/judicial-system/message/src/lib/message.ts (2 hunks)
  • libs/judicial-system/types/src/index.ts (1 hunks)
  • libs/judicial-system/types/src/lib/notification.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/judicial-system/backend/src/app/messages/notifications.ts
🧰 Additional context used
📓 Path-based instructions (18)
apps/judicial-system/backend/src/app/modules/notification/notification.module.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/notification.config.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/infra/judicial-system-backend.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/event-log/eventLog.module.ts (1)

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

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

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/notification/services/indictmentCaseNotification/indictmentCaseNotification.strings.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/dto/notificationDispatch.dto.ts (1)

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

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

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

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

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

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

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/indictmentCaseNotification/sendIndictmentVerdictInfoNotification.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/event-log/eventLog.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."
libs/judicial-system/types/src/index.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
apps/judicial-system/backend/src/app/modules/notification/internalNotification.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."
libs/judicial-system/types/src/lib/notification.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
apps/judicial-system/backend/src/app/modules/notification/services/indictmentCaseNotification/indictmentCaseNotification.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."
libs/judicial-system/message/src/lib/message.ts (1)

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

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
apps/judicial-system/backend/src/app/modules/notification/notificationDispatch.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 (5)
apps/judicial-system/backend/src/app/modules/notification/notification.module.ts (1)
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.
apps/judicial-system/backend/src/app/modules/notification/internalNotification.controller.ts (2)
Learnt from: gudjong
PR: island-is/island.is#15393
File: apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts:28-28
Timestamp: 2024-11-12T15:15:11.835Z
Learning: The `DeliverCancellationNoticeDto` import in `apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts` is used in the `deliverIndictmentCancellationNoticeToCourt` method.
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.
libs/judicial-system/types/src/lib/notification.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/indictmentCaseNotification/indictmentCaseNotification.service.ts (1)
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.
apps/judicial-system/backend/src/app/modules/notification/notificationDispatch.service.ts (2)
Learnt from: gudjong
PR: island-is/island.is#15393
File: apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts:691-711
Timestamp: 2024-11-12T15:15:20.158Z
Learning: The `deliverIndictmentCancellationNoticeToCourt` method in `InternalCaseService` returns `{ delivered: false }` in case of an exception, as error handling is managed by a message queue handler.
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.
🪛 Biome (1.9.4)
apps/judicial-system/backend/src/app/modules/notification/test/internalNotificationController/indictmentCaseNotification/sendIndictmentVerdictInfoNotification.spec.ts

[error] 79-79: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)


[error] 80-80: The assignment should not be in an expression.

The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.

(lint/suspicious/noAssignInExpressions)

apps/judicial-system/backend/src/app/modules/notification/services/indictmentCaseNotification/indictmentCaseNotification.service.ts

[error] 108-108: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (21)
apps/judicial-system/backend/src/app/modules/notification/notification.config.ts (1)

24-29: LGTM! Verify email configuration format.

The implementation follows the established pattern and type safety. However, let's verify the expected format of the POLICE_INSTITUTIONS_EMAILS secret.

✅ Verification successful

Format verified: POLICE_INSTITUTIONS_EMAILS follows the expected structure

The test file confirms that the environment variable follows the expected JSON format of {"institution_id": "[email protected]"}, which matches the type definition in the config. This is demonstrated in the test setup:

process.env.POLICE_INSTITUTIONS_EMAILS = `{"${prosecutorInstitutionId}": "${prosecutorsOfficeEmail}"}`
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the format of POLICE_INSTITUTIONS_EMAILS secret
# Expected format: { "institution_id": "[email protected]" }

# Check if the secret exists and its format
gh api graphql -f query='
{
  repository(owner: "island-is", name: "island.is") {
    object(expression: "HEAD:apps/judicial-system/backend/src/app/modules/notification") {
      ... on Tree {
        entries {
          name
          object {
            ... on Blob {
              text
            }
          }
        }
      }
    }
  }
}' | jq -r '.data.repository.object.entries[] | select(.name | endswith(".test.ts")) | .object.text' | grep -A 5 -B 5 "POLICE_INSTITUTIONS_EMAILS"

Length of output: 490


Script:

#!/bin/bash
# Let's try a different approach to find test files and configuration usage
rg -A 5 -B 5 "POLICE_INSTITUTIONS_EMAILS" --type ts

# Also search for any test files in the notification module
fd "notification.*\.test\.ts" -t f

Length of output: 4869

apps/judicial-system/backend/infra/judicial-system-backend.ts (1)

71-72: LGTM! Secret configuration is properly structured.

The secret is correctly configured following the established pattern and is appropriately grouped with other email-related secrets.

charts/services/judicial-system-backend/values.dev.yaml (1)

141-141: LGTM! Secret configuration matches infrastructure.

The secret configuration is consistent with the infrastructure setup and follows the established pattern.

✅ Verification successful

Let me verify the actual configuration values across environments to ensure complete consistency.


✅ Secret configuration is consistent across all environments

The POLICE_INSTITUTIONS_EMAILS secret path '/k8s/judicial-system/POLICE_INSTITUTIONS_EMAILS' is identical across dev, staging, and production environments, confirming proper infrastructure alignment.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify secret configuration consistency across environments
# Expected: Same secret path in all environment files

# Check if the secret is consistently configured across environments
for env in dev staging prod; do
  echo "Checking $env environment..."
  fd -t f "values.${env}.yaml" charts/services/judicial-system-backend -x grep -l "POLICE_INSTITUTIONS_EMAILS"
done

Length of output: 784


Script:

#!/bin/bash
# Check the actual secret path configuration across environments
for env in dev staging prod; do
  echo "=== ${env} environment ==="
  grep "POLICE_INSTITUTIONS_EMAILS:" "charts/services/judicial-system-backend/values.${env}.yaml" -A 1
done

Length of output: 995

charts/services/judicial-system-backend/values.prod.yaml (1)

141-141: Verify the secret exists in production environment

The addition of POLICE_INSTITUTIONS_EMAILS secret aligns with the PR objective to implement notifications to prosecutors' office. However, we should verify that this secret is properly configured in the production environment.

charts/services/judicial-system-backend/values.staging.yaml (1)

141-141: Verify the secret exists in staging environment

The addition of POLICE_INSTITUTIONS_EMAILS secret is consistent with other environments. Let's verify its existence in staging.

charts/judicial-system/values.dev.yaml (1)

228-228: Verify the secret exists in development environment

The addition of POLICE_INSTITUTIONS_EMAILS secret is consistent with staging and production environments. Let's verify its existence in development.

✅ Verification successful

Secret path is consistent across all environments

The secret path /k8s/judicial-system/POLICE_INSTITUTIONS_EMAILS is correctly configured and consistently defined across all environments (development, staging, and production). The implementation follows the established pattern used for other secrets in the system, such as PRISON_ADMIN_EMAIL.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if the secret exists in AWS Secrets Manager for development environment
# Note: This helps prevent deployment issues due to missing secrets

aws secretsmanager list-secrets --filters Key=name,Values=/k8s/judicial-system/POLICE_INSTITUTIONS_EMAILS

Length of output: 201


Script:

#!/bin/bash
# Let's check if this secret is referenced in other environment files
fd "values.*yaml" charts/judicial-system/ --exec grep -l "POLICE_INSTITUTIONS_EMAILS"

# Also check the related deployment files
fd "deployment.*yaml" charts/judicial-system/ --exec grep -l "POLICE_INSTITUTIONS_EMAILS"

# Check if there's any documentation or configuration mentioning this secret
rg "POLICE_INSTITUTIONS_EMAILS" charts/judicial-system/ -l

Length of output: 478


Script:

#!/bin/bash
# Let's check the actual content of these files to compare the secret paths
echo "=== Development ==="
grep -A 1 "POLICE_INSTITUTIONS_EMAILS" charts/judicial-system/values.dev.yaml

echo -e "\n=== Staging ==="
grep -A 1 "POLICE_INSTITUTIONS_EMAILS" charts/judicial-system/values.staging.yaml

echo -e "\n=== Production ==="
grep -A 1 "POLICE_INSTITUTIONS_EMAILS" charts/judicial-system/values.prod.yaml

Length of output: 831

charts/judicial-system/values.staging.yaml (1)

228-228: LGTM! Verify secret creation in AWS Parameter Store

The addition of the POLICE_INSTITUTIONS_EMAILS secret is consistent with the feature requirements for prosecutor notifications.

Run the following script to verify the secret exists in the staging environment:

charts/judicial-system/values.prod.yaml (1)

228-228: LGTM! Verify secret creation in AWS Parameter Store

The addition of the POLICE_INSTITUTIONS_EMAILS secret in production matches the staging configuration, maintaining environment parity.

Run the following script to verify the secret exists in the production environment:

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

71-83: Implementation of 'dispatchIndictmentSentToPublicProsecutorNotifications' is correct

The method correctly dispatches indictment notification messages to the queue using the MessageService. The message structure aligns with the expected format, and TypeScript types are appropriately used.


85-108: Proper error handling in 'dispatchEventNotification' method

The dispatchEventNotification method effectively handles different notification types with a switch statement. Errors are caught and logged, and the method returns { delivered: false } when an error occurs, ensuring robustness.

apps/judicial-system/backend/src/app/modules/event-log/eventLog.service.ts (1)

27-33: Effective mapping with 'eventToNotificationMap'

The introduction of eventToNotificationMap provides a clear and maintainable way to map event types to notification types, facilitating future expansions.

apps/judicial-system/backend/src/app/modules/notification/internalNotification.controller.ts (3)

87-109: Well-structured addition of 'sendIndictmentCaseNotification' endpoint

The new sendIndictmentCaseNotification endpoint is appropriately defined with correct routing, guards, and dependency injection. The use of CaseTypeGuard ensures only indictment cases are processed.


194-208: Refactored 'sendInstitutionNotification' method is correctly updated

The method now utilizes the InstitutionNotificationDto and properly calls the institutionNotificationService. Logging and API documentation have been updated accordingly.


210-232: Proper implementation of 'dispatchEventNotification' method

The dispatchEventNotification endpoint is well-implemented with appropriate guards and logging. It correctly delegates the notification dispatching to the notificationDispatchService.

apps/judicial-system/backend/src/app/modules/event-log/eventLog.module.ts (1)

11-14: LGTM! Verify circular dependency necessity.

The implementation correctly uses forwardRef for circular dependency resolution.

Let's verify if the circular dependency is necessary by checking the dependencies between EventLogModule and MessageModule:

apps/judicial-system/backend/src/app/modules/notification/notification.module.ts (1)

23-23: LGTM! Service registration looks good

The IndictmentCaseNotificationService is properly imported and registered in the module's providers array.

Also applies to: 51-51

libs/judicial-system/types/src/index.ts (1)

22-23: LGTM! New notification type exports added correctly

The new notification type exports are properly structured and align with the PR objectives for implementing prosecutor notifications.

libs/judicial-system/types/src/lib/notification.ts (2)

51-81: LGTM! NotificationType enum maintains single source of truth

The NotificationType enum properly references the source enums for each notification type, maintaining a single source of truth and making the code more maintainable.


23-25: LGTM! New notification types align with requirements

The new IndictmentCaseNotificationType and EventNotificationType enums are well-structured and their values clearly indicate their purpose.

Let's verify these notification types are used consistently:

Also applies to: 47-49

✅ Verification successful

Notification types are used consistently across the codebase

The verification shows that both notification types are properly integrated:

  • INDICTMENT_VERDICT_INFO is correctly used in notification services and tests
  • INDICTMENT_SENT_TO_PUBLIC_PROSECUTOR is consistently used in event logs, filters, and frontend components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check usage of new notification types
rg "INDICTMENT_VERDICT_INFO|INDICTMENT_SENT_TO_PUBLIC_PROSECUTOR" -t ts

Length of output: 3621

libs/judicial-system/message/src/lib/message.ts (1)

34-35: LGTM! Message types and endpoints properly defined

The new message types and their corresponding endpoints are well-structured and follow the established patterns in the codebase.

Let's verify the endpoint naming consistency:

Also applies to: 73-74

✅ Verification successful

Endpoint naming follows consistent patterns

The endpoint naming for the new message types follows the established patterns in the codebase:

  • Notification-related endpoints use either the notification suffix (e.g., indictmentCaseNotification) or the dispatch pattern (e.g., eventNotification/dispatch)
  • The new endpoints align with existing ones like notification/dispatch and other notification endpoints
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for similar endpoint patterns in the codebase
rg "notification.*dispatch" -t ts

Length of output: 584


Script:

#!/bin/bash
# Check the endpoint mapping in message.ts to verify consistency
rg -A 5 "messageEndpoint = {" -t ts

Length of output: 139


Script:

#!/bin/bash
# Check the endpoint mapping in message.ts with fixed regex
rg -A 5 "messageEndpoint.*=.*{" libs/judicial-system/message/src/lib/message.ts

Length of output: 187


Script:

#!/bin/bash
# View the content of message.ts to check endpoint mappings
cat libs/judicial-system/message/src/lib/message.ts

Length of output: 4725

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

63-63: LGTM! Method rename improves clarity

The change from sendNotification to sendInstitutionNotification better reflects the domain context and improves code readability.

Copy link
Member

@robertaandersen robertaandersen left a comment

Choose a reason for hiding this comment

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

LGTM

@oddsson oddsson added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Dec 10, 2024
@kodiakhq kodiakhq bot merged commit 22c5b52 into main Dec 10, 2024
59 checks passed
@kodiakhq kodiakhq bot deleted the j-s/indictment-complete-modal branch December 10, 2024 13:44
thorhildurt pushed a commit that referenced this pull request Dec 11, 2024
…ts (#17174)

* fix(j-s): Display confirmation modal before completing case

* feat(j-s): Notifications for prosecutor

* chore: charts update dirty files

* chore: nx format:write update dirty files

* fix(j-s): Only send verdict info if there was a ruling

* Update eventLog.service.ts

---------

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

Successfully merging this pull request may close these issues.

4 participants