-
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.
Limit importers and exporters by user
Refs - #123 Prior work limited the ability to view the importer and exporter pages by user role, but did not limit what importers and exporters could be seen. With this work, only admin users can see all importers and exporters, while other users can only see importers and exporters they have created.
- Loading branch information
Showing
2 changed files
with
65 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,30 @@ | ||
# 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 | ||
if 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 | ||
else | ||
raise CanCan::AccessDenied | ||
end | ||
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,35 @@ | ||
# 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 | ||
if 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 | ||
else | ||
raise CanCan::AccessDenied | ||
end | ||
end | ||
end | ||
end | ||
|
||
Bulkrax::ImportersController.prepend(Bulkrax::ImportersControllerDecorator) |