Skip to content

Comments

[WEB-3597] fix: guest work item view access when hyper mode is enabled #6785

Merged
sriramveeraghanta merged 2 commits intopreviewfrom
fix-no-load-guest-access
Mar 20, 2025
Merged

[WEB-3597] fix: guest work item view access when hyper mode is enabled #6785
sriramveeraghanta merged 2 commits intopreviewfrom
fix-no-load-guest-access

Conversation

@prateekshourya29
Copy link
Member

@prateekshourya29 prateekshourya29 commented Mar 20, 2025

Description

This PR resolves an issue where guest were able to view work items even when view access was disabled for guests.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Summary by CodeRabbit

  • New Features

    • Enhanced guest-access controls: Projects now include a setting that indicates if guests can view all features, ensuring that guest users only see data when permitted.
    • Improved issue visibility: When guest access is restricted, guests will no longer see issue data.
  • Refactor

    • Streamlined project settings by removing outdated configuration fields for better clarity and maintainability.
    • Updated query handling for improved robustness and type safety in issue retrieval.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

Walkthrough

The changes add a new field, guest_view_all_features, to the project API response and adjust type definitions accordingly. The API now includes an extra attribute in the ProjectViewSet list method to support guest permissions. In the TypeScript definitions, the field is added to IPartialProject and removed from IProject along with two other properties. Additionally, the local database retrieval logic in Storage.getIssues is updated to enforce an early exit when a guest user attempts to access features not permitted by the project settings.

Changes

File(s) Change Summary
apiserver/.../project/base.py Added the guest_view_all_features field to the list method in ProjectViewSet.
packages/types/.../projects.d.ts Added guest_view_all_features as an optional property to IPartialProject and removed it, along with is_issue_type_enabled and is_time_tracking_enabled, from IProject.
web/core/.../storage.sqlite.ts Enhanced getIssues by modifying parameter types and introducing query sanitization logic.
web/core/.../utils/query-sanitizer.ts Added sanitizeWorkItemQueries function to clean up query parameters based on user permissions.
web/core/.../issue.service.ts Updated getIssues method to enforce type safety for query parameters using TIssueParams.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Storage
    participant RootStore

    User->>Storage: Request issues for a project
    Storage->>RootStore: Retrieve project details & user role
    RootStore-->>Storage: Return project details and role
    alt User is guest and guest view is disallowed
        Storage-->>User: Return empty results
    else
        Storage-->>User: Return issues data
    end
Loading

Possibly related PRs

Suggested labels

🐛bug, 🌐frontend, ⚙️backend

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham
  • rahulramesha

Poem

I'm a little code rabbit, hopping by at dawn,
Adding new fields so our projects live on.
A guest view field in a spring of clean code,
Guarding permissions on each little node.
With a hop and a nibble, I debug with delight,
Celebrating changes from morning to night!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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.

@prateekshourya29 prateekshourya29 marked this pull request as draft March 20, 2025 10:47
@henit-chobisa henit-chobisa changed the title [WEB-3597] fix: guest work item view access when hyper mode is enabled [WEB-3597] fix: guest work item view access when hyper mode is enabled Mar 20, 2025
@henit-chobisa henit-chobisa changed the title [WEB-3597] fix: guest work item view access when hyper mode is enabled [WEB-3597] fix: guest work item view access when hyper mode is enabled Mar 20, 2025
@prateekshourya29 prateekshourya29 marked this pull request as ready for review March 20, 2025 12:14
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/local-db/utils/query-sanitizer.ts.ts (1)

28-30: Consider adding a comment explaining the shouldApplyFilter condition.

The logic for determining when to apply the filter is correct, but slightly complex. A comment explaining when we should or shouldn't override the existing filter would improve maintainability.

    const shouldApplyFilter =
      !existingCreatedByFilter ||
      (typeof existingCreatedByFilter === "string" && existingCreatedByFilter.includes(currentUserId));
+    // Apply filter when no created_by filter exists or when the current filter already includes this user
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4339f71 and 59bf311.

