diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /lib/api/helpers.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r-- | lib/api/helpers.rb | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 147d8407142..6fe25471289 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -271,6 +271,10 @@ module API authorize! :read_build, user_project end + def authorize_read_build_trace!(build) + authorize! :read_build_trace, build + end + def authorize_destroy_artifacts! authorize! :destroy_artifacts, user_project end @@ -318,7 +322,7 @@ module API # keys (required) - A hash consisting of keys that must be present def required_attributes!(keys) keys.each do |key| - bad_request!(key) unless params[key].present? + bad_request_missing_attribute!(key) unless params[key].present? end end @@ -364,12 +368,16 @@ module API render_api_error!(message.join(' '), 403) end - def bad_request!(attribute) - message = ["400 (Bad request)"] - message << "\"" + attribute.to_s + "\" not given" if attribute + def bad_request!(reason = nil) + message = ['400 Bad request'] + message << "- #{reason}" if reason render_api_error!(message.join(' '), 400) end + def bad_request_missing_attribute!(attribute) + bad_request!("\"#{attribute}\" not given") + end + def not_found!(resource = nil) message = ["404"] message << resource if resource @@ -536,13 +544,23 @@ module API ) end + def increment_counter(event_name) + feature_name = "usage_data_#{event_name}" + return unless Feature.enabled?(feature_name) + + Gitlab::UsageDataCounters.count(event_name) + rescue => error + Gitlab::AppLogger.warn("Redis tracking event failed for event: #{event_name}, message: #{error.message}") + end + # @param event_name [String] the event name # @param values [Array|String] the values counted def increment_unique_values(event_name, values) return unless values.present? - feature_name = "usage_data_#{event_name}" - return unless Feature.enabled?(feature_name) + feature_flag = "usage_data_#{event_name}" + + return unless Feature.enabled?(feature_flag, default_enabled: true) Gitlab::UsageDataCounters::HLLRedisCounter.track_event(values, event_name) rescue => error |