Skip to content

Commit

Permalink
Update webauth controller for versioned file
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-collier committed Aug 2, 2024
1 parent 19986bb commit 98ccf69
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app/controllers/webauth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions spec/controllers/webauth_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 98ccf69

Please sign in to comment.