📒 Files selected for processing (3)
  • web/core/local-db/storage.sqlite.ts (5 hunks)
  • web/core/local-db/utils/query-sanitizer.ts.ts (1 hunks)
  • web/core/services/issue/issue.service.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/core/local-db/storage.sqlite.ts
🔇 Additional comments (5)
web/core/local-db/utils/query-sanitizer.ts.ts (2)

7-41: Solid implementation of guest access restrictions.

The sanitizeWorkItemQueries function effectively implements the security fix for guest work item access by:

  1. Checking if the current user is a guest and if the project has disabled the guest_view_all_features setting
  2. Ensuring guests can only see work items they've created by enforcing the created_by filter

This implementation correctly addresses the security issue mentioned in the PR objectives.


21-25:

Details

❓ Verification inconclusive

Verify the behavior when currentProject is undefined.

The code checks if currentProject?.guest_view_all_features === false, but doesn't handle the case where currentProject is undefined. Consider what happens if project data hasn't loaded yet.


🏁 Script executed:

#!/bin/bash
# Check how currentProject is initialized in the codebase

# Find where projectRoot.project.getProjectById is defined
rg -A 10 "projectRoot\s*=\s*{" --type ts

# Check if the getProjectById method handles undefined cases
rg -A 5 "getProjectById\s*\(" --type ts

Length of output: 51546


Attention: Verify Handling of Undefined Project Data for Guest Users
When currentProject is undefined, the optional chaining in

currentProject?.guest_view_all_features === false

evaluates to undefined === false (i.e. false), which means the restriction block won’t run. This behavior is consistent with many usages of getProjectById in the codebase; however, please confirm that it’s acceptable in cases where project data hasn’t loaded yet. If the design requires applying guest restrictions even while the project data is pending, an explicit check for an undefined currentProject might be necessary.

  • Review Point: Confirm that skipping the branch when currentProject is undefined is intended.
  • Suggestion: If guest users should be restricted by default when project data is not yet available, consider adding an explicit undefined check.
web/core/services/issue/issue.service.ts (3)

4-4: Good addition of the TIssueParams import.

Adding this import supports the type safety improvements in the getIssues method.


79-84: Improved type safety for getIssues method.

The updated type signature (Partial<Record<TIssueParams, string | boolean>>) provides better type safety compared to the previous any type. This aligns well with the sanitization function implemented in query-sanitizer.ts.


89-89:

Details

✅ Verification successful

Verify that persistence.getIssues is updated to use the sanitizeWorkItemQueries function.

This line calls persistence.getIssues with the queries, but we need to ensure this function is properly utilizing the new sanitization function to enforce guest access restrictions.


🏁 Script executed:

#!/bin/bash
# Check how persistence.getIssues is implemented and if it uses sanitizeWorkItemQueries

# Find the persistence.getIssues method definition
rg -A 15 "getIssues\s*\(" --type ts

# Check if sanitizeWorkItemQueries is imported and used in the file
rg "sanitizeWorkItemQueries" --type ts

Length of output: 27027


Persistence Layer Query Sanitization Confirmed

After verification, it appears that the persistence layer handles query sanitization. Although the service file (web/core/services/issue/issue.service.ts) invokes persistence.getIssues without directly applying sanitizeWorkItemQueries, the implementation in the persistence layer (e.g., in web/core/local-db/storage.sqlite.ts) shows that sanitizeWorkItemQueries is imported and used appropriately. No additional changes are required here.

@henit-chobisa henit-chobisa changed the title [WEB-3597] fix: guest work item view access when hyper mode is enabled [WEB-3597] fix: guest work item view access when hyper mode is enabled Mar 20, 2025
@makeplane
Copy link

makeplane bot commented Mar 20, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

@sriramveeraghanta sriramveeraghanta merged commit 94bf90d into preview Mar 20, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-no-load-guest-access branch March 20, 2025 14:13
lifeiscontent pushed a commit that referenced this pull request Aug 18, 2025
#6785)

* [WEB-3597] fix: guest work item view access when hyper mode is enabled

* fix: only show work item created by the guest user if the guest_view_all_features is disabled
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.

2 participants