diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 08:43:02 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 08:43:02 +0000 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /app/controllers/application_controller.rb | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) | |
download | gitlab-ce-d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb.tar.gz |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r-- | app/controllers/application_controller.rb | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a83458f3260..b22167a3952 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -21,7 +21,7 @@ class ApplicationController < ActionController::Base include Impersonation include Gitlab::Logging::CloudflareHelper include Gitlab::Utils::StrongMemoize - include ::Gitlab::WithFeatureCategory + include ::Gitlab::EndpointAttributes include FlocOptOut before_action :authenticate_user!, except: [:route_not_found] @@ -70,6 +70,10 @@ class ApplicationController < ActionController::Base # concerns due to caching private data. DEFAULT_GITLAB_CACHE_CONTROL = "#{ActionDispatch::Http::Cache::Response::DEFAULT_CACHE_CONTROL}, no-store" + def self.endpoint_id_for_action(action_name) + "#{self.name}##{action_name}" + end + rescue_from Encoding::CompatibilityError do |exception| log_exception(exception) render "errors/encoding", layout: "errors", status: :internal_server_error @@ -104,6 +108,12 @@ class ApplicationController < ActionController::Base head :forbidden, retry_after: Gitlab::Auth::UniqueIpsLimiter.config.unique_ips_limit_time_window end + rescue_from RateLimitedService::RateLimitedError do |e| + e.log_request(request, current_user) + response.headers.merge!(e.headers) + render plain: e.message, status: :too_many_requests + end + def redirect_back_or_default(default: root_path, options: {}) redirect_back(fallback_location: default, **options) end @@ -131,6 +141,14 @@ class ApplicationController < ActionController::Base end end + def feature_category + self.class.feature_category_for_action(action_name).to_s + end + + def urgency + self.class.urgency_for_action(action_name) + end + protected def workhorse_excluded_content_types @@ -457,7 +475,7 @@ class ApplicationController < ActionController::Base user: -> { context_user }, project: -> { @project if @project&.persisted? }, namespace: -> { @group if @group&.persisted? }, - caller_id: caller_id, + caller_id: self.class.endpoint_id_for_action(action_name), remote_ip: request.ip, feature_category: feature_category ) @@ -543,14 +561,6 @@ class ApplicationController < ActionController::Base auth_user if strong_memoized?(:auth_user) end - def caller_id - "#{self.class.name}##{action_name}" - end - - def feature_category - self.class.feature_category_for_action(action_name).to_s - end - def required_signup_info return unless current_user return unless current_user.role_required? |