Skip to content

Add Bulkrax::Ability concern and enforce importer/exporter ownership#1186

Open
orangewolf wants to merge 6 commits into
mainfrom
importer-exorter-permissions
Open

Add Bulkrax::Ability concern and enforce importer/exporter ownership#1186
orangewolf wants to merge 6 commits into
mainfrom
importer-exorter-permissions

Conversation

@orangewolf

Copy link
Copy Markdown
Member

Introduces a shared Bulkrax::Ability concern so all Bulkrax authorization methods live in one place, and adds per-record ownership enforcement so users can only access importers/exporters they own (or admin all records via new can_admin_importers?/can_admin_exporters? methods).

  • Add app/models/concerns/bulkrax/ability.rb with default implementations of can_import_works?, can_export_works?, can_admin_importers?, and can_admin_exporters? (all safe/conservative defaults)
  • Add accessible_importers, accessible_exporters, and item_accessible? helpers to ApplicationController; admin users see all records, others see only their own
  • Scope importer_table, set_importer, continue, upload_corrected_entries, upload_corrected_entries_file, and export_errors to accessible_importers; API requests bypass the ownership scope to preserve existing API behavior
  • Scope exporter_table, set_exporter, and download to accessible_exporters
  • Check item_accessible? in entries_controller update/destroy and when loading parent importer/exporter in show actions
  • Guard edit/delete action links in datatables_behavior so they only appear for owners and admins; scope recordsTotal/recordsFiltered counts to accessible records
  • Update install_generator to include Bulkrax::Ability instead of injecting raw method definitions; add commented override examples
  • Update test app Ability to include Bulkrax::Ability
  • Add spec/models/concerns/bulkrax/ability_spec.rb for new concern
  • Add ownership enforcement specs to importers and exporters controller specs (non-owner denied, owner allowed, admin allowed)
  • Fix export_errors and datatables specs to account for ownership scoping

orangewolf and others added 2 commits April 10, 2026 21:56
Introduces a shared Bulkrax::Ability concern so all Bulkrax authorization
methods live in one place, and adds per-record ownership enforcement so
users can only access importers/exporters they own (or admin all records
via new can_admin_importers?/can_admin_exporters? methods).

- Add app/models/concerns/bulkrax/ability.rb with default implementations
  of can_import_works?, can_export_works?, can_admin_importers?, and
  can_admin_exporters? (all safe/conservative defaults)
- Add accessible_importers, accessible_exporters, and item_accessible?
  helpers to ApplicationController; admin users see all records, others
  see only their own
- Scope importer_table, set_importer, continue, upload_corrected_entries,
  upload_corrected_entries_file, and export_errors to accessible_importers;
  API requests bypass the ownership scope to preserve existing API behavior
- Scope exporter_table, set_exporter, and download to accessible_exporters
- Check item_accessible? in entries_controller update/destroy and when
  loading parent importer/exporter in show actions
- Guard edit/delete action links in datatables_behavior so they only
  appear for owners and admins; scope recordsTotal/recordsFiltered counts
  to accessible records
- Update install_generator to include Bulkrax::Ability instead of
  injecting raw method definitions; add commented override examples
- Update test app Ability to include Bulkrax::Ability
- Add spec/models/concerns/bulkrax/ability_spec.rb for new concern
- Add ownership enforcement specs to importers and exporters controller
  specs (non-owner denied, owner allowed, admin allowed)
- Fix export_errors and datatables specs to account for ownership scoping

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@orangewolf orangewolf added the breaking-change for release notes label Apr 28, 2026
@orangewolf orangewolf added major-ver for release notes breaking-change for release notes and removed breaking-change for release notes labels Apr 28, 2026
@orangewolf
orangewolf marked this pull request as ready for review April 28, 2026 16:00

@laritakr laritakr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks great. I saw a few places referring to the API token work... would be ideal to update to reference an actual ticket.

# NOTE: We're paginating this in the browser.
if api_request?
# TODO: Scope API index by token owner once token-to-user wiring is in
# place. Tracked in [ISSUE]. Until then, API clients see all importers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we have an actual issue to link here for tracking?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change for release notes major-ver for release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants