X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/1ea2dbfc7fd6466a98cf8f239a6bea9b4947ef57..aeb966ee09166bf074ea19a4a2dd5045ca795a98:/services/api/app/controllers/application_controller.rb diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb index 71176056fa..7a9b7a67e5 100644 --- a/services/api/app/controllers/application_controller.rb +++ b/services/api/app/controllers/application_controller.rb @@ -78,14 +78,21 @@ class ApplicationController < ActionController::Base @distinct = nil @response_resource_name = nil @attrs = nil + @extra_included = nil end def default_url_options + options = {} if Rails.configuration.host - {:host => Rails.configuration.host} - else - {} + options[:host] = Rails.configuration.host + end + if Rails.configuration.port + options[:port] = Rails.configuration.port end + if Rails.configuration.protocol + options[:protocol] = Rails.configuration.protocol + end + options end def index @@ -157,6 +164,10 @@ class ApplicationController < ActionController::Base send_error("Path not found", status: 404) end + def render_accepted + send_json ({accepted: true}), status: 202 + end + protected def send_error(*args) @@ -182,7 +193,10 @@ class ApplicationController < ActionController::Base end def find_objects_for_index - @objects ||= model_class.readable_by(*@read_users, {:include_trash => (params[:include_trash] || 'untrash' == action_name)}) + @objects ||= model_class.readable_by(*@read_users, { + :include_trash => (params[:include_trash] || 'untrash' == action_name), + :include_old_versions => params[:include_old_versions] + }) apply_where_limit_order_params end @@ -337,13 +351,20 @@ class ApplicationController < ActionController::Base # If there are too many reader tokens, assume the request is malicious # and ignore it. if request.get? and params[:reader_tokens] and - params[:reader_tokens].size < 100 + params[:reader_tokens].size < 100 + secrets = params[:reader_tokens].map { |t| + if t.is_a? String and t.starts_with? "v2/" + t.split("/")[2] + else + t + end + } @read_auths += ApiClientAuthorization .includes(:user) .where('api_token IN (?) AND (expires_at IS NULL OR expires_at > CURRENT_TIMESTAMP)', - params[:reader_tokens]) - .all + secrets) + .to_a end @read_auths.select! { |auth| auth.scopes_allow_request? request } @read_users = @read_auths.map(&:user).uniq @@ -494,12 +515,15 @@ class ApplicationController < ActionController::Base :limit => @limit, :items => @objects.as_api_response(nil, {select: @select}) } + if @extra_included + list[:included] = @extra_included.as_api_response(nil, {select: @select}) + end case params[:count] when nil, '', 'exact' if @objects.respond_to? :except list[:items_available] = @objects. except(:limit).except(:offset). - count(:id, distinct: true) + distinct.count(:id) end when 'none' else @@ -553,7 +577,13 @@ class ApplicationController < ActionController::Base location: "query", required: false, default: false - } + }, + cluster_id: { + type: 'string', + description: "Create object on a remote federated cluster instead of the current one.", + location: "query", + required: false, + }, } end @@ -571,6 +601,12 @@ class ApplicationController < ActionController::Base limit: { type: 'integer', required: false, default: DEFAULT_LIMIT }, offset: { type: 'integer', required: false, default: 0 }, count: { type: 'string', required: false, default: 'exact' }, + cluster_id: { + type: 'string', + description: "List objects on a remote federated cluster instead of the current one.", + location: "query", + required: false, + }, } end