Skip to content

refactor: Remove strong dependency from feature flag enum to (de)serialise organization object #40374

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

Merged
merged 1 commit into from
Apr 28, 2025

Conversation

abhvsn
Copy link
Contributor

@abhvsn abhvsn commented Apr 25, 2025

Description

  • Refactor

    • Updated internal handling of feature flags for pending migrations to use string keys instead of enum values, improving consistency and error handling.
  • Tests

    • Adjusted test cases to align with the new string-based feature flag keys, ensuring continued reliability of migration-related features.

/test Settings

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/14657519125
Commit: ab4973c
Cypress dashboard.
Tags: @tag.Settings
Spec:


Fri, 25 Apr 2025 05:39:47 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • Refactor

    • Updated internal handling of feature flags for pending migrations to use string keys instead of enum values, improving consistency and error handling.
  • Tests

    • Adjusted test cases to align with the new string-based feature flag keys, ensuring continued reliability of migration-related features.

Copy link
Contributor

coderabbitai bot commented Apr 25, 2025

Walkthrough

This change refactors the handling of feature flags with pending migrations by replacing the use of the FeatureFlagEnum as map keys with their string name representations throughout the codebase. The update affects domain classes, helper interfaces and implementations, service logic, and related test cases. All relevant method signatures, map declarations, and usages have been updated to use String keys instead of enum instances. Error handling is added for unknown feature flags, and all references to the enum as a map key have been removed for consistency and simplicity.

Changes

File(s) Change Summary
.../domains/ce/OrganizationConfigurationCE.java Changed featuresWithPendingMigration field type from Map<FeatureFlagEnum, FeatureMigrationType> to Map<String, FeatureMigrationType>. Removed enum import.
.../helpers/ce/FeatureFlagMigrationHelperCE.java Updated method signatures to return Map<String, FeatureMigrationType> instead of enum-keyed maps.
.../helpers/ce/FeatureFlagMigrationHelperCEImpl.java Refactored all usages of feature flag keys in migration maps from enum to string. Updated method signatures and internal logic.
.../services/ce/OrganizationServiceCEImpl.java Updated migration logic to handle string keys, added error handling for unknown feature flags.
.../helpers/FeatureFlagMigrationHelperTest.java Updated test maps and assertions to use string keys for feature flags instead of enum constants.
.../services/ce/FeatureFlagServiceCETest.java Modified tests to use string keys for feature flags in mocks and assertions.
.../services/ce/OrganizationServiceCETest.java Changed test setup to use string keys for feature flags in migration maps.

Sequence Diagram(s)

sequenceDiagram
    participant Service as OrganizationServiceCEImpl
    participant Helper as FeatureFlagMigrationHelperCEImpl
    participant Org as Organization

    Service->>Helper: getUpdatedFlagsWithPendingMigration(Org)
    Helper-->>Service: Mono<Map<String, FeatureMigrationType>>
    Service->>Helper: checkAndExecuteMigrationsForFeatureFlag(featureFlagEnum, Org)
    Helper-->>Service: Migration result
    Service->>Org: Remove featureFlagKey from pending migrations
Loading

Suggested labels

Enhancement, ok-to-test

Suggested reviewers

  • NilanshBansal

Poem

Feature flags once enums, now strings in a map,
Refactored with care, no code overlap.
Migrations march forward, with keys clear and bright,
Error logs ready for flags not quite right.
Tests follow suit, enums bid adieu—
A stringy new future for feature flags, woo-hoo!
🗝️✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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

