aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/imports_controller.rb8
-rw-r--r--config/routes.rb4
-rw-r--r--spec/controllers/imports_controller_spec.rb8
3 files changed, 19 insertions, 1 deletions
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb
index 3eab7e66b..9b2101584 100644
--- a/app/controllers/imports_controller.rb
+++ b/app/controllers/imports_controller.rb
@@ -21,6 +21,14 @@ class ImportsController < BreadcrumbController
end
end
+ def download
+ if params[:token] == resource.token_download
+ send_file resource.file.path
+ else
+ user_not_authorized
+ end
+ end
+
private
def import_params
diff --git a/config/routes.rb b/config/routes.rb
index 6e26cbd72..943acb5cb 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -3,7 +3,9 @@ require 'sidekiq/web'
ChouetteIhm::Application.routes.draw do
resources :workbenches, :only => [:show] do
delete :referentials, on: :member, action: :delete_referentials
- resources :imports
+ resources :imports do
+ get :download, on: :member
+ end
end
devise_for :users, :controllers => {
diff --git a/spec/controllers/imports_controller_spec.rb b/spec/controllers/imports_controller_spec.rb
index 19756b72f..bffb89338 100644
--- a/spec/controllers/imports_controller_spec.rb
+++ b/spec/controllers/imports_controller_spec.rb
@@ -4,6 +4,7 @@ RSpec.describe ImportsController, :type => :controller do
login_user
let(:workbench) { create :workbench }
+ let(:import) { create :import, workbench: workbench }
describe 'GET #new' do
it 'should be successful' do
@@ -11,4 +12,11 @@ RSpec.describe ImportsController, :type => :controller do
expect(response).to be_success
end
end
+
+ describe 'GET #download' do
+ it 'should be successful' do
+ get :download, workbench_id: workbench.id, id: import.id, token: import.token_download
+ expect(response).to be_success
+ end
+ end
end