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: workspace roles for settings and members button #6574

Merged
merged 3 commits into from
Feb 10, 2025

Conversation

gakshita
Copy link
Collaborator

@gakshita gakshita commented Feb 10, 2025

Description
This PR fixes the permission for settings and invite button in workspace switcher

Summary by CodeRabbit

  • New Features

    • Enhanced workspace creation response to include total members and user role.
    • Updated preloading of user workspaces to ensure fresh data is fetched with each render.
  • Bug Fixes

    • Adjusted sidebar access controls so that only administrative users can view settings and invitation options.
  • Chores

    • Removed total_issues field from the workspace serializer and interface, streamlining data handling.

Copy link
Contributor

coderabbitai bot commented Feb 10, 2025

Walkthrough

The change updates the conditional rendering logic in the SidebarDropdownItem component. Previously, the settings and invite members links were displayed if the workspace role was greater than the guest level. The updated logic now renders these links only when the workspace role equals ADMIN, thereby enforcing stricter access controls. Additionally, the total_issues field has been removed from the WorkSpaceSerializer and the IWorkspace interface, impacting how workspace data is serialized and structured. The response from the create method in the WorkSpaceViewSet has been enhanced to include total_members and role.

Changes

File Path Change Summary
web/core/.../workspace/sidebar/dropdown-item.tsx Updated conditional check: now renders settings and invite links only for workspaces with an ADMIN role.
apiserver/plane/app/serializers/workspace.py Removed total_issues field from WorkSpaceSerializer.
apiserver/plane/app/views/workspace/base.py Removed issue_count annotation in get_queryset; modified create method response to include total_members and role.
packages/types/src/workspace.d.ts Removed total_issues property from IWorkspace interface.
web/app/layout.tsx Updated <link> element to preload user workspaces with a timestamp query parameter.

Possibly related PRs

  • [WEB-2587] fix: hide log work button for guest user #5787: The changes in the main PR, which restrict access to certain links based on user roles, are related to the modifications in the retrieved PR that also involve conditional rendering based on user permissions, specifically for guest users.
  • [WEB-3292] fix: workspace switcher validation and ui improvements #6570: The changes in the main PR modify the conditional rendering logic in the SidebarDropdownItem component, while the retrieved PR enhances the reactivity and rendering logic of the same component, indicating a direct relationship between the two.
  • fix: project join for admin and members #6097: The changes in the main PR, which restrict access to certain features based on the workspace.role, are related to the modifications in the retrieved PR that also involve role checks for permissions, specifically for ADMIN and MEMBER roles.

Suggested labels

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

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham
  • anmolsinghbhatia

Poem

I'm a rabbit with a cap so fine,
Hopping through code with a joyful rhyme.
Admins now hold the key,
Settings and invites for them, you see!
Bugs hop away, leaving the app sublime.
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4c91f4a and 531beb9.

📒 Files selected for processing (1)
  • apiserver/plane/app/views/workspace/base.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apiserver/plane/app/views/workspace/base.py
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)

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 (1)
web/core/components/workspace/sidebar/dropdown-item.tsx (1)

88-108: LGTM! Security improvement by restricting admin features.

The change correctly implements the principle of least privilege by restricting settings and member invitation access to workspace admins only. This is a security improvement over the previous implementation that allowed any role above guest to access these features.

Consider documenting this permission requirement in your security documentation to help maintain consistency across the application.

🧰 Tools
🪛 Biome (1.9.4)

[error] 87-108: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 16bc64e and c2ba337.

📒 Files selected for processing (1)
  • web/core/components/workspace/sidebar/dropdown-item.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)

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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c2ba337 and 4c91f4a.

📒 Files selected for processing (4)
  • apiserver/plane/app/serializers/workspace.py (0 hunks)
  • apiserver/plane/app/views/workspace/base.py (2 hunks)
  • packages/types/src/workspace.d.ts (0 hunks)
  • web/app/layout.tsx (1 hunks)
💤 Files with no reviewable changes (2)
  • apiserver/plane/app/serializers/workspace.py
  • packages/types/src/workspace.d.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (3)
web/app/layout.tsx (1)

69-73: Consider a more targeted cache-busting strategy.

While preventing caching ensures fresh workspace data (including roles), adding a timestamp on every render is aggressive and could impact performance. Consider these alternatives:

  1. Use cache-control headers on the API response instead
  2. Implement selective cache invalidation when roles change
  3. Add the timestamp parameter only when workspace data actually changes

Example implementation using cache-control headers in the API:

// In the API endpoint
response.headers['Cache-Control'] = 'max-age=300, must-revalidate'; // Cache for 5 minutes

Let's check if this endpoint is called frequently:

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Search for references to the workspaces API endpoint
rg -A 3 "api/users/me/workspaces" --type ts --type tsx

Length of output: 82


I'll run another shell script that searches for the workspace API endpoint across both TS and TSX files without relying on pre-defined file types. This should give us a clearer picture of where and how frequently the endpoint is referenced.


🏁 Script executed:

#!/bin/bash
rg -g '*.ts' -g '*.tsx' "api\/users\/me\/workspaces" -A 3

Length of output: 155


Optimize Cache-Busting Strategy for Workspace API

The current implementation in web/app/layout.tsx forces a new data fetch on every render by appending a timestamp (v=${Date.now()}) to the workspaces API URL. While this guarantees fresh data (useful for reflecting role changes immediately), it also aggressively bypasses browser caching, potentially increasing network requests and server load.

Recommendations:

  • Leverage Cache-Control Headers: Configure the API endpoint to return appropriate cache-control headers (e.g., a short TTL with revalidation) to allow controlled caching.
  • Selective Cache Invalidation: Instead of appending a timestamp on every render, consider updating the query parameter only when a meaningful change is detected (e.g., when a user's role or workspace data is modified).
  • Reevaluate Preload Necessity: Verify if preloading with a non-cached response is essential. If the workspace information doesn't change every second, a less aggressive cache-busting method might suffice.

The verification process (searching for additional references within the codebase) shows that this preload link appears to be the only direct usage of the workspaces API endpoint. Given this and the potential performance implications, the review comment's suggestion to optimize the cache-busting strategy is well-founded.

apiserver/plane/app/views/workspace/base.py (2)

191-191: LGTM! Efficient use of annotations.

The code efficiently combines role and total_members annotations in a single query using Django's annotation system.


50-50: LGTM! Proper permission controls in place.

The code maintains proper security through:

  • Base permission class for the viewset
  • Role-based permission decorators for specific actions
  • Proper filtering of querysets based on user membership

Also applies to: 147-147, 151-151, 155-155

apiserver/plane/app/views/workspace/base.py Outdated Show resolved Hide resolved
@sriramveeraghanta sriramveeraghanta merged commit a2328d0 into preview Feb 10, 2025
9 of 14 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-workspace-switcher branch February 10, 2025 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants