X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6e5079ff9a0349c57ab2cf06398413018a921cc0..17cde5d1333ae88e9eaf4739e5deaac458a523ec:/apps/workbench/app/controllers/application_controller.rb diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb index 0a40f58f21..21e9b49fd8 100644 --- a/apps/workbench/app/controllers/application_controller.rb +++ b/apps/workbench/app/controllers/application_controller.rb @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + class ApplicationController < ActionController::Base include ArvadosApiClientHelper include ApplicationHelper @@ -7,19 +11,19 @@ class ApplicationController < ActionController::Base ERROR_ACTIONS = [:render_error, :render_not_found] - prepend_before_filter :set_current_request_id, except: ERROR_ACTIONS - around_filter :thread_clear - around_filter :set_thread_api_token + around_action :thread_clear + around_action :set_current_request_id + around_action :set_thread_api_token # Methods that don't require login should - # skip_around_filter :require_thread_api_token - around_filter :require_thread_api_token, except: ERROR_ACTIONS - before_filter :ensure_arvados_api_exists, only: [:index, :show] - before_filter :set_cache_buster - before_filter :accept_uuid_as_id_param, except: ERROR_ACTIONS - before_filter :check_user_agreements, except: ERROR_ACTIONS - before_filter :check_user_profile, except: ERROR_ACTIONS - before_filter :load_filters_and_paging_params, except: ERROR_ACTIONS - before_filter :find_object_by_uuid, except: [:create, :index, :choose] + ERROR_ACTIONS + # skip_around_action :require_thread_api_token + around_action :require_thread_api_token, except: ERROR_ACTIONS + before_action :ensure_arvados_api_exists, only: [:index, :show] + before_action :set_cache_buster + before_action :accept_uuid_as_id_param, except: ERROR_ACTIONS + before_action :check_user_agreements, except: ERROR_ACTIONS + before_action :check_user_profile, except: ERROR_ACTIONS + before_action :load_filters_and_paging_params, except: ERROR_ACTIONS + before_action :find_object_by_uuid, except: [:create, :index, :choose] + ERROR_ACTIONS theme :select_theme begin @@ -349,6 +353,9 @@ class ApplicationController < ActionController::Base def update @updates ||= params[@object.resource_param_name.to_sym] + if @updates.is_a? ActionController::Parameters + @updates = @updates.to_unsafe_hash + end @updates.keys.each do |attr| if @object.send(attr).is_a? Hash if @updates[attr].is_a? String @@ -357,6 +364,9 @@ class ApplicationController < ActionController::Base if params[:merge] || params["merge_#{attr}".to_sym] # Merge provided Hash with current Hash, instead of # replacing. + if @updates[attr].is_a? ActionController::Parameters + @updates[attr] = @updates[attr].to_unsafe_hash + end @updates[attr] = @object.send(attr).with_indifferent_access. deep_merge(@updates[attr].with_indifferent_access) end @@ -569,6 +579,19 @@ class ApplicationController < ActionController::Base Rails.cache.delete_matched(/^request_#{Thread.current.object_id}_/) end + def set_current_request_id + response.headers['X-Request-Id'] = + Thread.current[:request_id] = + "req-" + Random::DEFAULT.rand(2**128).to_s(36)[0..19] + yield + Thread.current[:request_id] = nil + end + + def append_info_to_payload(payload) + super + payload[:request_id] = response.headers['X-Request-Id'] + end + # Set up the thread with the given API token and associated user object. def load_api_token(new_token) Thread.current[:arvados_api_token] = new_token @@ -1303,10 +1326,4 @@ class ApplicationController < ActionController::Base def wiselinks_layout 'body' end - - def set_current_request_id - # Request ID format: '-<9_digits_random_number>' - current_request_id = "#{Time.new.to_i}-#{sprintf('%09d', rand(0..10**9-1))}" - Thread.current[:current_request_id] = current_request_id - end end