-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from scientist-softserv/limit-importer-export…
…er-by-user Limit importers and exporters by user
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
|
||
# Override Bulkrax main (at v5.3.0) to limit access to only user's own exporters | ||
module Bulkrax | ||
module ExportersControllerDecorator | ||
def index | ||
# NOTE: We're paginating this in the browser. | ||
@exporters = Exporter.order(created_at: :desc) | ||
@exporters = @exporters.where(user: current_user) unless current_ability.admin? | ||
@exporters = @exporters.all | ||
|
||
add_exporter_breadcrumbs if defined?(::Hyrax) | ||
end | ||
|
||
private | ||
|
||
def check_permissions | ||
raise CanCan::AccessDenied unless current_ability.can_export_works? | ||
return true if current_ability.admin? | ||
return true unless params.key?(:id) | ||
return true if Importer.where(id: params[:id], user: current_user).exists? | ||
raise CanCan::AccessDenied | ||
end | ||
end | ||
end | ||
|
||
Bulkrax::ExportersController.prepend(Bulkrax::ExportersControllerDecorator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
# Override Bulkrax main (at v5.3.0) to limit access to only user's own importers | ||
module Bulkrax | ||
module ImportersControllerDecorator | ||
# GET /importers | ||
def index | ||
# NOTE: We're paginating this in the browser. | ||
@importers = Importer.order(created_at: :desc) | ||
@importers = @importers.where(user: current_user) unless current_ability.admin? | ||
@importers = @importers.all | ||
|
||
if api_request? | ||
json_response('index') | ||
elsif defined?(::Hyrax) | ||
add_importer_breadcrumbs | ||
end | ||
end | ||
|
||
private | ||
|
||
def check_permissions | ||
raise CanCan::AccessDenied unless current_ability.can_import_works? | ||
return true if current_ability.admin? | ||
return true unless params.key?(:id) | ||
return true if Importer.where(id: params[:id], user: current_user).exists? | ||
raise CanCan::AccessDenied | ||
end | ||
end | ||
end | ||
|
||
Bulkrax::ImportersController.prepend(Bulkrax::ImportersControllerDecorator) |