Skip to content

[WIKI-181] chore: asset check endpoint added#7140

Merged
sriramveeraghanta merged 1 commit intopreviewfrom
chore/asset-check-endpoint
May 30, 2025
Merged

[WIKI-181] chore: asset check endpoint added#7140
sriramveeraghanta merged 1 commit intopreviewfrom
chore/asset-check-endpoint

Conversation

@aaryan610
Copy link
Member

@aaryan610 aaryan610 commented May 30, 2025

Description

This PR creates a new endpoint to check whether an asset exists or not.

Type of Change

  • Improvement (change that would cause existing functionality to not work as expected)

Summary by CodeRabbit

  • New Features

    • Added an API endpoint to check if a specific asset exists within a workspace.
    • Introduced a method in the editor to verify asset existence by ID.
    • Enhanced file services to support asset existence checks.
  • Bug Fixes

    • None.
  • Documentation

    • None.
  • Refactor

    • None.
  • Style

    • None.
  • Tests

    • None.
  • Chores

    • None.
  • Revert

    • None.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 30, 2025

Walkthrough

A new API endpoint and supporting frontend logic were introduced to check the existence of a file asset by its ID within a workspace. This includes backend Django view and URL updates, TypeScript type and service additions, and integration of the check method into editor-related handlers.

Changes

File(s) Change Summary
apiserver/plane/app/urls/asset.py, apiserver/plane/app/views/init.py Added import and URL route for AssetCheckEndpoint to asset-related endpoints.
apiserver/plane/app/views/asset/v2.py Introduced AssetCheckEndpoint class with GET method to verify asset existence.
packages/editor/src/core/types/config.ts Added checkIfAssetExists method to TReadOnlyFileHandler type.
space/helpers/editor.helper.ts Added stub checkIfAssetExists method returning true to read-only editor file handlers.
web/core/hooks/editor/use-editor-config.ts Integrated checkIfAssetExists method, calling file service and returning asset existence boolean.
web/core/services/file.service.ts Added checkIfAssetExists method to FileService for API communication to backend endpoint.

Sequence Diagram(s)

sequenceDiagram
    participant Frontend
    participant FileService
    participant BackendAPI
    participant Database

    Frontend->>FileService: checkIfAssetExists(workspaceSlug, assetId)
    FileService->>BackendAPI: GET /api/assets/v2/workspaces/{workspaceSlug}/check/{assetId}/
    BackendAPI->>Database: Query FileAsset (by assetId, workspaceSlug, not deleted)
    Database-->>BackendAPI: Asset existence (true/false)
    BackendAPI-->>FileService: { exists: true/false }
    FileService-->>Frontend: { exists: true/false }
Loading

Poem

In the warren of code, a tunnel appears,
To check if an asset still hops or disappears.
A GET and a promise, a boolean reply—
"Exists?" asks the frontend, and backend says, "Aye!"
Now rabbits can rest, their files in sight,
For asset checks happen with speed and delight.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@makeplane
Copy link

makeplane bot commented May 30, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

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 4a97d7c and ac54ac5.

📒 Files selected for processing (7)
  • apiserver/plane/app/urls/asset.py (2 hunks)
  • apiserver/plane/app/views/__init__.py (1 hunks)
  • apiserver/plane/app/views/asset/v2.py (1 hunks)
  • packages/editor/src/core/types/config.ts (1 hunks)
  • space/helpers/editor.helper.ts (1 hunks)
  • web/core/hooks/editor/use-editor-config.ts (1 hunks)
  • web/core/services/file.service.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
apiserver/plane/app/views/__init__.py (1)
apiserver/plane/app/views/asset/v2.py (1)
  • AssetCheckEndpoint (712-720)
apiserver/plane/app/urls/asset.py (1)
apiserver/plane/app/views/asset/v2.py (1)
  • AssetCheckEndpoint (712-720)
web/core/hooks/editor/use-editor-config.ts (1)
web/core/store/router.store.ts (1)
  • workspaceSlug (69-71)
web/core/services/file.service.ts (1)
web/core/store/router.store.ts (1)
  • workspaceSlug (69-71)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (7)
apiserver/plane/app/views/__init__.py (1)

109-109: LGTM: Clean import addition following established patterns.

The import of AssetCheckEndpoint is properly placed within the asset v2 imports section and follows the existing code organization.

packages/editor/src/core/types/config.ts (1)

2-2: LGTM: Well-defined type signature for asset existence checking.

The method signature is clear and appropriate:

  • Descriptive parameter name assetId
  • Correct return type Promise<boolean> for async existence check
  • Properly placed within TReadOnlyFileHandler type
apiserver/plane/app/urls/asset.py (2)

15-15: LGTM: Proper import of the new endpoint.

The AssetCheckEndpoint import is correctly added to support the new URL routing.


87-91: LGTM: Well-structured URL pattern following established conventions.

The new URL pattern is properly designed:

  • Follows RESTful naming with /check/ path segment
  • Uses appropriate parameter types (str:slug, uuid:asset_id)
  • Consistent with other v2 asset endpoints
  • Descriptive URL name "asset-check"
web/core/hooks/editor/use-editor-config.ts (1)

32-35:

Details

❌ Incorrect review comment

Verify workspaceSlug availability and add error handling.

The implementation looks good and follows existing patterns. However, consider adding validation for workspaceSlug to prevent potential runtime errors.

Let me check if workspaceSlug can be undefined in this context:


🏁 Script executed:

#!/bin/bash
# Description: Check how workspaceSlug is used in similar methods and verify its availability

# Search for similar usage patterns of workspaceSlug in this file and related files
rg -A 3 -B 3 "workspaceSlug" --type ts

# Check if there are any null checks for workspaceSlug in the codebase
ast-grep --pattern 'workspaceSlug && $_'

Length of output: 68195


I need to inspect how workspaceSlug is sourced in the hook to confirm its non-null guarantees:


🏁 Script executed:

#!/bin/bash
# Print the start of the hook file to see where workspaceSlug comes from
sed -n '1,200p' web/core/hooks/editor/use-editor-config.ts

Length of output: 2919


No workspaceSlug null check needed

The workspaceSlug parameter is defined as a required string in the TArgs type and is always passed into getReadOnlyEditorFileHandlers. TypeScript guarantees it cannot be undefined, so no additional runtime validation is necessary.

Likely an incorrect or invalid review comment.

web/core/services/file.service.ts (1)

239-250: LGTM! Clean implementation following established patterns.

The method implementation is excellent:

  • Consistent with existing FileService patterns
  • Proper error handling with standardized error propagation
  • Clear method signature and return type
  • Appropriate URL construction following the API conventions
apiserver/plane/app/views/asset/v2.py (1)

712-720:

Details

❓ Verification inconclusive

LGTM! Well-structured endpoint with proper permissions and filtering.

The implementation is excellent:

  • Appropriate permission decorator for workspace-level access
  • Correct use of all_objects with deleted_at__isnull=True filter to check non-deleted assets
  • Proper response format matching frontend expectations
  • Follows established Django view patterns in the codebase

Consider database performance if this endpoint will be called frequently:


🏁 Script executed:

#!/bin/bash
# Description: Check if there are database indexes on the fields used in the query

# Look for database migrations or model definitions that might have indexes
fd -e py -x grep -l "asset.*index\|index.*asset" {} \;
rg -A 5 -B 5 "class.*FileAsset" --type py

Length of output: 4691


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== FileAsset Model Definition ==="
rg -n "class FileAsset" -A 200 apiserver/plane/db/models/asset.py

echo ""
echo "=== Workspace Model File Path ==="
rg -l "class Workspace" --type py

echo ""
echo "=== Workspace Model Definition ==="
rg -n "class Workspace" -A 200 $(rg -l "class Workspace" --type py)

Length of output: 97584


AssetCheckEndpoint Implementation Approved — Please Confirm Database Indexes

The AssetCheckEndpoint is well-structured, follows existing Django patterns, and correctly uses the all_objects manager with deleted_at__isnull=True to check for non-deleted assets. Permissions and response format are appropriate.

Performance considerations:

  • file_assets.id is the primary key and indexed by default.
  • file_assets.workspace_id (foreign key) is indexed by default.
  • Please confirm that workspace.slug is defined as a unique/indexed field in the Workspace model to ensure efficient joins on the workspace__slug filter.

@sriramveeraghanta sriramveeraghanta merged commit 151fc83 into preview May 30, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the chore/asset-check-endpoint branch May 30, 2025 15:28
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.

4 participants