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

feat: add issue attachment v1 endpoint #6307

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

pablohashescobar
Copy link
Collaborator

@pablohashescobar pablohashescobar commented Jan 3, 2025

Description

Added the IssueAttachment endpoint to create and fetch attachments from v1 apis.

Type of Change

  • Feature (non-breaking change which adds functionality)

Summary by CodeRabbit

  • New Features

    • Enhanced issue attachment handling with improved validation
    • Added ability to retrieve individual attachments
    • Introduced new method to update existing attachments
  • Bug Fixes

    • Refined file type validation and upload process
    • Implemented more robust attachment management
  • Improvements

    • Added support for generating presigned URLs for file uploads and downloads
    • Improved error handling for attachment operations

Copy link
Contributor

coderabbitai bot commented Jan 3, 2025

Walkthrough

The changes in the apiserver/plane/api/views/issue.py file focus on enhancing the IssueAttachmentEndpoint class's functionality for handling issue attachments. The modifications include improved validation for file uploads, a new UUID-based asset key generation, and refined methods for creating, retrieving, updating, and deleting attachments. The updates introduce more robust file handling, including checks for file types, size, and name, and implement a soft-delete approach for attachments.

Changes

File Change Summary
apiserver/plane/api/views/issue.py - Added validation for attachment uploads
- Implemented UUID-based asset key generation
- Updated FileAsset creation with new parameters
- Modified delete method to soft-delete attachments
- Added get method to retrieve individual attachments
- Introduced patch method for updating attachment status

Sequence Diagram

sequenceDiagram
    participant Client
    participant IssueAttachmentEndpoint
    participant FileAsset
    participant S3Storage

    Client->>IssueAttachmentEndpoint: POST attachment
    IssueAttachmentEndpoint->>IssueAttachmentEndpoint: Validate attachment
    IssueAttachmentEndpoint->>FileAsset: Create FileAsset
    FileAsset-->>IssueAttachmentEndpoint: Return asset details
    IssueAttachmentEndpoint-->>S3Storage: Generate presigned URL
    IssueAttachmentEndpoint-->>Client: Return upload details
Loading

Poem

🐰 Attachments dance, a digital delight,
With UUIDs and checks so tight,
Soft deletes and uploads so neat,
Our issue tracker's now a treat!
Hop along, code rabbit's might! 🚀


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.

@pablohashescobar pablohashescobar changed the title feat: add issue attachment endpoint feat: add issue attachment v1 endpoint Jan 3, 2025
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 (3)
apiserver/plane/api/views/issue.py (3)

948-1032: Solid attachment creation logic with a few suggestions.

  1. Size-Capping vs. Rejection
    At line 961, the logic silently caps the file size using min(size, settings.FILE_SIZE_LIMIT), which might confuse users expecting an error if size exceeds the limit. Consider explicitly rejecting oversized files to align with typical behavior and user expectations.

  2. File name sanitization
    At lines 949–950, we accept user-derived name and type. Although this is partially mitigated by random prefixing (line 973), you might want to ensure there's no path-traversal risk (e.g., ../). A quick check or sanitization can help avoid any edge-case vulnerabilities.

  3. Long line warning
    Static analysis flagged line 997 (> 88 chars). Consider wrapping or splitting it per the project’s style:

    - "error": "Issue with the same external id and external source already exists",
    + "error": (
    +     "Issue with the same external id "
    +     "and external source already exists"
    + ),
  4. Overall
    The rest of the logic—validating required fields, creating the FileAsset, generating a presigned URL, and returning it—appears consistent and robust.

🧰 Tools
🪛 Ruff (0.8.2)

997-997: Line too long (98 > 88)

(E501)


1035-1057: Soft-delete approach is reasonable but can be improved.

  1. Consolidating saves
    The method calls issue_attachment.save() at lines 1041 and again at 1057. Merging these into a single save call after setting all desired fields can reduce overhead and minimize the risk of stale data between saves.

  2. Soft-delete vs. S3 deletion
    Setting is_deleted to True (lines 1039-1041) does not remove the object from storage. This may be intentional. If you eventually need to free S3 space, consider scheduling or providing a separate process to delete the file from S3.

  3. Optional check for is_deleted
    Because we rely on soft deletes, you might also want to exclude such attachments from future listings (e.g., in get methods) to ensure consistent user experience.


1094-1122: Patch method effectively finalizes uploads with a minor naming concern.

  1. Event naming
    At lines 1102–1113, you trigger "attachment.activity.created". Consider leveraging "attachment.activity.uploaded" (or similar) to more accurately depict the event.

  2. Idempotent design
    Checking if not issue_attachment.is_uploaded: ensures you only log the event once. This is a good approach to prevent duplicated notifications.

  3. Test coverage
    If coverage is lacking, consider adding tests to ensure the patch operation consistently sets is_uploaded and triggers the correct activity log.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 873e433 and 8ff8518.

