Skip to content

Commit

Permalink
Copy file endpoint (#1382)
Browse files Browse the repository at this point in the history
The portal can send a message to a Bourreau to start a background process to copy files.
  • Loading branch information
natacha-beck authored Mar 7, 2024
1 parent 4e593c4 commit 7c68e84
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
24 changes: 23 additions & 1 deletion BrainPortal/app/controllers/bourreaux_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BourreauxController < ApplicationController
api_available :except => :row_data

before_action :login_required
before_action :manager_role_required, :except => [:index, :show, :row_data, :load_info, :rr_disk_usage, :cleanup_caches, :rr_access, :rr_access_dp, :update, :start, :stop]
before_action :manager_role_required, :except => [:index, :show, :row_data, :load_info, :rr_disk_usage, :cleanup_caches, :rr_access, :rr_access_dp, :update, :start, :stop, :file_copy]

def index #:nodoc:
@scope = scope_from_session
Expand Down Expand Up @@ -610,6 +610,28 @@ def rr_access_dp

end

# API method to copy files from one DP to another via a bourreau
def file_copy #:nodoc:
bourreau_id = params[:id]
userfile_ids = params[:userfile_ids]
data_provider_id = params[:dataprovider_id]

bourreau = Bourreau.find(bourreau_id)
data_provider = DataProvider.find(data_provider_id)

# Check if the user has access to the bourreau and the data provider
if !bourreau.can_be_accessed_by?(current_user) || !data_provider.can_be_accessed_by?(current_user)
render :json => { :error => "Access denied" }, :status => :forbidden
return
end

# Filter out userfile_ids that are not readable by the user
userfile_ids = Userfile.find_all_accessible_by_user(current_user, :access_requested => :read)
.where(:id => userfile_ids).pluck(:id)

bourreau.send_command_copy_files(userfile_ids, data_provider_id, current_user.id)
render :json => { :status => "ok", :file_copied_count => userfile_ids.size }
end

private

Expand Down
1 change: 1 addition & 0 deletions BrainPortal/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
member do
post 'start'
post 'stop'
post 'file_copy'
get 'row_data'
get 'info'
get 'cache_disk_usage'
Expand Down

0 comments on commit 7c68e84

Please sign in to comment.