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(api): add ff to resolver #16865

Merged
merged 2 commits into from
Nov 14, 2024
Merged

Conversation

disaerna
Copy link
Member

@disaerna disaerna commented Nov 14, 2024

Api - Health Directorate

What

Add feature flag to resolver

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 FeatureFlagModule to enhance feature management.
    • Added new feature flags for health-related pages: servicePortalHealthVaccinationsPageEnabled and servicePortalHealthOrganDonationPageEnabled.
    • Enhanced HealthDirectorateResolver with feature flags for specific methods, allowing granular access control.
  • Bug Fixes

    • Improved security by adding FeatureFlagGuard to the resolver's guards.

@disaerna disaerna requested review from a team as code owners November 14, 2024 13:04
@disaerna disaerna added the automerge Merge this PR as soon as all checks pass label Nov 14, 2024
Copy link
Contributor

coderabbitai bot commented Nov 14, 2024

Walkthrough

The changes in this pull request involve the integration of a new FeatureFlagModule into the HealthDirectorateModule, enhancing the existing module's capabilities. Additionally, the HealthDirectorateResolver has been updated to include new feature flags that control access to specific methods, thereby allowing for more granular feature management. Two new entries have also been added to the Features enum to support these updates, specifically targeting health-related functionalities within the service portal.

Changes

File Path Change Summary
libs/api/domains/health-directorate/src/lib/health-directorate.module.ts Added FeatureFlagModule to the imports array in the HealthDirectorateModule.
libs/api/domains/health-directorate/src/lib/health-directorate.resolver.ts Updated HealthDirectorateResolver to include FeatureFlagGuard and added @FeatureFlag decorators to methods for feature management.
libs/feature-flags/src/lib/features.ts Introduced two new entries in the Features enum: servicePortalHealthVaccinationsPageEnabled and servicePortalHealthOrganDonationPageEnabled.

Possibly related PRs

Suggested labels

high priority

Suggested reviewers

  • thorkellmani
  • brynjarorng

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: 0

🧹 Outside diff range and nitpick comments (1)
libs/feature-flags/src/lib/features.ts (1)

48-49: Add JSDoc comments to document the feature flags.

The new feature flags follow the established naming conventions and are correctly placed in the service portal modules section. Consider adding JSDoc comments to document their purpose and usage:

+  /** Controls the visibility of vaccinations page in the service portal's health section */
   servicePortalHealthVaccinationsPageEnabled = 'isServicePortalHealthVaccinationsPageEnabled',
+  /** Controls the visibility of organ donation page in the service portal's health section */
   servicePortalHealthOrganDonationPageEnabled = 'isServicePortalHealthOrganDonationPageEnabled',
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e47d2b9 and a9e1632.

📒 Files selected for processing (3)
  • libs/api/domains/health-directorate/src/lib/health-directorate.module.ts (1 hunks)
  • libs/api/domains/health-directorate/src/lib/health-directorate.resolver.ts (4 hunks)
  • libs/feature-flags/src/lib/features.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
libs/api/domains/health-directorate/src/lib/health-directorate.module.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."
libs/api/domains/health-directorate/src/lib/health-directorate.resolver.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."
libs/feature-flags/src/lib/features.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."
🔇 Additional comments (5)
libs/api/domains/health-directorate/src/lib/health-directorate.module.ts (1)

5-8: LGTM! Clean integration of feature flags.

The addition of FeatureFlagModule is well-structured and follows NestJS best practices. This change appropriately supports the feature flag implementation in the resolver.

Let's verify the feature flag implementation across the codebase:

✅ Verification successful

Feature flag integration is properly implemented and verified

The verification confirms that:

  • FeatureFlagModule is correctly imported and used in the module
  • The resolver properly implements feature flags using @FeatureFlag decorator with the correct feature flag servicePortalHealthOrganDonationPageEnabled
  • The feature flag is properly defined in the features enum
  • The implementation follows the standard pattern with @UseGuards(FeatureFlagGuard)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the feature flag implementation in related files
# Expected: Find corresponding feature flag usage in resolver and proper configuration

# Check resolver implementation
ast-grep --pattern 'class HealthDirectorateResolver {
  $$$
  @UseGuards(FeatureFlagGuard)
  $$$
}'

# Check feature flag configuration
rg -l "servicePortalHealthOrganDonationPageEnabled|servicePortalHealthVaccinationsPageEnabled" --type ts

Length of output: 322


Script:

#!/bin/bash
# Let's check the actual implementation in the resolver and feature flags
rg -A 5 "@UseGuards\(FeatureFlagGuard\)" libs/api/domains/health-directorate/src/lib/health-directorate.resolver.ts

# Check feature flags configuration
cat libs/feature-flags/src/lib/features.ts

Length of output: 6055


Script:

#!/bin/bash
# Let's check the resolver implementation one more time with more context
rg -B 5 -A 10 "HealthDirectorateResolver" libs/api/domains/health-directorate/src/lib/health-directorate.resolver.ts

