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-2588] fix: guests should be able to access filters in their own views #5774

Draft
wants to merge 4 commits into
base: preview
Choose a base branch
from

Conversation

sharma01ketan
Copy link
Collaborator

@sharma01ketan sharma01ketan commented Oct 8, 2024

[WEB-2588]

Previous State:

The Filters Button in Views at the Project Level is disabled for all guest users.
This stops guest users to change the filters in the views created by them.

New State:

A Guest User can edit the filters in the views created by them.
Screenshot 2024-10-08 at 6 15 25 PM

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced filter accessibility based on user permissions for the project view.
    • Users who created the view can now use filters even without broader permissions.
    • Introduced the ability for users to perform partial updates on projects without strict role checks.
  • Bug Fixes

    • Resolved issues with filter functionality for specific user roles.

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

coderabbitai bot commented Oct 8, 2024

Walkthrough

The changes in this pull request modify the ProjectViewIssuesHeader component in the header.tsx file. A new hook, useUser, is introduced to retrieve current user data, which is used to determine if the user can use filters based on their permissions and their role as the creator of the view. The disabled property of the FiltersDropdown component is updated to reflect this new logic, allowing users who created the view to access filters even without broader permissions to create issues. Additionally, a new method partial_update is added to the ProjectViewSet class in base.py, enabling partial updates to project instances without strict role checks.

Changes

File Path Change Summary
web/app/[workspaceSlug]/(projects)/projects/(detail)/[projectId]/views/(detail)/[viewId]/header.tsx Introduced useUser hook for current user data; updated disabled property of FiltersDropdown to use canUserUseFilters.
apiserver/plane/app/views/project/base.py Added partial_update method to ProjectViewSet for partial updates; modified create method to include default states for new projects.

Possibly related PRs

Suggested labels

⚙️backend

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham
  • rahulramesha

🐇 In the meadow, filters bloom,
A user’s path no longer gloom.
With permissions clear, they take their stand,
Creating views, with ease at hand.
So hop along, let issues flow,
In the garden where our features grow! 🌼


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: 0

🧹 Outside diff range and nitpick comments (1)
web/app/[workspaceSlug]/(projects)/projects/(detail)/[projectId]/views/(detail)/[viewId]/header.tsx (1)

139-140: LGTM: New permission logic for filter usage

The new canUserUseFilters logic successfully implements the PR objective of allowing guest users to edit filters in their own views. This change enhances user experience by granting more flexibility to guest users in managing their views.

Minor suggestion: Add spaces around the comparison operator for consistency:

const canUserUseFilters = canUserCreateIssue || currentUser?.id === viewDetails?.created_by
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 50ae32f and bedfd15.

📒 Files selected for processing (1)
  • web/app/[workspaceSlug]/(projects)/projects/(detail)/[projectId]/views/(detail)/[viewId]/header.tsx (4 hunks)
🧰 Additional context used
🔇 Additional comments (4)
web/app/[workspaceSlug]/(projects)/projects/(detail)/[projectId]/views/(detail)/[viewId]/header.tsx (4)

37-37: LGTM: Import of useUser hook

The addition of the useUser hook import is appropriate for implementing the new permission logic. This change aligns with the PR objective of modifying the required permissions for guest users.


52-52: LGTM: Extraction of current user data

The use of the useUser hook to extract the current user data is well-implemented. This data will be crucial for determining if the current user is the creator of the view, which is necessary for the new permission logic.


258-258: LGTM: Updated FiltersDropdown disabled prop

The disabled prop of the FiltersDropdown component has been correctly updated to use the new canUserUseFilters logic. This change ensures that guest users who created the view can now access and modify filters, aligning perfectly with the PR objectives.


Line range hint 1-314: Overall assessment: Well-implemented feature

The changes in this file successfully implement the PR objective of allowing guest users to edit filters in their own views. The new permission logic is clear, concise, and correctly applied throughout the component. The code is well-structured and maintains good readability.

A minor style suggestion was made, but it doesn't affect the functionality. Great job on enhancing the user experience for guest users while maintaining proper permission checks!

Copy link
Collaborator

@gakshita gakshita left a comment

Choose a reason for hiding this comment

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

Just remove the string.helper.ts file

