Skip to content

Conversation

@vamsikrishnamathala
Copy link
Member

@vamsikrishnamathala vamsikrishnamathala commented Feb 3, 2025

Description

This update fixes labels creation at views.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

References

WEB-3287
WEB-3289

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced label creation so that labels are only added when users have the proper permissions.
    • Improved workspace-aware permission checks to prevent unauthorized label additions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

Walkthrough

This pull request updates the event handling logic related to label creation in two React components. Both components now enforce permission checks before adding a label. In the label-select component, the condition within the searchInputKeyDown function verifies that the user has creation rights. In the label-dropdown component, the permission check is enhanced by including the workspace context via the workspaceSlug and projectId parameters. These modifications tighten the control flow for label creation based on user permissions.

Changes

Files Change Summary
web/.../issue-detail/label/select/label-select.tsx, web/.../issue-layouts/properties/label-dropdown.tsx Updated the searchInputKeyDown event handling to include a permission check (canCreateLabel) before adding labels. The label-dropdown component's check now uses workspaceSlug and projectId with allowPermissions for context-specific validation.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as Label Component
    participant PC as Permission Checker
    U->>C: Press "Enter" key in search input
    C->>PC: Verify canCreateLabel (and workspace context if applicable)
    alt Permission Granted
        PC-->>C: Permission valid
        C->>C: Execute label addition logic
    else Permission Denied
        PC-->>C: Permission invalid
        C->>U: Ignore action or show error
    end
Loading

Possibly related PRs

  • [WEB-2879]fix: label creation #6271: The changes in this PR and the retrieved PR are related as both involve modifications to the canCreateLabel variable and the logic for label creation within the searchInputKeyDown function, ensuring user permissions are checked in the context of both the workspace and project.
  • [WEB-2443] fix: role validation and code refactor #5596: The changes in this PR and the retrieved PR are related as both involve modifications to the canCreateLabel variable and its permission-checking logic, specifically incorporating workspaceSlug and projectId to determine user permissions for label creation.
  • [WEB-2467] fix: platform bug #5621: The changes in this PR and the retrieved PR are related as both involve modifications to the logic surrounding the canCreateLabel variable and its permission checks, specifically incorporating workspaceSlug and projectId in the context of label creation.

Suggested labels

⚙️backend

Suggested reviewers

  • SatishGandham
  • rahulramesha

Poem

I'm a rabbit, hopping through the code,
Checking permissions on each little node.
With a twitch of my nose and a joyful leap,
I secure each label, no secrets to keep.
Hop along, dear coders, with logic so neat!
🐇

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

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/issues/issue-detail/label/select/label-select.tsx (1)

99-104: LGTM! Permission check added for label creation.

The addition of the canCreateLabel check in the Enter key handler aligns with the PR objective of restricting label creation. This ensures that only users with appropriate permissions can create labels.

Consider adding a user feedback message when label creation is attempted without permission:

 if (query !== "" && e.key === "Enter" && canCreateLabel) {
   e.stopPropagation();
   e.preventDefault();
   await handleAddLabel(query);
+} else if (query !== "" && e.key === "Enter") {
+  e.stopPropagation();
+  e.preventDefault();
+  // Show feedback that user doesn't have permission to create labels
 }
web/core/components/issues/issue-layouts/properties/label-dropdown.tsx (1)

160-163: LGTM! Consistent permission check implementation.

The permission check in the Enter key handler matches the implementation in the label-select component, ensuring consistent behavior across components.

Consider adding the same user feedback message suggested for the label-select component:

 if (query !== "" && e.key === "Enter" && canCreateLabel) {
   e.preventDefault();
   await handleAddLabel(query);
+} else if (query !== "" && e.key === "Enter") {
+  e.preventDefault();
+  // Show feedback that user doesn't have permission to create labels
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c14fb81 and 04c0569.

📒 Files selected for processing (2)
  • web/core/components/issues/issue-detail/label/select/label-select.tsx (1 hunks)
  • web/core/components/issues/issue-layouts/properties/label-dropdown.tsx (2 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/issues/issue-layouts/properties/label-dropdown.tsx (1)

84-84: LGTM! Workspace-aware permission check added.

The canCreateLabel permission check now includes the workspaceSlug parameter, making it properly workspace-aware. This aligns with the PR objective of restricting label creation in global views.

@vamsikrishnamathala vamsikrishnamathala marked this pull request as draft February 5, 2025 10:57
@vamsikrishnamathala vamsikrishnamathala marked this pull request as ready for review February 5, 2025 13:22
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 (1)
web/core/components/issues/issue-layouts/properties/label-dropdown.tsx (1)

279-298: Consider adding user feedback for permission denied cases.

When a user without permissions attempts to create a label (by pressing Enter or clicking), they currently see "No matching results." Consider showing a more informative message like "You don't have permission to create labels."

                ) : submitting ? (
                  <Loader className="spin  h-3.5 w-3.5" />
                ) : canCreateLabel ? (
                  <p
                    onClick={() => {
                      if (!query.length) return;
                      handleAddLabel(query);
                    }}
                    className={`text-left text-custom-text-200 ${query.length ? "cursor-pointer" : "cursor-default"}`}
                  >
                    {query.length ? (
                      <>
                        + Add <span className="text-custom-text-100">&quot;{query}&quot;</span> to labels
                      </>
                    ) : (
                      "Type to add a new label"
                    )}
                  </p>
                ) : (
-                  <p className="text-left text-custom-text-200 ">No matching results.</p>
+                  <p className="text-left text-custom-text-200">
+                    {query.length ? "You don't have permission to create labels" : "No matching results"}
+                  </p>
                )}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 04c0569 and 89abbcf.

📒 Files selected for processing (2)
  • web/core/components/issues/issue-detail/label/select/label-select.tsx (2 hunks)
  • web/core/components/issues/issue-layouts/properties/label-dropdown.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/core/components/issues/issue-detail/label/select/label-select.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (2)
web/core/components/issues/issue-layouts/properties/label-dropdown.tsx (2)

84-85: LGTM! Permission check enhancement properly scopes label creation.

The permission check now correctly includes both workspace and project context, which aligns with the PR objective to restrict label creation.


161-164: LGTM! Label creation is properly gated by permissions.

The Enter key handler now correctly enforces the permission check before allowing label creation.

@sriramveeraghanta sriramveeraghanta merged commit dff1272 into preview Feb 10, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-labels-creation branch February 10, 2025 14:05
lifeiscontent pushed a commit that referenced this pull request Aug 18, 2025
* fix: label creation on enter

* fix: update label creation permissions

---------

Co-authored-by: sriram veeraghanta <[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 🌐frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants