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: Refactor UpdateSuperUserMigrationHelperCE for re-use in EE #36851

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

trishaanand
Copy link
Contributor

@trishaanand trishaanand commented Oct 14, 2024

Automation

/ok-to-test tags="@tag.Sanity"

🔍 Cypress test results

Tip

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


Mon, 14 Oct 2024 06:12:25 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Enhanced user creation process with automatic generation of user management permission groups and policies.
    • Introduced a new method for creating permission groups associated with user management.
  • Bug Fixes

    • Streamlined the assignment of user policies during user creation.

Copy link
Contributor

coderabbitai bot commented Oct 14, 2024

Walkthrough

The changes in this pull request involve modifications to the UpdateSuperUserMigrationHelperCE class, particularly enhancing the createNewUser method. A new method, createUserManagementPermissionGroup, has been introduced to facilitate the creation of user management permission groups. This method generates a PermissionGroup associated with the user and assigns relevant permissions. The user policies are generated and assigned right after the permission group creation, streamlining the overall user creation process.

Changes

File Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/solutions/ce/UpdateSuperUserMigrationHelperCE.java Enhanced createNewUser method to include user management permission group creation; added createUserManagementPermissionGroup method.

Possibly related PRs

  • chore: update code owner for migrations #36769: This PR updates the code owner for migrations, which includes the UpdateSuperUserMigrationHelperCE class that is modified in the main PR, indicating a direct connection to the migration functionality.

Suggested labels

Task, skip-changelog, ok-to-test

Suggested reviewers

  • abhvsn
  • sharat87
  • AnaghHegde

🎉 In the realm of code where users are made,
A new permission group, we’ve carefully laid.
With policies set, and management in hand,
The user creation process now takes a stand!
So let’s celebrate this migration spree,
For smoother transitions, just wait and see! 🎊


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.

@trishaanand trishaanand added the ok-to-test Required label for CI label Oct 14, 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 Oct 14, 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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ef5a253 and 402dfb3.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/solutions/ce/UpdateSuperUserMigrationHelperCE.java (3 hunks)
🧰 Additional context used
🔇 Additional comments (2)
app/server/appsmith-server/src/main/java/com/appsmith/server/migrations/solutions/ce/UpdateSuperUserMigrationHelperCE.java (2)

11-11: Excellent Use of Nullability Annotation

It's great to see the import of org.jetbrains.annotations.NotNull. Using @NotNull helps prevent null-related errors and improves code reliability. Keep up the good work ensuring your methods clearly communicate their nullability contracts!


Line range hint 70-80: Ensure User's Username is Not Null

When constructing the permission group name using user.getUsername(), ensure that the username is not null to avoid a potential NullPointerException. It's advisable to add a null check or use a default value if user.getUsername() might be null.

Would you like to add a null check for the user's username, or should we enforce that the username must be set before this method is called?

Comment on lines +60 to +68
PermissionGroup userManagementPermissionGroup = createUserManagementPermissionGroup(mongoTemplate, user);

Set<Policy> userPolicies = this.generateUserPolicy(
user, userManagementPermissionGroup, instanceAdminRole, tenant, policySolution, policyGenerator);

user.setPolicies(userPolicies);

return mongoTemplate.save(user);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize by Reducing Multiple Database Saves

I notice that you're saving the User object twice in the createNewUser method: once after initial creation and again after setting the policies. To improve efficiency, consider setting all user properties, including policies, before the initial save. This way, you can minimize database interactions and enhance performance.

Copy link
Contributor

@nsarupr nsarupr left a comment

Choose a reason for hiding this comment

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

Changes look good to me.

@trishaanand trishaanand merged commit dfd5a5a into release Oct 14, 2024
46 checks passed
@trishaanand trishaanand deleted the chore/refactor-ce-for-ee branch October 14, 2024 08:22
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.

2 participants