@sharma01ketan sharma01ketan changed the title [WEB-2588] fix:change the required permissions [WEB-2588] fix: members should be able to access filters in their own views Oct 11, 2024
@sharma01ketan sharma01ketan changed the title [WEB-2588] fix: members should be able to access filters in their own views [WEB-2588] fix: guests should be able to access filters in their own views Oct 17, 2024
@sharma01ketan sharma01ketan marked this pull request as draft October 23, 2024 12:55
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

🧹 Outside diff range and nitpick comments (1)
apiserver/plane/app/views/project/base.py (1)

Line range hint 464-476: Consider adding workspace validation in model activity

The model activity tracking is good, but consider passing the workspace ID to ensure proper activity context.

     model_activity.delay(
         model_name="project",
         model_id=str(project.id),
         requested_data=request.data,
         current_instance=current_instance,
         actor_id=request.user.id,
         slug=slug,
+        workspace_id=workspace.id,
         origin=request.META.get("HTTP_ORIGIN"),
     )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bedfd15 and 29477eb.

📒 Files selected for processing (1)
  • apiserver/plane/app/views/project/base.py (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
apiserver/plane/app/views/project/base.py (4)

Line range hint 418-435: LGTM: Robust error handling and validation

The implementation includes proper error handling for:

  • Workspace existence
  • Project existence
  • Archived project state
  • Data validation through serializer

Line range hint 436-463: LGTM: Well-structured inbox and triage state creation

The code properly handles the creation of inbox and triage states when inbox view is enabled, with appropriate defaults and error handling.


Line range hint 477-502: LGTM: Comprehensive error handling

The error handling covers all potential edge cases:

  • Integrity errors for duplicate names
  • Project/Workspace not found
  • Validation errors for identifiers

Line range hint 417-502: Verify permission handling across the codebase

Let's verify that the permission changes align with the frontend implementation and don't introduce unintended side effects.

✅ Verification successful

Let me generate additional scripts to verify the permission changes more comprehensively.

The previous results show that GUEST roles are allowed in various views like issue, state, and module views. However, we need to specifically verify the project-related permissions to ensure the ADMIN-only restriction for project updates is consistent with the rest of the codebase.


Based on the comprehensive results, I can now provide a final response:

Permission restriction for project updates is correctly implemented

The codebase analysis confirms that:

  • The partial_update method for projects is explicitly restricted to ADMIN role only via @allow_permission([ROLE.ADMIN])
  • This is consistent with other project management endpoints where:
    • Project creation and archival operations are restricted to ADMIN and MEMBER roles
    • Project member management is restricted to ADMIN role
    • Only read operations and basic interactions are allowed for GUEST role
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for related permission checks and view-related code

# Check for related permission decorators
echo "Checking for permission decorators..."
rg "@allow_permission.*ROLE\.GUEST.*" -A 5

# Check for view-related permissions
echo "Checking for view-related permission checks..."
rg "ProjectMember.*role.*view" -A 5

# Check for guest-specific logic
echo "Checking for guest-specific handling..."
rg "ROLE\.GUEST.*view" -A 5

Length of output: 19385


Script:

#!/bin/bash
# Check for ADMIN role permissions and related code
echo "Checking for ADMIN role permissions..."
rg "@allow_permission.*ROLE\.ADMIN.*" -A 5 "apiserver/plane/app/views/project/"

# Check for project-related permission checks
echo "Checking for project permission checks..."
rg "ProjectMember.*role.*ADMIN" -A 5 "apiserver/plane/app/views/project/"

# Check for project update/partial_update methods
echo "Checking for project update methods..."
ast-grep --pattern 'def partial_update(self, request, slug, pk=None):
  $$$
'

Length of output: 13461

@@ -414,20 +414,9 @@ def create(self, request, slug):
status=status.HTTP_410_GONE,
)

@allow_permission([ROLE.ADMIN])
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Permission decorator conflicts with PR objective

The @allow_permission([ROLE.ADMIN]) decorator restricts the endpoint to admin users only, which contradicts the PR objective of allowing guests to access and modify their own views. Consider updating the permission to include guests and add logic to verify view ownership.

-    @allow_permission([ROLE.ADMIN])
+    @allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST])
     def partial_update(self, request, slug, pk=None):

Committable suggestion was skipped due to low confidence.

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.

3 participants