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

chore: Change policies set to policyMap #34566

Merged
merged 59 commits into from
Aug 11, 2024
Merged

chore: Change policies set to policyMap #34566

merged 59 commits into from
Aug 11, 2024

Conversation

sharat87
Copy link
Member

@sharat87 sharat87 commented Jun 27, 2024

Migrate policies from being a Set<Policy> to a policyMap, that's a Map<String, Policy>. The key defines the permission whereas the value is the actual policy object. This makes it easier to use this data in code, to query as a MongoDB nested document, and as a Postgres jsonb column. Win-win!

The migration runs for all collections in parallel, with following stats taken on 1-Jul-2024.

  1. Release data, only non-deleted documents, all collections, parallel, 2m 42s.
  2. Prod replica data, only non-deleted documents, all collections, parallel, (15m).
  3. Release data, only non-deleted documents, all collections, serial, ~9m.

This PR is only part of the solution. We have backwards compatible getPolicies() and setPolicies() methods so the diff isn't too big, but a follow-up PR will remove those two, and migration all usages to use the map instead.

This PR only (almost) strictly includes changes that were necessary for the build and tests to pass.

/test all

Tip

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


Thu, 08 Aug 2024 12:46:36 UTC

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced migration logic to convert policies to policyMap, enhancing data structure for policy management.
  • Documentation

    • Updated summaries and documentation to reflect changes in policy handling.
  • Refactor

    • Replaced direct field references with constant values for policy fields in migration files.
    • Adjusted method signatures to utilize the new policyMap structure.
    • Improved policy management logic for better immutability and safety.
  • Tests

    • Added new test cases for policy management functionality.
    • Updated existing test assertions to ensure proper policy handling with the new data structure.

Copy link
Contributor

coderabbitai bot commented Jun 27, 2024

Walkthrough

The recent updates represent a significant overhaul in how policies are managed within the codebase. Transitioning from a Set<Policy> to a Map<String, Policy> enhances data retrieval and management efficiency. This change is complemented by migration scripts to convert existing data and method updates across various components, ensuring a seamless transition and maintaining functionality. The overall architecture is better equipped for future enhancements while preserving backward compatibility.

Changes

Files Summary
BaseDomain.java, ActionCE_DTO.java, PageDTO.java Transitioned from Set<Policy> to Map<String, Policy>, with old methods marked as deprecated.
ApplicationForkingServiceCEImpl.java, ApplicationPageServiceCEImpl.java Updated methods to utilize the new policyMap for fetching permissions, enhancing the data structure.
PolicyUtil.java Introduced policyMapToSet method for converting policyMap to a Set<Policy>.
Migration057PolicySetToPolicyMap.java Implemented a migration process to convert the policies set into a policyMap in MongoDB.
PolicySolutionCEImpl.java, ImportServiceTests.java, PolicySolutionCEImplTest.java Refined logic for managing user ACL permissions and revised test cases for accurate policy handling.

Poem

In the realm of code where structures blend,
Policies shift, on maps we depend.
From sets to maps, a clearer view,
Efficiency blooms, in every hue.
Migrations flow like a gentle stream,
In our codebase, we dare to dream.
Let's celebrate this transformation bright!


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@sharat87 sharat87 changed the title Remove policies field, with a compatibility API chore: Change policies set to policyMap Jun 27, 2024
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Jun 27, 2024
Copy link

Failed server tests

  • com.appsmith.server.fork.ApplicationForkingServiceTests#cloneApplicationForkWithConfigurationTrueWithActionsThrice
  • com.appsmith.server.services.NewPageServiceTest#publishPages_WhenUserDoesNotHavePermissionOnPages_NotPublished

@sharat87 sharat87 added the ok-to-test Required label for CI label Jun 27, 2024
@sharat87 sharat87 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 27, 2024
Copy link

Failed server tests

  • com.appsmith.server.services.NewPageServiceTest#publishPages_WhenUserDoesNotHavePermissionOnPages_NotPublished

@sharat87 sharat87 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jun 29, 2024
@appsmithorg appsmithorg deleted a comment from github-actions bot Jun 29, 2024
Copy link

github-actions bot commented Jul 1, 2024

Failed server tests

  • com.appsmith.server.git.CommonGitServiceCETest#listBranchForArtifact_emptyGitMetadata_throwError

