Skip to content

Fix: project settings pages permissions#6649

Merged
sriramveeraghanta merged 6 commits intopreviewfrom
fix-project-settings-permissions
Feb 19, 2025
Merged

Fix: project settings pages permissions#6649
sriramveeraghanta merged 6 commits intopreviewfrom
fix-project-settings-permissions

Conversation

@gakshita
Copy link
Collaborator

@gakshita gakshita commented Feb 19, 2025

Description

  • The Plus icon disabled for members on issue states settings page
  • Rearrangement of labels restricted from frontend for project members

Summary by CodeRabbit

  • New Features
    • Enhanced label interactions by enabling drag and drop only for users with the proper access, ensuring restricted editing capabilities.
    • Updated UI controls for adding states, replacing a static icon with a button that visually indicates when actions are unavailable due to insufficient permissions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 19, 2025

Walkthrough

This pull request adds user permissions checks to two components. In the LabelDndHOC component, a new hook, useUserPermissions, along with imported permission types, gate the initialization of drag-and-drop functionality based on whether the user has the necessary admin permissions. Similarly, in the GroupItem component, a non-interactive div is replaced with a button that is conditionally disabled according to the same permission logic. These changes ensure that both components adjust their behavior based on the user’s edit permissions.

Changes

File(s) Change Summary
web/core/components/labels/label-drag-n-drop-HOC.tsx - Added imports for EUserPermissions, EUserPermissionsLevel, and useUserPermissions
- Introduced the isEditable variable to check for admin permissions
- Modified useEffect to conditionally initialize drag-and-drop functionality based on the user’s permissions
- Updated onDrop to operate under these conditions
web/core/components/project-states/group-item.tsx - Replaced a div with a button element for the Plus icon
- Added a disabled attribute controlled by the isEditable state
- Incorporated conditional class names to indicate the disabled state
- Preserved the original click event handler for state creation when permissions allow

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant L as LabelDndHOC Component
    participant P as useUserPermissions Hook

    U->>L: Load component
    L->>P: Retrieve user permissions
    P-->>L: Return permission level (e.g., admin or not)
    alt User is editable
        L->>L: Initialize drag-and-drop functionality
        L->>L: Allow onDrop events
    else User is not editable
        L->>L: Skip drag-and-drop initialization
    end
Loading
sequenceDiagram
    participant U as User
    participant G as GroupItem Component

    U->>G: Click the Plus icon/button
    G->>G: Check if `isEditable` (user permission)
    alt Button is enabled
        G->>G: Execute click event handler for state creation
    else Button is disabled
        G-->>U: No action (disabled state)
    end
Loading

Possibly related PRs

Suggested labels

🐛bug, 🌐frontend, ⚙️backend, 🧹chore

Suggested reviewers

  • sriramveeraghanta
  • rahulramesha
  • SatishGandham

Poem

Oh, what a hop, what a skip,
I'm a rabbit with a code-filled grip!
Permissions check, and changes unfold,
Drag and drop, and buttons bold.
With every line, our story's told,
🐇 Innovating with style—bright and keen!
Hoppy codes keep our projects serene!


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (2)
web/core/components/project-states/group-item.tsx (1)

78-87: Great improvement in accessibility and permission handling!

The changes enhance both accessibility and permission handling by:

  1. Using a semantic button element instead of a div.
  2. Properly implementing the disabled state based on user permissions.
  3. Providing visual feedback through cursor and color changes.

Consider adding an aria-label to improve screen reader experience:

 <button
   className={cn(
     "flex-shrink-0 w-6 h-6 rounded flex justify-center items-center overflow-hidden transition-colors hover:bg-custom-background-80 cursor-pointer text-custom-primary-100/80 hover:text-custom-primary-100",
     !isEditable && "cursor-not-allowed text-custom-text-400 hover:text-custom-text-400"
   )}
   onClick={() => !createState && setCreateState(true)}
   disabled={!isEditable}
+  aria-label="Add new state"
 >
   <Plus className="w-4 h-4" />
 </button>
web/core/components/labels/label-drag-n-drop-HOC.tsx (1)

70-70: Clean implementation of permission-based early return!

The early return in useEffect efficiently prevents drag-and-drop initialization when the user lacks edit permissions.

Consider adding a debug log to help troubleshoot permission issues:

-    if (!element || !isEditable) return;
+    if (!element || !isEditable) {
+      if (process.env.NODE_ENV === 'development' && !isEditable) {
+        console.debug('Label drag-and-drop disabled: User lacks admin permissions');
+      }
+      return;
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd11ebf and 777992a.

📒 Files selected for processing (2)
  • web/core/components/labels/label-drag-n-drop-HOC.tsx (2 hunks)
  • web/core/components/project-states/group-item.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (1)
web/core/components/labels/label-drag-n-drop-HOC.tsx (1)

63-64: Well-implemented permission check!

The permission check is correctly implemented using the useUserPermissions hook and appropriate permission constants.

@sriramveeraghanta sriramveeraghanta merged commit f6dfca4 into preview Feb 19, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-project-settings-permissions branch February 19, 2025 12:35
lifeiscontent pushed a commit that referenced this pull request Aug 18, 2025
* fix: Handled workspace switcher closing on click

* fix: permissions for labels dnd + issue state creation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants