Skip to content

[ActiveStorage for All] Add a storage-neutral file API to Hyrax::UploadedFile#7554

Draft
orangewolf wants to merge 1 commit into
mainfrom
active-storage-for-all/uploaded-file-neutral-io
Draft

[ActiveStorage for All] Add a storage-neutral file API to Hyrax::UploadedFile#7554
orangewolf wants to merge 1 commit into
mainfrom
active-storage-for-all/uploaded-file-neutral-io

Conversation

@orangewolf

Copy link
Copy Markdown
Member

Summary

Part of the [ActiveStorage for All] chain (see #7553). This PR is a pure refactor — no behavior change.

Hyrax::UploadedFile gains a small storage-neutral API for reading staged content and metadata:

  • #filename, #content_type, #byte_size, #stored?
  • #with_io — yields a rewound binary IO with a real filesystem #path (what Valkyrie storage adapters need), closed deterministically after the block
  • #with_local_path — yields a local path for copy-based consumers

and the storage-agnostic consumers adopt it instead of reaching through the CarrierWave uploader:

Consumer Before
ValkyrieIngestJob#upload_file file.uploader.file.to_file (leaked the IO), .original_filename
Hyrax::WorkUploadsHandler#file_set_args file.uploader.filename
uploads/create.json.jbuilder uploaded_file.file&.file&.filename / .size
SaveCollectionBanner / SaveCollectionLogo steps, Dashboard::CollectionsController branding f.file_url used as a local filesystem path (only works because CarrierWave's store_dir is absolute)

ActiveFedora-specific consumers (JobIoWrapper, FileActor, FileSetActor) intentionally keep the CarrierWave interface — the AF ingest path is out of scope for this whole chain.

Why

These call sites were coupled to CarrierWave storing files at absolute local paths. Routing them through one narrow interface lets a follow-up PR add an opt-in Active Storage staging backend without touching every consumer (and keeps that follow-up reviewable).

Dependencies

None (independent of #7553; the two merge in either order).

Supersedes #7548 (same change, moved from a fork branch to an in-repo branch and retitled).

Tests

Run locally against the koppie (Valkyrie) test app — dockerized Postgres/Solr/Redis:

  • spec/models/hyrax/uploaded_file_spec.rb — new coverage for the API (16 examples, 0 failures)
  • spec/controllers/hyrax/uploads_controller_spec.rb, spec/services/hyrax/work_uploads_handler_spec.rb, spec/jobs/valkyrie_ingest_job_spec.rb, spec/hyrax/transactions/steps/save_collection_banner_spec.rb, spec/hyrax/transactions/steps/save_collection_logo_spec.rb (32 examples, 0 failures, 1 pending)
  • spec/controllers/hyrax/dashboard/collections_controller_spec.rb (102 examples, 0 failures, 2 pending)

AF-side (dassie) portions of the suite were not run locally; CI covers them. RuboCop clean on touched files; git diff --check clean.

🤖 Generated with Claude Code

Introduces filename, content_type, byte_size, stored?, with_io, and
with_local_path on Hyrax::UploadedFile as the supported interface for
reading staged upload content, and adopts it in the storage-agnostic
consumers: ValkyrieIngestJob, WorkUploadsHandler, the uploads JSON
response, the collection branding transaction steps, and the dashboard
collections controller.

These call sites were reaching through the CarrierWave uploader
(uploader.file.to_file, uploader.filename, file_url-as-local-path) and
so were coupled to CarrierWave storing files at absolute local paths.
Routing them through one narrow API prepares for an alternative Active
Storage staging backend without behavior change today; with_io also
deterministically closes the IO that ValkyrieIngestJob previously
leaked.

ActiveFedora-specific consumers (JobIoWrapper, FileActor, FileSetActor)
intentionally keep using the CarrierWave interface unchanged.

Tests: spec/models/hyrax/uploaded_file_spec.rb (new API coverage),
spec/controllers/hyrax/uploads_controller_spec.rb,
spec/services/hyrax/work_uploads_handler_spec.rb,
spec/jobs/valkyrie_ingest_job_spec.rb,
spec/hyrax/transactions/steps/save_collection_banner_spec.rb,
spec/hyrax/transactions/steps/save_collection_logo_spec.rb,
spec/controllers/hyrax/dashboard/collections_controller_spec.rb —
all green locally against the koppie (Valkyrie) test app.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Test Results

    17 files  ± 0      17 suites  ±0   3h 23m 4s ⏱️ - 6m 35s
 7 992 tests +15   7 683 ✅ +13  307 💤 ±0  2 ❌ +2 
27 331 runs  +56  26 727 ✅ +51  599 💤 ±0  5 ❌ +5 

For more details on these failures, see this check.

Results for commit bb199b2. ± Comparison against base commit 5cc41d6.

This pull request removes 448 and adds 463 tests. Note that renamed tests count towards both.
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplate:0x00007f37d68cb2d8>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplate:0x00007f4a43d1c448>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplate:0x00007fdf34ed9d90>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplate:0x00007fee6c78aa20>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplateAccess:0x00007f37d68c0b58>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplateAccess:0x00007f4a4ae00010>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplateAccess:0x00007fdf45ad4c48>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplateAccess:0x00007fee7038e120>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to destroy AdminSet: 2132c8ed-856c-4771-994f-282c496d9150
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to destroy Hyrax::AdministrativeSet: 497eb04a-2b61-4268-a741-91b1fe06e111
…
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplate:0x00007f370d333d58>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplate:0x00007fa271dec590>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplate:0x00007faee447d340>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplate:0x00007ff7adfb3c20>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplateAccess:0x00007f370d59b910>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplateAccess:0x00007fa281ef0b48>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplateAccess:0x00007faee8e6be20>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to create #<Hyrax::PermissionTemplateAccess:0x00007ff7bab6a008>
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to destroy AdminSet: c0a29e55-2d0f-4e80-b27b-8d2853ef1c63
spec.abilities.ability_spec ‑ Hyrax::Ability AdminSets and PermissionTemplates a user without edit access is expected not to be able to destroy Hyrax::AdministrativeSet: 00b3fb11-df4f-4995-b4f0-e9654f2927b1
…

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.

1 participant