@sharat87 sharat87 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 1, 2024
@sharat87 sharat87 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 2, 2024
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c9bc27d and c14a0c8.

Files selected for processing (10)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration025RemoveUnassignPermissionFromUnnecessaryRoles.java (4 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration028TagUserManagementRolesWithoutDefaultDomainTypeAndId.java (3 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration029PopulateDefaultDomainIdInUserManagementRoles.java (3 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration031CreateUserManagementRolesForUsersTaggedIn030.java (3 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration047AddMissingFieldsInDefaultAppsmithAiDatasource.java (4 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration057PolicySetToPolicyMap.java (1 hunks)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/PolicySolutionCEImpl.java (4 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java (3 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/NewPageServiceTest.java (1 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/PolicySolutionCEImplTest.java (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration025RemoveUnassignPermissionFromUnnecessaryRoles.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration028TagUserManagementRolesWithoutDefaultDomainTypeAndId.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration029PopulateDefaultDomainIdInUserManagementRoles.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration047AddMissingFieldsInDefaultAppsmithAiDatasource.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration057PolicySetToPolicyMap.java
  • app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/PolicySolutionCEImpl.java
Additional comments not posted (11)
app/server/appsmith-server/src/test/java/com/appsmith/server/solutions/ce/PolicySolutionCEImplTest.java (4)

35-44: Good job on the test coverage!

The test method testAddNewPoliciesToEmptyObject is well-written and covers the scenario of adding new policies to an empty object.


46-65: Great work on testing policy merging!

The test method testMergePoliciesWithExistingOnes is well-written and covers the scenario of merging new policies with existing ones.


67-85: Excellent test for immutability!

The test method testOriginalPolicyMapNotModified is well-written and ensures that the original policy map is not modified.


87-96: Well done on ensuring object consistency!

The test method testReturnModifiedObject is well-written and ensures that the modified object is returned.

app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/db/ce/Migration031CreateUserManagementRolesForUsersTaggedIn030.java (3)

27-27: Good use of constant for deprecated field name.

Using the constant DeprecatedFieldName.POLICIES improves code maintainability by centralizing the reference to the policies field.


54-54: Ensure backward compatibility with the new field.

Including both POLICIES and policyMap in the query ensures backward compatibility. This is a good practice during migrations.


71-71: Good practice to use constant for deprecated field name.

Using the constant DeprecatedFieldName.POLICIES in the update operation ensures consistency and maintainability.

app/server/appsmith-server/src/test/java/com/appsmith/server/services/NewPageServiceTest.java (1)

290-294: Nice use of streams for immutability!

The use of streams and the peek method to set the permission enhances immutability and ensures that the policies are not modified after being set.

app/server/appsmith-server/src/test/java/com/appsmith/server/imports/internal/ImportServiceTests.java (3)

2160-2161: Good job enhancing the assertion logic!

The new assertion logic using containsExactlyInAnyOrderElementsOf ensures that the order of elements is not considered when comparing the policies, making the test more robust.


4947-4952: Nice use of stream operations for filtering policies!

The new filtering logic using streams and collect(Collectors.toUnmodifiableSet()) improves code clarity and ensures immutability of the resulting set.


4984-4989: Great job updating the filtering logic!

The use of streams and collect(Collectors.toUnmodifiableSet()) enhances the readability and immutability of the code.

@abhvsn abhvsn requested a review from nsarupr July 24, 2024 12:37
// Migrate the policies field to the policyMap field only if the policies field exists and is not empty
new Query(where(dotted(POLICIES, "0"))
.exists(true)
.and(BaseDomain.Fields.deletedAt)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean that we will need to update the notDeleted() method, because it will end up giving this error at other places as well?

@abhvsn abhvsn added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Aug 5, 2024
@abhvsn abhvsn requested a review from AnaghHegde August 7, 2024 12:07
@abhvsn abhvsn added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Aug 7, 2024
@abhvsn abhvsn requested review from nsarupr and removed request for nidhi-nair, sondermanish and a team August 7, 2024 13:51
@abhvsn abhvsn added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Aug 8, 2024
@abhvsn abhvsn merged commit 8cbb13e into release Aug 11, 2024
84 checks passed
@abhvsn abhvsn deleted the chore/policy-map branch August 11, 2024 08:03
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 skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants