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

[WEB-2443] fix: join project flicker #5602

Merged
merged 2 commits into from
Sep 16, 2024
Merged

Conversation

anmolsinghbhatia
Copy link
Collaborator

@anmolsinghbhatia anmolsinghbhatia commented Sep 13, 2024

Changes:

This PR fixes the flickering issue when joining a project.

Reference:

[WEB-2443]

Summary by CodeRabbit

  • New Features

    • Simplified permission checking for projects, ensuring consistent evaluation regardless of project ID presence.
    • Enhanced user permissions management by deriving values from workspace roles instead of direct service responses.
    • Comprehensive cleanup of project-related data when a user leaves a project.
  • Bug Fixes

    • Improved handling of permission states, reducing potential undefined scenarios.

Copy link
Contributor

coderabbitai bot commented Sep 13, 2024

Walkthrough

The changes involve modifications to the ProjectAuthWrapper component's permission-checking logic, ensuring that permission checks are always executed regardless of the presence of a projectId. Additionally, the UserPermissionStore class has been updated to derive workspace project permissions from workspace roles rather than directly from service responses. Furthermore, when a user leaves a project, the project is now also removed from the projectMap, enhancing data management related to user permissions and project associations.

Changes

File Change Summary
web/core/layouts/auth-layout/... Simplified logic in ProjectAuthWrapper to always call allowPermissions, impacting permission checks for the current project.
web/core/store/user/... Updated UserPermissionStore to set workspaceProjectsPermissions based on workspace roles instead of direct service responses, and added cleanup for project data when a user leaves.

Possibly related PRs

Poem

🐇 In the meadow where permissions play,
A rabbit hops with joy today!
"No more undefined," it sings with glee,
"Roles and rights are clear as can be!
With every check, we leap and bound,
In this project, harmony is found!" 🐇

Tip

OpenAI O1 model for chat
  • We have deployed OpenAI's latest O1 model for chat.
  • OpenAI claims that this model has superior reasoning capabilities than their GPT-4o model.
  • Please share any feedback with us in the discussions post.

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8831ce1 and 6444cbd.

Files selected for processing (1)
  • web/core/store/user/permissions.store.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • web/core/store/user/permissions.store.ts

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.

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.

@anmolsinghbhatia anmolsinghbhatia marked this pull request as ready for review September 13, 2024 13:14
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 UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 485caaf and 8831ce1.

Files selected for processing (2)
  • web/core/layouts/auth-layout/project-wrapper.tsx (1 hunks)
  • web/core/store/user/permissions.store.ts (1 hunks)
Additional comments not posted (1)
web/core/layouts/auth-layout/project-wrapper.tsx (1)

108-113: LGTM! The permission check logic has been simplified.

The change simplifies the permission check logic by always calling the allowPermissions function, regardless of whether projectId is defined. This may affect the control flow of the application, particularly in scenarios where the projectId is not available, as it no longer results in an undefined state but rather a direct call to the permissions function.

Comment on lines 248 to 252
set(
this.workspaceProjectsPermissions,
[workspaceSlug, projectId],
this.workspaceInfoBySlug(workspaceSlug)?.role
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Review and update permission setting logic for consistency

The usage of workspaceInfoBySlug in the changed code is consistent with its usage elsewhere in the codebase. However, the way workspaceProjectsPermissions is being set appears to be inconsistent with other occurrences in the same file.

Consider the following:

  1. In the changed code (line 251), you're using this.workspaceInfoBySlug(workspaceSlug)?.role.
  2. In other parts of the file (e.g., line 209), it's set directly with response.role.

To ensure consistency and robustness:

  1. Review other occurrences of setting workspaceProjectsPermissions and update them if necessary to align with this new approach.
  2. Add error handling for cases where workspaceInfoBySlug might return undefined. For example:
const role = this.workspaceInfoBySlug(workspaceSlug)?.role;
if (role) {
  set(this.workspaceProjectsPermissions, [workspaceSlug, projectId], role);
} else {
  console.error(`Failed to get role for workspace: ${workspaceSlug}`);
  // Consider how to handle this case - maybe set a default role or throw an error
}
  1. Ensure that this change is part of a deliberate shift from using direct API responses to using workspace roles for permissions, and update related documentation if necessary.
Analysis chain

Verify the consistency of the change and add error handling.

The change shifts from using the service response directly to utilizing a derived value (the role) from the workspace information. This may affect how permissions are managed and interpreted within the application.

Please verify if this change is consistent with the application's permission management logic by running the following script:

Also, the change seems to be missing error handling for the case when workspaceInfoBySlug returns undefined.

Consider adding error handling like this:

  runInAction(() => {
+   const role = this.workspaceInfoBySlug(workspaceSlug)?.role;
+   if (role) {
      set(
        this.workspaceProjectsPermissions,
        [workspaceSlug, projectId],
-       this.workspaceInfoBySlug(workspaceSlug)?.role
+       role
      );
+   } else {
+     console.error(`Failed to get role for workspace: ${workspaceSlug}`);
+   }
  });
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of the change with the application's permission management logic.

# Test 1: Search for other occurrences of setting `workspaceProjectsPermissions` state. 
# Expect: The logic should be consistent with the change.
rg --type typescript -A 5 $'set\(this\.workspaceProjectsPermissions'

# Test 2: Search for usage of `workspaceInfoBySlug` method. 
# Expect: The return value should be consistently used and handled.
rg --type typescript -A 5 $'workspaceInfoBySlug'

Length of output: 187


Script:

#!/bin/bash
# Description: Verify the consistency of the change with the application's permission management logic using generic search patterns.

# Find TypeScript files and search for setting workspaceProjectsPermissions
fd -e ts -e tsx | xargs grep -n -A 5 "set(this.workspaceProjectsPermissions"

# Find TypeScript files and search for usage of workspaceInfoBySlug method
fd -e ts -e tsx | xargs grep -n -A 5 "workspaceInfoBySlug"

Length of output: 8744

@pushya22 pushya22 merged commit 5ba1eea into preview Sep 16, 2024
14 of 15 checks passed
@SatishGandham SatishGandham deleted the fix-join-project-flicker branch September 16, 2024 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants