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): Whitelist config #16974

Merged
merged 4 commits into from
Nov 21, 2024
Merged

fix(j-s): Whitelist config #16974

merged 4 commits into from
Nov 21, 2024

Conversation

unakb
Copy link
Member

@unakb unakb commented Nov 21, 2024

What

Fix whitelist config

Why

Misunderstanding of the node env variable

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 a new configuration option shouldUseWhitelist to control email whitelist behavior based on the environment.
  • Bug Fixes

    • Updated the email sending logic to utilize the new configuration for handling whitelisted emails.

@unakb unakb requested a review from a team as a code owner November 21, 2024 11:05
Copy link
Contributor

coderabbitai bot commented Nov 21, 2024

Walkthrough

The changes in this pull request involve modifications to the email notification handling within the BaseNotificationService class and the introduction of a new configuration property in the notification.config.ts file. Specifically, the condition for using a whitelist for email addresses is updated to rely on shouldUseWhitelist instead of production. Additionally, a new property shouldUseWhitelist is added to the notification configuration, which is determined based on the CONTENTFUL_ENVIRONMENT variable.

Changes

File Change Summary
apps/judicial-system/backend/src/app/modules/notification/baseNotification.service.ts Updated sendEmail method to check this.config.shouldUseWhitelist for handling whitelisted emails.
apps/judicial-system/backend/src/app/modules/notification/notification.config.ts Added shouldUseWhitelist property to notificationModuleConfig, determined by CONTENTFUL_ENVIRONMENT.

Possibly related PRs

  • feat(j-s): Case Files Added Notification #16452: The changes in this PR enhance the notification system for case file updates, which is directly related to the modifications in the BaseNotificationService class's sendEmail method in the main PR, as both involve email notifications and recipient handling.

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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

8-9: Consider improving configuration clarity and documentation

The current implementation has several points that could benefit from improvement:

  1. The default value 'test' for CONTENTFUL_ENVIRONMENT might be too specific
  2. The inverse logic (!== 'master') makes the intent less clear
  3. The configuration lacks documentation explaining the whitelist behavior

Consider this alternative implementation for better clarity:

-    shouldUseWhitelist:
-      env.required('CONTENTFUL_ENVIRONMENT', 'test') !== 'master',
+    // Controls email whitelist functionality
+    // Whitelist is disabled only in production (master) environment
+    shouldUseWhitelist: env.optional('CONTENTFUL_ENVIRONMENT') !== 'master' ?? true,

Please add documentation in the README or configuration guide explaining:

  • The purpose of email whitelisting
  • When it's enabled/disabled
  • How to configure it in different environments
apps/judicial-system/backend/src/app/modules/notification/baseNotification.service.ts (1)

92-94: Enhance type safety for configuration

Per the coding guidelines for TypeScript safety, consider adding type constraints for the config interface.

Add type definitions:

interface NotificationConfig {
  shouldUseWhitelist: boolean;
  email: {
    fromName: string;
    fromEmail: string;
    replyToName: string;
    replyToEmail: string;
  };
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 869bce3 and 9729ae4.

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

8-9: Verify the whitelist configuration usage across the application

The change from NODE_ENV to CONTENTFUL_ENVIRONMENT for determining whitelist behavior is significant. Let's verify its usage.

✅ Verification successful

The whitelist configuration change is correctly implemented and used

The verification shows that the shouldUseWhitelist configuration is properly integrated into the notification system:

  • The configuration is used in baseNotification.service.ts to control email filtering:
    if (!this.config.shouldUseWhitelist && recipients) {
      recipients = await this.handleWhitelist(recipients)
    }
  • The whitelist implementation is robust with proper domain and email filtering through filterWhitelistEmails
  • The change from NODE_ENV to CONTENTFUL_ENVIRONMENT aligns with the system's configuration pattern, where master environment represents production

The inverse logic (!== 'master') is intentional and correctly implements the requirement that whitelist should be used in all environments except master.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check how the whitelist configuration is used across the codebase

# Find all references to shouldUseWhitelist
rg -A 3 "shouldUseWhitelist"

# Find any remaining references to production flag in notification contexts
rg -A 3 "production.*notification" 

Length of output: 1034


Script:

#!/bin/bash
# Let's check the handleWhitelist implementation and any whitelist-related code
ast-grep --pattern 'handleWhitelist($_) {
  $$$
}'

# Also check for any whitelist-related configuration or constants
rg -A 5 "whitelist" -i

Length of output: 32169

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

92-94: Verify whitelist configuration tests

Let's ensure this critical change is properly tested and consistently used across the codebase.

✅ Verification successful

Whitelist implementation is properly tested and configured

The whitelist functionality is well-implemented with:

  • Configuration based on environment (CONTENTFUL_ENVIRONMENT !== 'master')
  • Comprehensive test coverage in formatters.spec.ts
  • Proper domain and email whitelisting with clear default values
  • Appropriate error handling and logging

The implementation is consistent across the codebase with no conflicting usages found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for tests covering whitelist functionality
rg -t typescript -t javascript "shouldUseWhitelist.*test" apps/judicial-system

# Search for other usages of shouldUseWhitelist
rg -t typescript -t javascript "shouldUseWhitelist" apps/judicial-system

# Search for potential legacy uses of production flag in email context
rg -t typescript -t javascript "production.*email" apps/judicial-system

Length of output: 332


Script:

#!/bin/bash
# Search for tests covering whitelist functionality without file type filters
rg "shouldUseWhitelist.*test" apps/judicial-system

# Search for other usages of shouldUseWhitelist
rg "shouldUseWhitelist" apps/judicial-system

# Search for whitelist-related tests
rg "handleWhitelist" apps/judicial-system

Length of output: 696


Script:

#!/bin/bash
# Let's check the notification config implementation
cat apps/judicial-system/backend/src/app/modules/notification/notification.config.ts

# Check for any tests related to notification service
rg -l "notification.*\.spec\." apps/judicial-system

# Check the implementation of handleWhitelist method
rg -A 10 "handleWhitelist" apps/judicial-system/backend/src/app/modules/notification/baseNotification.service.ts

Length of output: 2182


Script:

#!/bin/bash
# Let's check the notifications constants for whitelist configuration
rg -A 5 "emailWhitelist" apps/judicial-system

# Check for any test files in the notification module directory
fd "\.spec\.(ts|js)$" apps/judicial-system/backend/src/app/modules/notification/

# Check the filterWhitelistEmails implementation
rg -A 10 "filterWhitelistEmails" apps/judicial-system

Length of output: 16619

@gudjong gudjong added the automerge Merge this PR as soon as all checks pass label Nov 21, 2024
@datadog-island-is
Copy link

datadog-island-is bot commented Nov 21, 2024

Datadog Report

All test runs c7295f7 🔗

15 Total Test Services: 0 Failed, 13 Passed
⬆️ Test Sessions change in coverage: 1 increased (+0.01%), 28 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 3.1s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 14.67s 1 no change Link
application-system-api 0 0 0 34 0 2m 38.46s 1 no change Link
application-template-api-modules 0 0 0 116 0 2m 23.4s 1 no change Link
auth-api-lib 0 0 0 20 0 27.46s 1 no change Link
judicial-system-backend 0 0 0 21327 0 22m 52.32s 1 no change Link
portals-admin-ids-admin 0 0 0 2 0 6.96s 1 no change Link
services-auth-admin-api 0 0 0 130 0 3m 38.49s 1 no change Link
services-auth-delegation-api 0 0 0 262 0 2m 41.09s 1 no change Link
services-auth-ids-api 0 0 0 152 0 1m 9.36s 1 increased (+0.01%) Link

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 35.62%. Comparing base (05f9988) to head (dd0b79e).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16974   +/-   ##
=======================================
  Coverage   35.62%   35.62%           
=======================================
  Files        6914     6914           
  Lines      145990   145990           
  Branches    41446    41446           
=======================================
  Hits        52011    52011           
  Misses      93979    93979           
Flag Coverage Δ
api 3.34% <ø> (ø)
api-domains-auth-admin 48.49% <ø> (ø)
application-system-api 38.71% <ø> (+<0.01%) ⬆️
application-template-api-modules 27.72% <ø> (+<0.01%) ⬆️
judicial-system-backend 55.60% <100.00%> (ø)
services-auth-admin-api 52.51% <ø> (+<0.01%) ⬆️
services-auth-delegation-api 57.52% <ø> (-0.01%) ⬇️
services-auth-public-api 48.91% <ø> (ø)
services-user-notification 46.74% <ø> (ø)
services-user-profile 56.81% <ø> (ø)

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

Files with missing lines Coverage Δ
...p/modules/notification/baseNotification.service.ts 79.41% <100.00%> (ø)

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 05f9988...dd0b79e. Read the comment docs.

---- 🚨 Try these New Features:

@kodiakhq kodiakhq bot merged commit 6b0e779 into main Nov 21, 2024
56 checks passed
@kodiakhq kodiakhq bot deleted the j-s/fix-whitelist branch November 21, 2024 16:36
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
* fix(j-s): Whitelist config

* Update baseNotification.service.ts

---------

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.

2 participants