diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-07 03:09:26 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-04-07 03:09:26 +0300 |
commit | 418a39f6c20ebaf9572c4ef3ae924b0c6ffc5e3b (patch) | |
tree | c4ae73eee4e0a2ba535e87893858d9e76778d09d /lib/gitlab | |
parent | 2633d5ef5ed868eccb174c6ff644a3fb8224f990 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/downtime_check.rb | 73 | ||||
-rw-r--r-- | lib/gitlab/downtime_check/message.rb | 41 | ||||
-rw-r--r-- | lib/gitlab/graphql/authorize/object_authorization.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/pagination/keyset/order.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/quick_actions/issue_and_merge_request_actions.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/usage_data_counters/quick_action_activity_unique_counter.rb | 2 |
6 files changed, 6 insertions, 119 deletions
diff --git a/lib/gitlab/downtime_check.rb b/lib/gitlab/downtime_check.rb deleted file mode 100644 index 457a3c12206..00000000000 --- a/lib/gitlab/downtime_check.rb +++ /dev/null @@ -1,73 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - # Checks if a set of migrations requires downtime or not. - class DowntimeCheck - # The constant containing the boolean that indicates if downtime is needed - # or not. - DOWNTIME_CONST = :DOWNTIME - - # The constant that specifies the reason for the migration requiring - # downtime. - DOWNTIME_REASON_CONST = :DOWNTIME_REASON - - # Checks the given migration paths and returns an Array of - # `Gitlab::DowntimeCheck::Message` instances. - # - # migrations - The migration file paths to check. - def check(migrations) - migrations.map do |path| - require(path) - - migration_class = class_for_migration_file(path) - - unless migration_class.const_defined?(DOWNTIME_CONST) - raise "The migration in #{path} does not specify if it requires " \ - "downtime or not" - end - - if online?(migration_class) - Message.new(path) - else - reason = downtime_reason(migration_class) - - unless reason - raise "The migration in #{path} requires downtime but no reason " \ - "was given" - end - - Message.new(path, true, reason) - end - end - end - - # Checks the given migrations and prints the results to STDOUT/STDERR. - # - # migrations - The migration file paths to check. - def check_and_print(migrations) - check(migrations).each do |message| - puts message.to_s # rubocop: disable Rails/Output - end - end - - # Returns the class for the given migration file path. - def class_for_migration_file(path) - File.basename(path, File.extname(path)).split('_', 2).last.camelize - .constantize - end - - # Returns true if the given migration can be performed without downtime. - def online?(migration) - migration.const_get(DOWNTIME_CONST, false) == false - end - - # Returns the downtime reason, or nil if none was defined. - def downtime_reason(migration) - if migration.const_defined?(DOWNTIME_REASON_CONST) - migration.const_get(DOWNTIME_REASON_CONST, false) - else - nil - end - end - end -end diff --git a/lib/gitlab/downtime_check/message.rb b/lib/gitlab/downtime_check/message.rb deleted file mode 100644 index 5debb754943..00000000000 --- a/lib/gitlab/downtime_check/message.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - class DowntimeCheck - class Message - attr_reader :path, :offline - - OFFLINE = "\e[31moffline\e[0m" - ONLINE = "\e[32monline\e[0m" - - # path - The file path of the migration. - # offline - When set to `true` the migration will require downtime. - # reason - The reason as to why the migration requires downtime. - def initialize(path, offline = false, reason = nil) - @path = path - @offline = offline - @reason = reason - end - - def to_s - label = offline ? OFFLINE : ONLINE - - message = ["[#{label}]: #{path}"] - - if reason? - message << ":\n\n#{reason}\n\n" - end - - message.join - end - - def reason? - @reason.present? - end - - def reason - @reason.strip.lines.map(&:strip).join("\n") - end - end - end -end diff --git a/lib/gitlab/graphql/authorize/object_authorization.rb b/lib/gitlab/graphql/authorize/object_authorization.rb index 5f6c266fd61..0bc87108871 100644 --- a/lib/gitlab/graphql/authorize/object_authorization.rb +++ b/lib/gitlab/graphql/authorize/object_authorization.rb @@ -21,8 +21,9 @@ module Gitlab def ok?(object, current_user) return true if none? + subject = object.try(:declarative_policy_subject) || object abilities.all? do |ability| - Ability.allowed?(current_user, ability, object) + Ability.allowed?(current_user, ability, subject) end end end diff --git a/lib/gitlab/pagination/keyset/order.rb b/lib/gitlab/pagination/keyset/order.rb index bfb15320b57..e596e1bac9d 100644 --- a/lib/gitlab/pagination/keyset/order.rb +++ b/lib/gitlab/pagination/keyset/order.rb @@ -93,7 +93,7 @@ module Gitlab end def cursor_attributes_for_node(node) - column_definitions.each_with_object({}) do |column_definition, hash| + column_definitions.each_with_object({}.with_indifferent_access) do |column_definition, hash| field_value = node[column_definition.attribute_name] hash[column_definition.attribute_name] = if field_value.is_a?(Time) field_value.strftime('%Y-%m-%d %H:%M:%S.%N %Z') @@ -162,7 +162,7 @@ module Gitlab # rubocop: disable CodeReuse/ActiveRecord def apply_cursor_conditions(scope, values = {}) scope = apply_custom_projections(scope) - scope.where(build_where_values(values)) + scope.where(build_where_values(values.with_indifferent_access)) end # rubocop: enable CodeReuse/ActiveRecord diff --git a/lib/gitlab/quick_actions/issue_and_merge_request_actions.rb b/lib/gitlab/quick_actions/issue_and_merge_request_actions.rb index 4934c12a339..b7d58e05651 100644 --- a/lib/gitlab/quick_actions/issue_and_merge_request_actions.rb +++ b/lib/gitlab/quick_actions/issue_and_merge_request_actions.rb @@ -182,7 +182,7 @@ module Gitlab parse_params do |raw_time_date| Gitlab::QuickActions::SpendTimeAndDateSeparator.new(raw_time_date).execute end - command :spend do |time_spent, time_spent_date| + command :spend, :spent do |time_spent, time_spent_date| if time_spent @updates[:spend_time] = { duration: time_spent, diff --git a/lib/gitlab/usage_data_counters/quick_action_activity_unique_counter.rb b/lib/gitlab/usage_data_counters/quick_action_activity_unique_counter.rb index 15c68fb3945..ed3df7dcf75 100644 --- a/lib/gitlab/usage_data_counters/quick_action_activity_unique_counter.rb +++ b/lib/gitlab/usage_data_counters/quick_action_activity_unique_counter.rb @@ -28,7 +28,7 @@ module Gitlab 'unassign_reviewer' when 'request_review', 'reviewer' 'assign_reviewer' - when 'spend' + when 'spend', 'spent' event_name_for_spend(args) when 'unassign' event_name_for_unassign(args) |