Commit ef4a021f authored by Jan Provaznik's avatar Jan Provaznik

Merge branch '119208-limit-metric-type-on-list-pd' into 'master'

Add limit metric to list

See merge request gitlab-org/gitlab!25532
parents f996f939 3c1652f3
---
title: Add limit metric to lists
merge_request: 25532
author:
type: added
# frozen_string_literal: true
class AddLimitMetricTypeToList < ActiveRecord::Migration[6.0]
DOWNTIME = false
def change
add_column :lists, :limit_metric, :string, limit: 20
end
end
...@@ -2425,6 +2425,7 @@ ActiveRecord::Schema.define(version: 2020_03_13_123934) do ...@@ -2425,6 +2425,7 @@ ActiveRecord::Schema.define(version: 2020_03_13_123934) do
t.integer "milestone_id" t.integer "milestone_id"
t.integer "max_issue_count", default: 0, null: false t.integer "max_issue_count", default: 0, null: false
t.integer "max_issue_weight", default: 0, null: false t.integer "max_issue_weight", default: 0, null: false
t.string "limit_metric", limit: 20
t.index ["board_id", "label_id"], name: "index_lists_on_board_id_and_label_id", unique: true t.index ["board_id", "label_id"], name: "index_lists_on_board_id_and_label_id", unique: true
t.index ["label_id"], name: "index_lists_on_label_id" t.index ["label_id"], name: "index_lists_on_label_id"
t.index ["list_type"], name: "index_lists_on_list_type" t.index ["list_type"], name: "index_lists_on_list_type"
......
...@@ -9,7 +9,7 @@ module EE ...@@ -9,7 +9,7 @@ module EE
before_action :push_wip_limits before_action :push_wip_limits
end end
EE_MAX_LIMITS_PARAMS = %i[max_issue_count max_issue_weight].freeze EE_MAX_LIMITS_PARAMS = %i[max_issue_count max_issue_weight limit_metric].freeze
override :list_creation_attrs override :list_creation_attrs
def list_creation_attrs def list_creation_attrs
......
...@@ -6,6 +6,8 @@ module EE ...@@ -6,6 +6,8 @@ module EE
include ::Gitlab::Utils::StrongMemoize include ::Gitlab::Utils::StrongMemoize
LIMIT_METRIC_TYPES = %w[all_metrics issue_count issue_weights].freeze
# ActiveSupport::Concern does not prepend the ClassMethods, # ActiveSupport::Concern does not prepend the ClassMethods,
# so we cannot call `super` if we use it. # so we cannot call `super` if we use it.
def self.prepended(base) def self.prepended(base)
...@@ -24,6 +26,11 @@ module EE ...@@ -24,6 +26,11 @@ module EE
base.validates :milestone_id, uniqueness: { scope: :board_id }, if: :milestone? base.validates :milestone_id, uniqueness: { scope: :board_id }, if: :milestone?
base.validates :max_issue_count, numericality: { only_integer: true, greater_than_or_equal_to: 0 } base.validates :max_issue_count, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
base.validates :max_issue_weight, numericality: { only_integer: true, greater_than_or_equal_to: 0 } base.validates :max_issue_weight, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
base.validates :limit_metric, inclusion: {
in: LIMIT_METRIC_TYPES,
allow_blank: true,
allow_nil: true
}
base.validates :list_type, base.validates :list_type,
exclusion: { in: %w[assignee], message: _('Assignee lists not available with your current license') }, exclusion: { in: %w[assignee], message: _('Assignee lists not available with your current license') },
unless: -> { board&.resource_parent&.feature_available?(:board_assignee_lists) } unless: -> { board&.resource_parent&.feature_available?(:board_assignee_lists) }
......
...@@ -37,13 +37,13 @@ module EE ...@@ -37,13 +37,13 @@ module EE
override :create_list_attributes override :create_list_attributes
def create_list_attributes(type, target, position) def create_list_attributes(type, target, position)
max_issue_count, max_issue_weight = if wip_limits_available? return super unless wip_limits_available?
[max_issue_count_by_params, max_issue_weight_by_params]
else
[0, 0]
end
super.merge(max_issue_count: max_issue_count, max_issue_weight: max_issue_weight) super.merge(
max_issue_count: max_issue_count_by_params,
max_issue_weight: max_issue_weight_by_params,
limit_metric: limit_metric_by_params
)
end end
private private
...@@ -71,6 +71,10 @@ module EE ...@@ -71,6 +71,10 @@ module EE
def wip_limits_available? def wip_limits_available?
parent.feature_available?(:wip_limits) parent.feature_available?(:wip_limits)
end end
def limit_metric_by_params
params[:limit_metric]
end
end end
end end
end end
......
...@@ -18,13 +18,25 @@ module EE ...@@ -18,13 +18,25 @@ module EE
end end
def update_max_limits(list) def update_max_limits(list)
return unless max_limits_update_possible?(list) return unless list.wip_limits_available? && can_admin?(list)
list.update(list_max_limit_attributes_by_params) attrs = max_limit_settings_by_params
list.update(attrs) unless attrs.empty?
end end
def max_limits_update_possible?(list) def max_limit_settings_by_params
max_limits_provided? && list.wip_limits_available? && can_admin?(list) {}.tap do |attrs|
attrs.merge!(list_max_limit_attributes_by_params) if max_limits_provided?
attrs.merge!(limit_metric_by_params) if limit_metric_provided?
end
end
def limit_metric_by_params
{ limit_metric: params[:limit_metric] }
end
def limit_metric_provided?
params.key?(:limit_metric)
end end
end end
end end
......
...@@ -13,6 +13,7 @@ describe List do ...@@ -13,6 +13,7 @@ describe List do
describe 'validations' do describe 'validations' do
it { is_expected.to validate_numericality_of(:max_issue_count).only_integer.is_greater_than_or_equal_to(0) } it { is_expected.to validate_numericality_of(:max_issue_count).only_integer.is_greater_than_or_equal_to(0) }
it { is_expected.to validate_numericality_of(:max_issue_weight).only_integer.is_greater_than_or_equal_to(0) } it { is_expected.to validate_numericality_of(:max_issue_weight).only_integer.is_greater_than_or_equal_to(0) }
it { is_expected.to validate_inclusion_of(:limit_metric).in_array([nil, *EE::List::LIMIT_METRIC_TYPES]) }
end end
context 'when it is an assignee type' do context 'when it is an assignee type' do
......
...@@ -55,24 +55,30 @@ describe Boards::Lists::CreateService do ...@@ -55,24 +55,30 @@ describe Boards::Lists::CreateService do
stub_feature_flags(wip_limits: wip_limits_enabled) stub_feature_flags(wip_limits: wip_limits_enabled)
end end
where(:params, :expected_max_issue_count, :expected_max_issue_weight) do where(:params, :expected_max_issue_count, :expected_max_issue_weight, :expected_limit_metric) do
[ [
[{ max_issue_count: 0 }, 0, 0], [{ max_issue_count: 0 }, 0, 0, nil],
[{ max_issue_count: nil }, 0, 0], [{ max_issue_count: nil }, 0, 0, nil],
[{ max_issue_count: 1 }, 1, 0], [{ max_issue_count: 1 }, 1, 0, nil],
[{ max_issue_weight: 0 }, 0, 0], [{ max_issue_weight: 0 }, 0, 0, nil],
[{ max_issue_weight: nil }, 0, 0], [{ max_issue_weight: nil }, 0, 0, nil],
[{ max_issue_weight: 1 }, 0, 1], [{ max_issue_weight: 1 }, 0, 1, nil],
[{ max_issue_count: 1, max_issue_weight: 0 }, 1, 0], [{ max_issue_count: 1, max_issue_weight: 0 }, 1, 0, nil],
[{ max_issue_count: 0, max_issue_weight: 1 }, 0, 1], [{ max_issue_count: 0, max_issue_weight: 1 }, 0, 1, nil],
[{ max_issue_count: 1, max_issue_weight: 1 }, 1, 1], [{ max_issue_count: 1, max_issue_weight: 1 }, 1, 1, nil],
[{ max_issue_count: nil, max_issue_weight: 1 }, 0, 1], [{ max_issue_count: nil, max_issue_weight: 1 }, 0, 1, nil],
[{ max_issue_count: 1, max_issue_weight: nil }, 1, 0], [{ max_issue_count: 1, max_issue_weight: nil }, 1, 0, nil],
[{ max_issue_count: nil, max_issue_weight: nil }, 0, 0] [{ max_issue_count: nil, max_issue_weight: nil }, 0, 0, nil],
[{ limit_metric: 'all_metrics' }, 0, 0, 'all_metrics'],
[{ limit_metric: 'issue_count' }, 0, 0, 'issue_count'],
[{ limit_metric: 'issue_weights' }, 0, 0, 'issue_weights'],
[{ limit_metric: '' }, 0, 0, ''],
[{ limit_metric: nil }, 0, 0, nil]
] ]
end end
...@@ -83,9 +89,11 @@ describe Boards::Lists::CreateService do ...@@ -83,9 +89,11 @@ describe Boards::Lists::CreateService do
attrs = service.create_list_attributes(nil, nil, nil) attrs = service.create_list_attributes(nil, nil, nil)
if wip_limits_enabled if wip_limits_enabled
expect(attrs).to include(max_issue_count: expected_max_issue_count, max_issue_weight: expected_max_issue_weight) expect(attrs).to include(max_issue_count: expected_max_issue_count,
max_issue_weight: expected_max_issue_weight,
limit_metric: expected_limit_metric)
else else
expect(attrs).to include(max_issue_count: 0, max_issue_weight: 0) expect(attrs).not_to include(max_issue_count: 0, max_issue_weight: 0, limit_metric: nil)
end end
end end
end end
......
...@@ -7,6 +7,7 @@ FactoryBot.define do ...@@ -7,6 +7,7 @@ FactoryBot.define do
list_type { :label } list_type { :label }
max_issue_count { 0 } max_issue_count { 0 }
max_issue_weight { 0 } max_issue_weight { 0 }
limit_metric { nil }
sequence(:position) sequence(:position)
end end
......
...@@ -37,7 +37,8 @@ ...@@ -37,7 +37,8 @@
"title": { "type": "string" }, "title": { "type": "string" },
"position": { "type": ["integer", "null"] }, "position": { "type": ["integer", "null"] },
"max_issue_count": { "type": "integer" }, "max_issue_count": { "type": "integer" },
"max_issue_weight": { "type": "integer" } "max_issue_weight": { "type": "integer" },
"limit_metric": { "type": ["string", "null"] }
}, },
"additionalProperties": true "additionalProperties": true
} }
...@@ -764,6 +764,7 @@ List: ...@@ -764,6 +764,7 @@ List:
- user_id - user_id
- max_issue_count - max_issue_count
- max_issue_weight - max_issue_weight
- limit_metric
ExternalPullRequest: ExternalPullRequest:
- id - id
- created_at - created_at
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment