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-2587] fix: hide log work button for guest user #5787

Merged
merged 3 commits into from
Oct 24, 2024

Conversation

sharma01ketan
Copy link
Collaborator

@sharma01ketan sharma01ketan commented Oct 10, 2024

[WEB-2587]

This PR aims to remove the "Log Work" button for Guest Users.

Screenshot 2024-10-10 at 2 42 25 PM

Summary by CodeRabbit

  • New Features

    • Enhanced the IssueActivity component to conditionally enable or disable the worklog button based on user permissions.
    • Integrated user role checks to improve the display logic for UI elements related to worklogs.
  • Bug Fixes

    • Improved the conditional rendering of the worklog button to ensure it accurately reflects user access rights.

@sharma01ketan sharma01ketan added 🐛bug Something isn't working 🌐frontend labels Oct 10, 2024
@sharma01ketan sharma01ketan added this to the v0.24.0 milestone Oct 10, 2024
@sharma01ketan sharma01ketan self-assigned this Oct 10, 2024
Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

Walkthrough

The changes in this pull request modify the IssueActivity component within root.tsx to incorporate user permissions into its functionality. The useUserPermissions hook is introduced to determine if the current user has guest permissions, influencing the rendering of the worklog button. The logic for displaying this button is refined to enhance user experience based on their permissions. Overall, the structure of the component remains largely the same, preserving existing functionalities related to comments.

Changes

File Path Change Summary
web/core/components/issues/issue-detail/issue-activity/root.tsx - Added imports for useUserPermissions and EUserPermissions.
- Introduced isWorklogButtonEnabled to manage worklog button visibility based on user permissions and issue type.
- Updated conditional rendering logic for IssueActivityWorklogCreateButton.

Possibly related PRs

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham
  • rahulramesha

Poem

🐇 In the garden of code, we hop and play,
Permissions now guide us, lighting the way.
With buttons enabled, our tasks are a breeze,
For guests and for users, we aim to please.
So let’s celebrate changes, both big and small,
In the world of issues, we’re having a ball! 🎉


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.

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.

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 8a866e4 and 0258563.

📒 Files selected for processing (1)
  • web/core/components/issues/issue-detail/issue-activity/root.tsx (3 hunks)
🧰 Additional context used
🔇 Additional comments (1)
web/core/components/issues/issue-detail/issue-activity/root.tsx (1)

123-123: Conditional rendering logic is correctly updated

The use of isWorklogButtonEnabled ensures that the IssueActivityWorklogCreateButton is displayed only when appropriate, based on the user's permissions and the issue type. This enhances the user experience by hiding the worklog button from guest users and on intake issues.

Comment on lines 38 to 42
const { projectPermissionsByWorkspaceSlugAndProjectId } = useUserPermissions();
const { getProjectById } = useProject();
//derived values
const isGuest = projectPermissionsByWorkspaceSlugAndProjectId(workspaceSlug, projectId) === EUserPermissions.GUEST;
const isWorklogButtonEnabled = !isIntakeIssue && !isGuest;
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 10, 2024

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Handle potential undefined permissions

It has been confirmed that projectPermissionsByWorkspaceSlugAndProjectId can return undefined. To prevent unintended behavior, please add error handling or default values where necessary.

  • web/core/store/user/permissions.store.ts returns EUserPermissions | undefined
  • Ensure all usages of projectPermissionsByWorkspaceSlugAndProjectId handle undefined appropriately
🔗 Analysis chain

Handle potential undefined permissions

Ensure that projectPermissionsByWorkspaceSlugAndProjectId always returns a valid permission level. If it can return undefined or null, the comparison in line 41 may cause unintended behavior. Consider adding error handling or a default value to prevent runtime errors.

Run the following script to verify that projectPermissionsByWorkspaceSlugAndProjectId always returns a valid permission:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that 'projectPermissionsByWorkspaceSlugAndProjectId' always returns a valid permission.

# Test: Find all return statements in 'projectPermissionsByWorkspaceSlugAndProjectId' implementations. Expect: Should not return undefined or null.

