diff --git a/ee/app/models/concerns/ee/issuable.rb b/ee/app/models/concerns/ee/issuable.rb index 4ee88b5a5a06a2160fffcfcebd5e9dd601a6254c..fdc8acd4c0cd91509994bc2ee1c97d5c5d9dd82c 100644 --- a/ee/app/models/concerns/ee/issuable.rb +++ b/ee/app/models/concerns/ee/issuable.rb @@ -18,7 +18,7 @@ def supports_weight? end def weight_available? - supports_weight? && project&.feature_available?(:issue_weights) + supports_weight? end def sla_available? diff --git a/ee/app/models/ee/issue.rb b/ee/app/models/ee/issue.rb index 20fc2d8907f4e6684999f0218812ee614f731072..dccd3758cd512879b5e66abf7d5bdf6297202d09 100644 --- a/ee/app/models/ee/issue.rb +++ b/ee/app/models/ee/issue.rb @@ -198,6 +198,11 @@ def supports_weight? !work_item_type&.incident? end + override :weight_available? + def weight_available? + super && resource_parent&.licensed_feature_available?(:issue_weights) + end + override :supports_iterations? def supports_iterations? !work_item_type&.incident? diff --git a/ee/spec/models/issue_spec.rb b/ee/spec/models/issue_spec.rb index 4dc6468f404ce10895c2de05d0375a30fbf135a3..1420127847fd24c18333d3614bc81bca42827475 100644 --- a/ee/spec/models/issue_spec.rb +++ b/ee/spec/models/issue_spec.rb @@ -499,6 +499,62 @@ end end + describe '#weight_available?' do + subject { issue.weight_available? } + + context 'when issue belongs to a project' do + let(:issue) { build_stubbed(:issue) } + + context 'when weights feature is available' do + before do + stub_licensed_features(issue_weights: true) + end + + it { is_expected.to be_truthy } + + context 'when issue is of type incident' do + let(:issue) { build_stubbed(:issue, :incident) } + + it { is_expected.to be_falsey } + end + end + + context 'when weights feature is not available' do + before do + stub_licensed_features(issue_weights: false) + end + + it { is_expected.to be_falsey } + end + end + + context 'when issue belongs to a group' do + let(:issue) { build_stubbed(:issue, :group_level) } + + context 'when weights feature is available' do + before do + stub_licensed_features(issue_weights: true) + end + + it { is_expected.to be_truthy } + + context 'when issue is of type incident' do + let(:issue) { build_stubbed(:issue, :group_level, :incident) } + + it { is_expected.to be_falsey } + end + end + + context 'when weights feature is not available' do + before do + stub_licensed_features(issue_weights: false) + end + + it { is_expected.to be_falsey } + end + end + end + describe '.simple_sorts' do it 'includes weight with other base keys' do expect(described_class.simple_sorts.keys).to match_array( diff --git a/ee/spec/requests/api/graphql/mutations/work_items/update_spec.rb b/ee/spec/requests/api/graphql/mutations/work_items/update_spec.rb index 1ed9cb6565cd7f81e8fb694034e3b72a49262869..c4cc882487af7fb2aae4ce06ac11ba7831faf8dc 100644 --- a/ee/spec/requests/api/graphql/mutations/work_items/update_spec.rb +++ b/ee/spec/requests/api/graphql/mutations/work_items/update_spec.rb @@ -7,10 +7,11 @@ let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, group: group) } - let_it_be(:reporter) { create(:user).tap { |user| project.add_reporter(user) } } - let_it_be(:guest) { create(:user).tap { |user| project.add_guest(user) } } - let_it_be(:work_item, refind: true) { create(:work_item, project: project) } + let_it_be(:reporter) { create(:user).tap { |user| group.add_reporter(user) } } + let_it_be(:guest) { create(:user).tap { |user| group.add_guest(user) } } + let_it_be(:project_work_item, refind: true) { create(:work_item, project: project) } + let(:work_item) { project_work_item } let(:mutation) { graphql_mutation(:workItemUpdate, input.merge('id' => work_item.to_global_id.to_s), fields) } let(:mutation_response) { graphql_mutation_response(:work_item_update) } @@ -223,6 +224,12 @@ it_behaves_like 'work item is not updated' end end + + context 'when the work item is directly associated with a group' do + let(:work_item) { create(:work_item, :group_level, namespace: group) } + + it_behaves_like 'update work item weight widget' + end end it_behaves_like 'user without permission to admin work item cannot update the attribute'