Skip to content

Add collection download as JSON endpoint#4509

Open
brandonjackson wants to merge 1 commit intomainfrom
claude/add-collection-download-WTRq6
Open

Add collection download as JSON endpoint#4509
brandonjackson wants to merge 1 commit intomainfrom
claude/add-collection-download-WTRq6

Conversation

@brandonjackson
Copy link
Contributor

@brandonjackson brandonjackson commented Mar 6, 2026

Description

This PR adds a new endpoint to download collection items as JSON files. Users can now export collection data from a project via GET /download/collection with query parameters for project_id and collection name.

The implementation includes:

  • New download_collection_json/2 controller action with proper authorization checks
  • Streaming response handler (stream_collection_items/2) that efficiently processes large collections in batches of 500 items
  • Download button in the collections UI component
  • Comprehensive test coverage for success cases, authorization, and error scenarios

Validation steps

  1. Navigate to a project with collections
  2. Click the "Download" button next to a collection
  3. Verify the JSON file downloads with correct filename and content
  4. Test with empty collections (should return [])
  5. Verify authorization: non-project members should receive 401, non-existent collections should return 404
  6. Run test suite: mix test test/lightning_web/controllers/download_controller_test.exs

Additional notes for the reviewer

  • Authorization is enforced via ProjectUsers and Permissions.can/4 to ensure only project members can download
  • Collection ownership is validated by checking collection.project_id == project.id
  • Streaming implementation uses Plug.Conn.chunk/2 to handle large datasets efficiently
  • The endpoint follows the same pattern as the existing download_project_yaml action

AI Usage

  • I have used Claude Code
  • I have used another model
  • I have not used AI

Pre-submission checklist

  • I have performed an AI review of my code (we recommend using /review with Claude Code)
  • I have implemented and tested all related authorization policies. (e.g., :owner, :admin, :editor, :viewer)
  • I have updated the changelog.
  • I have ticked a box in "AI usage" in this PR

https://claude.ai/code/session_0133om1iWqftcidvyYshXDFQ

Add a Download button to each collection row in the settings table,
allowing users to download all collection items as a JSON file.

- Add GET /download/collection route with browser session auth
- Add download_collection_json/2 to DownloadsController with chunked
  streaming to handle large collections efficiently
- Add Download link in CollectionsComponent actions slot
- Add tests for success, empty, unauthorized, not found, and
  project mismatch scenarios

https://claude.ai/code/session_0133om1iWqftcidvyYshXDFQ
@github-project-automation github-project-automation bot moved this to New Issues in Core Mar 6, 2026
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 96.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.55%. Comparing base (75489ef) to head (f84a047).

Files with missing lines Patch % Lines
.../lightning_web/controllers/downloads_controller.ex 95.65% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4509   +/-   ##
=======================================
  Coverage   89.55%   89.55%           
=======================================
  Files         425      425           
  Lines       20295    20320   +25     
=======================================
+ Hits        18175    18198   +23     
- Misses       2120     2122    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@midigofrank midigofrank self-requested a review March 9, 2026 10:31
Copy link
Collaborator

@midigofrank midigofrank left a comment

Choose a reason for hiding this comment

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

@brandonjackson , this is definitely in the right direction. We can polish it a little bit to reduce duplication of the streaming logic and also to reuse the auth logic used by other actions. 🤔 I'd be curious to see how the app handles a 50mb collection

@github-project-automation github-project-automation bot moved this from New Issues to In review in Core Mar 10, 2026
@brandonjackson brandonjackson linked an issue Mar 12, 2026 that may be closed by this pull request
@theroinaochieng theroinaochieng marked this pull request as ready for review March 17, 2026 08:41
@stuartc stuartc self-requested a review March 19, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

Download collections from UI

3 participants