🧹 Nitpick comments (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/FeatureFlagMigrationHelperCEImpl.java (1)

10-10: Remove unused import.

The ScheduledTaskCEImpl import is only referenced in a comment at line 34 but not used in the code.

-import com.appsmith.server.solutions.ce.ScheduledTaskCEImpl;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cf90a8e and ab4973c.

📒 Files selected for processing (7)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/OrganizationConfigurationCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/FeatureFlagMigrationHelperCE.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/FeatureFlagMigrationHelperCEImpl.java (9 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/OrganizationServiceCEImpl.java (2 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/FeatureFlagMigrationHelperTest.java (7 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/FeatureFlagServiceCETest.java (4 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/OrganizationServiceCETest.java (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: server-spotless / spotless-check
  • GitHub Check: server-unit-tests / server-unit-tests
🔇 Additional comments (30)
app/server/appsmith-server/src/main/java/com/appsmith/server/domains/ce/OrganizationConfigurationCE.java (1)

60-60: Appropriate key type change for map

The change from Map<FeatureFlagEnum, FeatureMigrationType> to Map<String, FeatureMigrationType> properly implements the decoupling of feature flag enums from the organization configuration. This reduces direct dependencies and facilitates easier serialization/deserialization.

app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/OrganizationServiceCETest.java (2)

341-345: Test updated correctly to use string keys

The test data initialization has been properly updated to use string keys (enum names) instead of enum values directly. This aligns with the refactoring changes in the main code.


370-374: Test updated correctly to use string keys

Similar to the previous test case, the map initialization properly uses string keys via name() method on the enum constants. This maintains consistency with the refactoring approach.

app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/FeatureFlagServiceCETest.java (4)

229-229: Mock return value updated to use string keys

Mock data properly updated to use string representation of feature flag enum as key.


240-240: Assertion updated to use string keys

Assertion correctly updated to verify using string keys instead of enum constants.


252-252: Mock return value updated to use string keys

Mock data properly updated for enable migration test case.


263-263: Assertion updated to use string keys

Assertion correctly updated for enable migration test case.

app/server/appsmith-server/src/test/java/com/appsmith/server/helpers/FeatureFlagMigrationHelperTest.java (9)

67-67: Return type updated to use string keys

Method return type correctly updated to use Map<String, FeatureMigrationType> instead of enum-based map.


74-75: Assertion updated to use string keys

Map lookup in assertion properly uses the string representation of enum via .name().


105-106: Return type updated consistently

Return type consistently updated in another test method.


112-113: Assertion updated consistently

Map lookup in assertion consistently updated in another test method.


136-137: Return type updated consistently

Return type consistently updated in third test method.


174-175: Return type updated consistently

Return type consistently updated in fourth test method.


200-201: Test data updated to use string keys

Map initialization using Map.of() correctly uses string representation of enum constant.


233-234: Test data updated to use string keys

Map initialization for pending migration test case correctly uses string keys.


258-259: Return type updated consistently

Return type consistently updated in last test method.

app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/FeatureFlagMigrationHelperCE.java (2)

12-12: Method signature change aligns with refactoring strategy.

The return type change from Mono<Map<FeatureFlagEnum, FeatureMigrationType>> to Mono<Map<String, FeatureMigrationType>> is part of the broader refactoring to decouple feature flag serialization from the enum type.


14-15: Method signature change maintains consistency across the interface.

This overloaded method signature has been updated to match the refactoring pattern of using string keys instead of enum keys.

app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/OrganizationServiceCEImpl.java (5)

293-294: Map type change aligns with domain model changes.

The map type has been updated from Map<FeatureFlagEnum, FeatureMigrationType> to Map<String, FeatureMigrationType> to match the changes in OrganizationConfigurationCE.


296-309: Well-implemented error handling for unknown feature flags.

The new code properly handles unknown feature flags by safely converting string keys to enum values with appropriate error handling. This is more robust than the previous implementation which would have thrown exceptions for unknown flags.


310-310: Using the converted enum value in method call.

The code correctly passes the converted enum value to the helper method while handling the case where conversion might have failed (finalFeatureFlagEnum could be null).


313-313: Consistent use of string key for map operations.

The code correctly uses the original string key for removing items from the map after successful migration, maintaining consistency with the new string-based approach.


326-326: Using enum value in exception message.

The code uses the converted enum in the error message, which provides better context for troubleshooting migration failures.

app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/ce/FeatureFlagMigrationHelperCEImpl.java (7)

40-43: Method signature updated to match interface changes.

The implementation correctly aligns with the interface changes, returning a map with string keys instead of enum keys.


53-55: Method signature updated consistently.

The overloaded method implementation also correctly matches the interface changes.


131-148: Map operations consistently use string keys.

The helper method has been updated to work with string keys throughout. The error handling at lines 140-144 has been simplified, which is appropriate since the direct enum conversion is no longer needed.


150-192: Updated map handling logic for feature flags.

The method has been refactored to use string keys throughout, maintaining consistency with the broader refactoring. All map operations and comparisons now work with strings instead of enum values.


214-224: Consistent use of enum name for map lookups.

The code now uses featureFlagEnum.name() to look up values in the map, which is consistent with the refactoring to use string keys.


235-253: Feature migration map type updated for consistency.

The map type and lookups have been updated to use string keys while maintaining the core business logic.


262-267: Added clarifying comment for placeholder implementation.

The comment clarifies that this is a placeholder meant to be extended by subclasses, which improves code maintainability.

@abhvsn abhvsn added the ok-to-test Required label for CI label Apr 25, 2025
@abhvsn abhvsn merged commit c14a896 into release Apr 28, 2025
51 checks passed
@abhvsn abhvsn deleted the chore/remove-ff-enum-dependency-in-org branch April 28, 2025 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants