X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/682dd5b6cc23a455766a7651e3e841257660b31c..bf159738719badbbe1e08ee4f839027892912ab2:/apps/workbench/app/controllers/collections_controller.rb diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb index 0610fd2e81..38b58a1650 100644 --- a/apps/workbench/app/controllers/collections_controller.rb +++ b/apps/workbench/app/controllers/collections_controller.rb @@ -1,4 +1,6 @@ require "arvados/keep" +require "uri" +require "cgi" class CollectionsController < ApplicationController include ActionController::Live @@ -119,18 +121,38 @@ class CollectionsController < ApplicationController # we ask the API server if the file actually exists. This serves two # purposes: it lets us return a useful status code for common errors, and # helps us figure out which token to provide to arv-get. + # The order of searched tokens is important: because the anonymous user + # token is passed along with every API request, we have to check it first. + # Otherwise, it's impossible to know whether any other request succeeded + # because of the reader token. coll = nil - tokens = [Thread.current[:arvados_api_token], + tokens = [(Rails.configuration.anonymous_user_token || nil), params[:reader_token], - (Rails.configuration.anonymous_user_token || nil)].compact + Thread.current[:arvados_api_token]].compact usable_token = find_usable_token(tokens) do coll = Collection.find(params[:uuid]) end + if usable_token.nil? + # Response already rendered. + return + end + + if Rails.configuration.keep_web_url + opts = {} + if usable_token == params[:reader_token] + opts[:path_token] = usable_token + elsif usable_token == Rails.configuration.anonymous_user_token + # Don't pass a token at all + else + # We pass the current user's real token only if it's necessary + # to read the collection. + opts[:query_token] = usable_token + end + return redirect_to keep_web_url(params[:uuid], params[:file], opts) + end file_name = params[:file].andand.sub(/^(\.\/|\/|)/, './') - if usable_token.nil? - return # Response already rendered. - elsif file_name.nil? or not coll.manifest.has_file?(file_name) + if file_name.nil? or not coll.manifest.has_file?(file_name) return render_not_found end @@ -269,15 +291,6 @@ class CollectionsController < ApplicationController sharing_popup end - def update - @updates ||= params[@object.resource_param_name.to_sym] - if @updates && (@updates.keys - ["name", "description"]).empty? - # exclude manifest_text since only name or description is being updated - @object.manifest_text = nil - end - super - end - protected def find_usable_token(token_list) @@ -310,6 +323,21 @@ class CollectionsController < ApplicationController return nil end + def keep_web_url(uuid_or_pdh, file, opts) + fmt = {uuid_or_pdh: uuid_or_pdh.sub('+', '-')} + uri = URI.parse(Rails.configuration.keep_web_url % fmt) + uri.path += '/' unless uri.path.end_with? '/' + if opts[:path_token] + uri.path += 't=' + opts[:path_token] + '/' + end + uri.path += '_/' + uri.path += CGI::escape(file) + if opts[:query_token] + uri.query = 'api_token=' + CGI::escape(opts[:query_token]) + end + uri.to_s + end + # Note: several controller and integration tests rely on stubbing # file_enumerator to return fake file content. def file_enumerator opts