Length of output: 694

libs/api/domains/health-directorate/src/lib/health-directorate.resolver.ts (3)

25-29: LGTM! Imports are well-structured

The feature flag imports are correctly organized and follow tree-shaking best practices.


30-30: LGTM! Guard ordering is correct

The FeatureFlagGuard is correctly placed after authentication and scope guards, ensuring proper authorization flow.


42-42: Consider adding feature flag to resolveOrganList method

While the main organ donation endpoints are protected by feature flags, the resolveOrganList resolver field is not. Since it's part of the organ donation functionality, consider adding the same feature flag for consistency.

Let's verify the feature flag usage:

Also applies to: 66-66, 81-81

libs/feature-flags/src/lib/features.ts (1)

48-49: Verify feature flag usage in the resolver.

Let's verify that these feature flags are properly implemented in the resolver and that no unguarded routes exist.

✅ Verification successful

Let me check the resolver implementation to verify the feature flag usage.


Feature flags are properly implemented in the resolver

The verification shows that both feature flags are correctly used:

  • @FeatureFlag(Features.servicePortalHealthOrganDonationPageEnabled) guards both getDonorStatus and updateDonorStatus methods
  • @FeatureFlag(Features.servicePortalHealthVaccinationsPageEnabled) guards the getVaccinations method

All health-related resolver methods are properly protected with their respective feature flags.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify feature flag implementation in resolver and routes

# Check for feature flag usage in resolver
echo "Checking feature flag usage in resolver..."
ast-grep --pattern 'class $_ {
  $$$
  @FeatureFlag($flag)
  $$$
  get$_($$_) {
    $$$
  }
  $$$
}'

# Check for any unguarded health-related routes
echo "Checking for unguarded health-related routes..."
rg -l "servicePortalHealth(Vaccinations|OrganDonation)" --type ts

Length of output: 484


Script:

#!/bin/bash
# Check the implementation in the resolver
echo "Checking resolver implementation..."
rg -A 10 "servicePortalHealth(Vaccinations|OrganDonation)" libs/api/domains/health-directorate/src/lib/health-directorate.resolver.ts

# Check for any routes or components using these feature flags
echo "Checking for routes and components..."
rg -A 5 "isServicePortalHealth(Vaccinations|OrganDonation)PageEnabled"

Length of output: 2305

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.45%. Comparing base (64ad820) to head (87da5e5).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16865   +/-   ##
=======================================
  Coverage   36.44%   36.45%           
=======================================
  Files        6851     6851           
  Lines      143567   143577   +10     
  Branches    40980    40976    -4     
=======================================
+ Hits        52328    52340   +12     
+ Misses      91239    91237    -2     
Flag Coverage Δ
air-discount-scheme-backend 54.08% <100.00%> (+0.02%) ⬆️
air-discount-scheme-web 0.00% <ø> (ø)
api 3.34% <ø> (ø)
api-domains-air-discount-scheme 37.08% <100.00%> (+0.06%) ⬆️
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
api-domains-communications 39.64% <100.00%> (+0.01%) ⬆️
api-domains-criminal-record 47.56% <100.00%> (+0.07%) ⬆️
api-domains-driving-license 44.50% <100.00%> (+0.03%) ⬆️
api-domains-education 30.62% <100.00%> (+0.06%) ⬆️
api-domains-health-insurance 34.43% <100.00%> (+0.09%) ⬆️
api-domains-mortgage-certificate 34.74% <100.00%> (+0.05%) ⬆️
api-domains-payment-schedule 41.31% <100.00%> (+0.05%) ⬆️
application-api-files 62.52% <100.00%> (+0.06%) ⬆️
application-core 70.75% <ø> (ø)
application-system-api 40.99% <100.00%> (+<0.01%) ⬆️
application-template-api-modules 27.64% <100.00%> (-0.01%) ⬇️
application-templates-accident-notification 28.98% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.87% <ø> (ø)
application-templates-driving-license 18.26% <ø> (ø)
application-templates-estate 12.14% <ø> (ø)
application-templates-example-payment 24.80% <ø> (ø)
application-templates-financial-aid 15.48% <ø> (ø)
application-templates-general-petition 23.07% <ø> (ø)
application-templates-inheritance-report 6.52% <ø> (ø)
application-templates-marriage-conditions 15.04% <ø> (ø)
application-templates-mortgage-certificate 43.34% <ø> (ø)
application-templates-parental-leave 29.86% <ø> (ø)
application-types 6.60% <ø> (ø)
application-ui-components 1.27% <ø> (ø)
application-ui-shell 20.83% <ø> (ø)
clients-charge-fjs-v2 24.11% <ø> (ø)
clients-driving-license 40.28% <100.00%> (+0.08%) ⬆️
clients-driving-license-book 43.50% <100.00%> (+0.05%) ⬆️
clients-financial-statements-inao 49.06% <100.00%> (+0.07%) ⬆️
clients-license-client 1.26% <ø> (ø)
clients-regulations 42.36% <100.00%> (+0.08%) ⬆️
clients-rsk-company-registry 29.76% <ø> (ø)
clients-rsk-personal-tax-return 38.00% <ø> (ø)
clients-smartsolutions 12.77% <ø> (ø)
clients-syslumenn 49.23% <100.00%> (+0.04%) ⬆️
clients-zendesk 50.61% <100.00%> (+0.24%) ⬆️
cms 0.42% <ø> (ø)
cms-translations 38.94% <100.00%> (+0.01%) ⬆️
dokobit-signing 62.76% <100.00%> (+0.17%) ⬆️
download-service 44.16% <100.00%> (+0.02%) ⬆️
email-service 60.57% <100.00%> (+0.16%) ⬆️
feature-flags 90.62% <100.00%> (+0.14%) ⬆️
file-storage 46.09% <100.00%> (+0.22%) ⬆️
financial-aid-backend 51.29% <100.00%> (+0.02%) ⬆️
judicial-system-api 19.76% <ø> (ø)
judicial-system-audit-trail 68.86% <100.00%> (+0.16%) ⬆️
judicial-system-backend 55.14% <100.00%> (+<0.01%) ⬆️
judicial-system-message 66.99% <100.00%> (+0.12%) ⬆️
judicial-system-message-handler 47.99% <100.00%> (+0.18%) ⬆️
judicial-system-scheduler 70.67% <100.00%> (+0.04%) ⬆️
license-api 42.60% <100.00%> (+0.04%) ⬆️
nest-config 78.00% <100.00%> (+0.12%) ⬆️
nest-feature-flags 51.09% <100.00%> (+0.12%) ⬆️
nova-sms 62.09% <100.00%> (+0.18%) ⬆️
portals-admin-regulations-admin 1.85% <ø> (ø)
portals-core 15.89% <ø> (ø)
services-auth-admin-api 52.50% <100.00%> (+<0.01%) ⬆️
services-auth-delegation-api 58.22% <100.00%> (-0.06%) ⬇️
services-auth-ids-api 52.08% <100.00%> (-0.01%) ⬇️
services-auth-personal-representative 45.62% <100.00%> (+0.01%) ⬆️
services-auth-personal-representative-public 41.79% <100.00%> (+0.01%) ⬆️
services-auth-public-api 49.59% <100.00%> (+0.01%) ⬆️
services-endorsements-api 53.26% <100.00%> (+0.02%) ⬆️
services-sessions 65.49% <100.00%> (+0.03%) ⬆️
services-university-gateway 49.34% <100.00%> (+0.14%) ⬆️
services-user-notification 46.92% <100.00%> (+<0.01%) ⬆️
services-user-profile 61.89% <100.00%> (+0.01%) ⬆️
web 1.80% <ø> (ø)

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

Files with missing lines Coverage Δ
libs/feature-flags/src/lib/features.ts 100.00% <100.00%> (ø)

... and 8 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 64ad820...87da5e5. Read the comment docs.

Copy link
Member

@jonbjarnio jonbjarnio left a comment

Choose a reason for hiding this comment

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

🚀

@datadog-island-is
Copy link

datadog-island-is bot commented Nov 14, 2024

Datadog Report

All test runs 5ffed81 🔗

68 Total Test Services: 0 Failed, 66 Passed
🔻 Test Sessions change in coverage: 1 decreased (-0.18%), 26 increased, 173 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
air-discount-scheme-backend 0 0 0 82 0 30.57s N/A Link
air-discount-scheme-web 0 0 0 2 0 9.2s N/A Link
api 0 0 0 4 0 3.01s N/A Link
api-domains-air-discount-scheme 0 0 0 6 0 19.85s N/A Link
api-domains-assets 0 0 0 3 0 12.58s N/A Link
api-domains-auth-admin 0 0 0 18 0 12.51s N/A Link
api-domains-communications 0 0 0 5 0 30.56s N/A Link
api-domains-criminal-record 0 0 0 5 0 8.91s 1 increased (+0.08%) Link
api-domains-driving-license 0 0 0 23 0 32.43s N/A Link
api-domains-education 0 0 0 8 0 22.9s 1 increased (+0.06%) Link

🔻 Code Coverage Decreases vs Default Branch (1)

  • services-auth-delegation-api - jest 51.74% (-0.18%) - Details

@kodiakhq kodiakhq bot merged commit b434660 into main Nov 14, 2024
201 checks passed
@kodiakhq kodiakhq bot deleted the api/feature-flag-health-directorate branch November 14, 2024 14:50
disaerna added a commit that referenced this pull request Nov 14, 2024
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
kodiakhq bot added a commit that referenced this pull request Nov 15, 2024
* fix(my-pages): health vaccination tags & locale (#16567)

* fix: tags

* feat: add locale to service WIP

* feat: add locale from service

* feat: add locale to query call

* fix(api): add ff to resolver (#16865)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(api): add  correct scope (#16874)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
jonnigs pushed a commit that referenced this pull request Nov 26, 2024
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