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: updateWithoutPermission updates user instead of saving it #36206

Merged
merged 2 commits into from
Sep 10, 2024

Conversation

nsarupr
Copy link
Contributor

@nsarupr nsarupr commented Sep 9, 2024

Description

UserService$updateWithoutPermission will now update the user instead of saving it.

Fixes #36063

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/10786655302
Commit: 0eb7f18
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Tue, 10 Sep 2024 06:20:46 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced user update functionality for more efficient processing.
    • Added a mechanism to ensure user policies remain unchanged during updates.
  • Bug Fixes

    • Implemented tests to verify that user name updates do not affect associated policies.
  • Tests

    • Introduced new test methods to validate user update scenarios within the correct security context.

Copy link
Contributor

coderabbitai bot commented Sep 9, 2024

Walkthrough

This pull request introduces significant modifications to the UserServiceCEImpl class, particularly affecting the update and updateCurrentUser methods. The update method now utilizes a more efficient approach for updating user records, while the updateCurrentUser method ensures that the policies field remains unchanged during updates. Additionally, the UserServiceTest class has been enhanced with new testing capabilities, including methods to simulate user contexts and verify that user policies are preserved when updating user details.

Changes

File Change Summary
app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserServiceCEImpl.java Modified update and updateCurrentUser methods to streamline user updates and preserve policies.
app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserServiceTest.java Added runAs method for simulating user security contexts and new tests to verify policy preservation and field updates.

Assessment against linked issues

Objective Addressed Explanation
Ensure policies are preserved when updating user name (Issue #36063)
Verify that user updates do not disrupt existing policies (Issue #36063)
Confirm that changes are reflected correctly when updating user details

Poem

In the realm of code, changes arise,
User updates now swift, a welcome surprise.
Policies safe, as names take their flight,
Tests stand guard, ensuring what's right.
With each line refined, our code shines anew,
A dance of logic, in harmony too! 🎉

Tip

Announcements
  • The review status is no longer posted as a separate comment when there are no actionable or nitpick comments. In such cases, the review status is included in the walkthrough comment.
  • We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs: Walkthrough comment now includes a list of potentially related PRs to help you recall past context. Please share any feedback in the discussion post on our Discord.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs in the walkthrough comment. You can also provide custom labeling instructions in the UI or configuration file.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6f2e247 and 0eb7f18.

Files selected for processing (1)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserServiceTest.java (3 hunks)
Additional comments not posted (3)
app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserServiceTest.java (3)

756-763: Excellent work on the runAs helper method! 👏

This private utility method is a great addition for writing tests that need to execute code under a specific user's security context. By constructing a SecurityContext with the user's credentials and authorities, and integrating it into the reactive context, it allows simulating different user scenarios in the tests.

Well done on this helpful testing utility! 🙌


765-788: Great test for ensuring user policies are not affected by name updates! 🎉

This test method does a thorough job of verifying that updating a user's name does not inadvertently alter their associated policies:

  1. It creates a new user and checks the initial state - name is null and policies are assigned.
  2. It updates just the user's name using the runAs method to simulate the correct security context.
  3. It asserts that the name is updated as expected, while also ensuring all the original policies are still intact.

Excellent work on this comprehensive test case! It gives confidence that user updates behave correctly with respect to policies. 👍


790-811: Excellent test for the updateWithoutPermission method! 🚀

This test method thoroughly verifies the behavior of updating a user without permission:

  1. It creates a new user with some initial policies.
  2. It updates the user's name and state using the updateWithoutPermission method.
  3. It asserts that the name and state changes are reflected correctly on the updated user.
  4. It also ensures that the original policies assigned to the user remain unchanged.

Great job on this test case! It gives confidence that the updateWithoutPermission method in the UserService class is working as expected, updating only the specified fields while preserving the existing policies. 💯


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 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.

@nsarupr nsarupr requested a review from abhvsn September 9, 2024 18:52
@github-actions github-actions bot added the Bug Something isn't working label Sep 9, 2024
@nsarupr nsarupr self-assigned this Sep 9, 2024
@github-actions github-actions bot added High This issue blocks a user from building or impacts a lot of users Platform Administration Pod Issues related to platform administration & management Production RBAC Product Issues, requests and enhancements around RBAC. labels Sep 9, 2024
@nsarupr nsarupr added the ok-to-test Required label for CI label Sep 9, 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 9a26066 and 6f2e247.

Files selected for processing (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserServiceCEImpl.java (3 hunks)
  • app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserServiceTest.java (2 hunks)
Additional comments not posted (4)
app/server/appsmith-server/src/test/java/com/appsmith/server/services/UserServiceTest.java (2)

42-44: Looks good!

The imports are necessary for implementing security-related functionality in the test class. The code changes are approved.


755-787: Great work on enhancing the test coverage!

The new runAs method is a helpful utility for simulating user security contexts during testing. It will make it easier to write tests that verify the behavior of user-related operations under different security contexts.

The testUpdateName_shouldNotUpdatePolicies test is a valuable addition. It ensures that updating a user's name does not accidentally modify their associated policies. This test helps maintain the integrity of user permissions and roles.

Overall, these changes significantly improve the robustness and reliability of the user management functionality. Well done!

app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/UserServiceCEImpl.java (2)

578-578: Excellent optimization!

The change in the update method is a significant improvement. By directly calling repository.updateById, you have streamlined the update process and eliminated the need for manual field copying.

This optimization not only simplifies the code but also improves performance by reducing the overhead associated with object creation and field mapping.

Great job on identifying and implementing this enhancement!


604-605: Good catch on preserving user policies!

Setting the policies field to null in the updates object is a critical change. It ensures that the existing user policies are not accidentally overwritten during the update process.

By preserving the user's policies, you maintain the integrity of their permissions and roles. This is essential for maintaining a secure and consistent access control system.

Well done on identifying and addressing this important aspect of user updates!

@nsarupr nsarupr requested a review from nidhi-nair September 10, 2024 04:23
nidhi-nair
nidhi-nair previously approved these changes Sep 10, 2024
Copy link
Contributor

@nidhi-nair nidhi-nair left a comment

Choose a reason for hiding this comment

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

LGTM except for the above comment. Approving to not block the PR in case the tests turn out okay.

@nsarupr nsarupr merged commit 316f914 into release Sep 10, 2024
44 checks passed
@nsarupr nsarupr deleted the fix/update-user-should-not-update-policies branch September 10, 2024 06:57
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Sep 26, 2024
…ithorg#36206)

## Description
> UserService$updateWithoutPermission will now update the user instead
of saving it.

Fixes appsmithorg#36063

## Automation

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

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10786655302>
> Commit: 0eb7f18
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10786655302&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Sanity`
> Spec:
> <hr>Tue, 10 Sep 2024 06:20:46 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


## Summary by CodeRabbit

- **New Features**
	- Enhanced user update functionality for more efficient processing.
- Added a mechanism to ensure user policies remain unchanged during
updates.

- **Bug Fixes**
- Implemented tests to verify that user name updates do not affect
associated policies.

- **Tests**
- Introduced new test methods to validate user update scenarios within
the correct security context.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Nilesh Sarupriya <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working High This issue blocks a user from building or impacts a lot of users ok-to-test Required label for CI Platform Administration Pod Issues related to platform administration & management Production RBAC Product Issues, requests and enhancements around RBAC.
Projects
None yet
2 participants