📒 Files selected for processing (1)
  • apiserver/plane/api/views/issue.py (4 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
apiserver/plane/api/views/issue.py

997-997: Line too long (98 > 88)

(E501)

🔇 Additional comments (2)
apiserver/plane/api/views/issue.py (2)

3-3: All new or updated imports appear correct.

These additions (e.g., uuid, DjangoJSONEncoder, and references to settings, Workspace, S3Storage, get_asset_object_metadata) support the new attachment workflow. No immediate concerns.

Also applies to: 6-7, 23-23, 54-54, 56-57


1060-1093: Confirm visibility of soft-deleted attachments.

  1. Filtering out is_deleted
    The listing at lines 1084–1090 does not exclude files marked as deleted (is_deleted=True). If the intention is to hide soft-deleted records from users, add is_deleted=False in the filter.

  2. Presigned URL redirect
    Lines 1074–1080 properly redirect to a presigned URL. This approach is straightforward. Just verify that returning an HTTP redirect is acceptable for your client’s workflow and security model (e.g., handling sensitive attachments).

@sriramveeraghanta sriramveeraghanta merged commit 3fd2550 into preview Jan 3, 2025
12 of 14 checks passed
@sriramveeraghanta sriramveeraghanta deleted the feat-issue-attachment branch January 3, 2025 08:59
sriramveeraghanta added a commit that referenced this pull request Jan 6, 2025
* WIP

* WIP

* WIP

* WIP

* Create home preference if not exist

* chore: handled the unique state name validation (#6299)

* fix: changed the response structure (#6301)

* [WEB-1964]chore: cycles actions restructuring (#6298)

* chore: cycles quick actions restructuring

* chore: added additional actions to cycle list actions

* chore: cycle quick action structure

* chore: added additional actions to cycle list actions

* chore: added end cycle hook

* fix: updated end cycle export

---------

Co-authored-by: gurusinath <[email protected]>

* fix: active cycle graph tooltip and endpoint validation (#6306)

* [WEB-2870]feat: language support (#6215)

* fix: adding language support package

* fix: language support implementation using mobx

* fix: adding more languages for support

* fix: profile settings translations

* feat: added language support for sidebar and user settings

* feat: added language support for deactivation modal

* fix: added project sync after transfer issues (#6200)

* code refactor and improvement (#6203)

* chore: package code refactoring

* chore: component restructuring and refactor

* chore: comment create improvement

* refactor: enhance workspace and project wrapper modularity (#6207)

* [WEB-2678]feat: added functionality to add labels directly from dropdown (#6211)

* enhancement:added functionality to add features directly from dropdown

* fix: fixed import order

* fix: fixed lint errors

* chore: added common component for project activity (#6212)

* chore: added common component for project activity

* fix: added enum

* fix: added enum for initiatives

* - Do not clear temp files that are locked. (#6214)

- Handle edge cases in sync workspace

* fix: labels empty state for drop down (#6216)

* refactor: remove cn helper function from the editor package (#6217)

* * feat: added language support to issue create modal in sidebar
* fix: project activity type

* * fix: added missing translations
* fix: modified translation for plurals

* fix: fixed spanish translation

* dev: language type error in space user profile types

* fix: type fixes

* chore: added alpha tag

---------

Co-authored-by: sriram veeraghanta <[email protected]>
Co-authored-by: Anmol Singh Bhatia <[email protected]>
Co-authored-by: Prateek Shourya <[email protected]>
Co-authored-by: Akshita Goyal <[email protected]>
Co-authored-by: Satish Gandham <[email protected]>
Co-authored-by: Aaryan Khandelwal <[email protected]>
Co-authored-by: gurusinath <[email protected]>

* feat: introduced stacked bar chart and tree map chart. (#6305)

* feat: add issue attachment external endpoint (#6307)

* [PE-97] chore: re-order pages options (#6303)

* chore: re-order pages dropdown options

* chore: re-order pages dropdown options

* fix: remove localdb tracing

* [WEB-2937] feat: home recent activies list endpoint (#6295)

* Crud for wuick links

* Validate quick link existence

* Add custom method for destroy and retrieve

* Add List method

* Remove print statements

* List all the workspace quick links

* feat: endpoint to get recently active items

* Resolve conflicts

* Resolve conflicts

* Add filter to only list required entities

* Return required fields

* Add filter

* Add filter

* fix: remove emoji edit for uneditable pages (#6304)

* Removed duplicate imports

* feat: patch api

* Enable sort order to be updatable

* Return key name
only insert missing keys
use serializer to return data

* Remove random generation of sort_order

* Remove name field
Remove random generation of sort_order

---------

Co-authored-by: Bavisetti Narayan <[email protected]>
Co-authored-by: Vamsi Krishna <[email protected]>
Co-authored-by: gurusinath <[email protected]>
Co-authored-by: Anmol Singh Bhatia <[email protected]>
Co-authored-by: sriram veeraghanta <[email protected]>
Co-authored-by: Prateek Shourya <[email protected]>
Co-authored-by: Akshita Goyal <[email protected]>
Co-authored-by: Satish Gandham <[email protected]>
Co-authored-by: Aaryan Khandelwal <[email protected]>
Co-authored-by: Nikhil <[email protected]>
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.

2 participants