diff --git a/app/controllers/webauth_controller.rb b/app/controllers/webauth_controller.rb index d8ac0d8d..1ceb05cc 100644 --- a/app/controllers/webauth_controller.rb +++ b/app/controllers/webauth_controller.rb @@ -29,7 +29,11 @@ def logout # TODO: we may want one method for all the below, with a referer param to know where to redirect def login_file - redirect_to file_path(params.to_unsafe_h.symbolize_keys) + if params[:version_id] + redirect_to versioned_file_path(params.to_unsafe_h.symbolize_keys) + else + redirect_to file_path(params.to_unsafe_h.symbolize_keys) + end end # For zip files diff --git a/config/routes.rb b/config/routes.rb index ff276eb6..6dccdb93 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,7 +6,7 @@ constraints id: druid_regex do get '/file/:id/*file_name' => 'file#show', format: false, as: :file - get '/v2/file/:id/:version_id/*file_name', to: 'file#show', format: false, constraints: { version_id: /v\d+/ } + get '/v2/file/:id/:version_id/*file_name', to: 'file#show', format: false, as: :versioned_file, constraints: { version_id: /v\d+/ } options '/file/:id/*file_name', to: 'file#options', format: false options '/v2/file/:id/:version_id/*file_name', to: 'file#options', format: false, constraints: { version_id: /v\d+/ } get '/file/app/:id/*file_name' => 'webauth#login_file', format: false diff --git a/spec/controllers/webauth_controller_spec.rb b/spec/controllers/webauth_controller_spec.rb index 358b2591..632eae09 100644 --- a/spec/controllers/webauth_controller_spec.rb +++ b/spec/controllers/webauth_controller_spec.rb @@ -22,8 +22,18 @@ subject { get :login_file, params: } let(:params) { { id: 'xf680rd3068', file_name: 'xf680rd3068_1.jp2' } } - it 'returns the user to the file api' do - expect(subject).to redirect_to file_url(params) + context 'without a version specified' do + it 'returns the user to the file api' do + expect(subject).to redirect_to file_url(params) + end + end + + context 'with version specified' do + let(:params) { { id: 'xf680rd3068', file_name: 'xf680rd3068_1.jp2', version_id: 'v1' } } + + it 'returns the user to the versioned file api' do + expect(subject).to redirect_to versioned_file_url(params) + end end it 'stores user information in the session' do