rg --type=typescript -A 5 -B 5 'function projectPermissionsByWorkspaceSlugAndProjectId'

Length of output: 124


Script:

#!/bin/bash
# Description: Verify that 'projectPermissionsByWorkspaceSlugAndProjectId' always returns a valid permission.

# Test: Find all return statements in 'projectPermissionsByWorkspaceSlugAndProjectId' implementations. Expect: Should not return undefined or null.

rg --type=ts -A 5 -B 5 'function projectPermissionsByWorkspaceSlugAndProjectId'

Length of output: 81


Script:

#!/bin/bash
# Description: Search for all declarations and exports of 'projectPermissionsByWorkspaceSlugAndProjectId' across TypeScript files.

rg --type=ts -e 'projectPermissionsByWorkspaceSlugAndProjectId' --context-separator='' 

Length of output: 1892

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

@sharma01ketan Thank you for addressing the issue!

(_/)
(^^)
(")
(")


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

@sharma01ketan sharma01ketan changed the title [WEB-2587] fix: the rendering logic [WEB-2587] fix: hide log work button for guest user Oct 10, 2024
const { getProjectById } = useProject();
//derived values
const isGuest = (projectPermissionsByWorkspaceSlugAndProjectId(workspaceSlug, projectId) ?? EUserPermissions.GUEST) === EUserPermissions.GUEST;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use allowPermissions function here

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

🧹 Outside diff range and nitpick comments (1)
web/core/components/issues/issue-detail/issue-activity/root.tsx (1)

46-47: LGTM with suggestion: New derived values for permission checks.

The new derived values isGuest and isWorklogButtonEnabled are correctly implemented and provide the necessary logic for controlling the visibility of the worklog button.

However, as suggested in a previous review, consider using the allowPermissions function for consistency with the rest of the codebase:

const isGuest = !allowPermissions(projectPermissionsByWorkspaceSlugAndProjectId(workspaceSlug, projectId), [EUserPermissions.MEMBER, EUserPermissions.ADMIN]);

This approach would be more aligned with the existing permission checking patterns in the project.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ec28b05 and 4344d62.

📒 Files selected for processing (1)
  • web/core/components/issues/issue-detail/issue-activity/root.tsx (3 hunks)
🧰 Additional context used
🔇 Additional comments (4)
web/core/components/issues/issue-detail/issue-activity/root.tsx (4)

14-14: LGTM: New imports for user permissions.

The new imports for useUserPermissions and EUserPermissions are correctly added and necessary for the permission-based logic introduced in the component.

Also applies to: 19-19


43-43: LGTM: New hook usage for user permissions.

The addition of projectPermissionsByWorkspaceSlugAndProjectId from useUserPermissions is correctly placed and necessary for the new permission-based logic.


Line range hint 147-153: LGTM: Updated conditional rendering for worklog button.

The conditional rendering of IssueActivityWorklogCreateButton now correctly uses the isWorklogButtonEnabled derived value. This change properly implements the new permission-based logic for controlling the visibility of the worklog button.


Line range hint 1-186: Summary: Successfully implemented permission-based control for worklog button visibility.

The changes in this file successfully implement the requirement to hide the log work button for guest users. The modifications include:

  1. Adding necessary imports for user permissions.
  2. Implementing permission checks using the useUserPermissions hook.
  3. Creating derived values to determine user status and button visibility.
  4. Updating the conditional rendering of the worklog button based on these checks.

These changes effectively achieve the PR objective of removing the "Log Work" button for Guest Users, enhancing the user interface by ensuring that only authorized users have access to this functionality.

To further improve the code:

  1. Consider using the allowPermissions function for consistency with the rest of the codebase, as suggested earlier.
  2. Ensure that this change is properly tested, especially with different user permission scenarios.

Overall, the implementation is solid and achieves the desired outcome.

To verify the impact of these changes, you can run the following script:

@pushya22 pushya22 merged commit ad25a97 into preview Oct 24, 2024
14 of 15 checks passed
@pushya22 pushya22 deleted the fix/worklog-button-guest-user branch October 24, 2024 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug Something isn't working 🌐frontend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants