Commit 0e5fa4c2 authored by Mark Chao's avatar Mark Chao

Merge branch 'issue_323778-restrict_time_tracking_for_requirements' into 'master'

Enable time tracking quick actions only for issues and incidents

See merge request gitlab-org/gitlab!62318
parents 46c03e93 9e760b44
......@@ -11,7 +11,8 @@ module IssueAvailableFeatures
def available_features_for_issue_types
{
assignee: %w(issue incident),
confidentiality: %(issue incident)
confidentiality: %(issue incident),
time_tracking: %(issue incident)
}.with_indifferent_access
end
end
......
......@@ -464,6 +464,10 @@ class Issue < ApplicationRecord
issue_type_supports?(:assignee)
end
def supports_time_tracking?
issue_type_supports?(:time_tracking)
end
def email_participants_emails
issue_email_participants.pluck(:email)
end
......
......@@ -10,6 +10,15 @@ FactoryBot.modify do
end
end
# There is another factory called :requirement for RequirementManagement::Requirement.
# We are converting that class into an issue type. We can rename this as :requirement
# when migration is completed. More information at https://gitlab.com/gitlab-org/gitlab/-/issues/323779
FactoryBot.define do
factory :requirement_issue, parent: :issue do
issue_type { :requirement }
end
end
FactoryBot.define do
factory :quality_test_case, parent: :issue do
issue_type { :test_case }
......
......@@ -1019,6 +1019,26 @@ RSpec.describe Issue do
end
end
describe '#supports_time_tracking?' do
let_it_be(:project) { create(:project) }
let_it_be_with_refind(:issue) { create(:incident, project: project) }
where(:issue_type, :supports_time_tracking) do
:requirement | false
:test_case | false
end
with_them do
before do
issue.update!(issue_type: issue_type)
end
it do
expect(issue.supports_time_tracking?).to eq(supports_time_tracking)
end
end
end
describe '.with_issue_type' do
let_it_be(:project) { create(:project) }
let_it_be(:issue) { create(:issue, project: project) }
......
......@@ -486,4 +486,48 @@ RSpec.describe Notes::QuickActionsService do
end
end
end
context 'with issue types' do
shared_examples 'note on issue type that does not support time tracking' do
let(:note) { build(:note_on_issue, project: project, noteable: noteable) }
before do
note.note = note_text
end
context '/spend' do
let(:note_text) { "/spend 1h 2021-05-26" }
it 'does not change time spent' do
expect { execute(note) }.not_to change { noteable.reload.time_spent }
end
end
context '/estimate' do
let(:note_text) { "/estimate 1h" }
it 'does not execute time estimate' do
expect { execute(note) }.not_to change { noteable.reload.time_estimate }
end
end
end
context 'when issue does not support quick actions' do
before do
group.add_developer(user)
end
context 'for requirement' do
it_behaves_like 'note on issue type that does not support time tracking' do
let(:noteable) { create(:requirement_issue, project: project) }
end
end
context 'for test case' do
it_behaves_like 'note on issue type that does not support time tracking' do
let(:noteable) { create(:quality_test_case, project: project) }
end
end
end
end
end
......@@ -155,6 +155,7 @@ module Gitlab
params '<1w 3d 2h 14m>'
types Issue, MergeRequest
condition do
quick_action_target.supports_time_tracking? &&
current_user.can?(:"admin_#{quick_action_target.to_ability_name}", project)
end
parse_params do |raw_duration|
......@@ -177,6 +178,7 @@ module Gitlab
params '<time(1h30m | -1h30m)> <date(YYYY-MM-DD)>'
types Issue, MergeRequest
condition do
quick_action_target.supports_time_tracking? &&
current_user.can?(:"admin_#{quick_action_target.to_ability_name}", quick_action_target)
end
parse_params do |raw_time_date|
......
......@@ -5,6 +5,8 @@ require 'spec_helper'
RSpec.describe Issue do
include ExternalAuthorizationServiceHelpers
using RSpec::Parameterized::TableSyntax
let_it_be(:user) { create(:user) }
let_it_be(:reusable_project) { create(:project) }
......@@ -1333,6 +1335,26 @@ RSpec.describe Issue do
end
end
describe '#supports_time_tracking?' do
let_it_be(:project) { create(:project) }
let_it_be_with_refind(:issue) { create(:incident, project: project) }
where(:issue_type, :supports_time_tracking) do
:issue | true
:incident | true
end
with_them do
before do
issue.update!(issue_type: issue_type)
end
it do
expect(issue.supports_time_tracking?).to eq(supports_time_tracking)
end
end
end
describe '#email_participants_emails' do
let_it_be(:issue) { create(:issue) }
......
......@@ -130,6 +130,17 @@ RSpec.describe Notes::QuickActionsService do
end
end
describe '/estimate' do
let(:note_text) { '/estimate 1h' }
it 'adds time estimate to noteable' do
content = execute(note)
expect(content).to be_empty
expect(note.noteable.time_estimate).to eq(3600)
end
end
describe 'note with command & text' do
describe '/close, /label, /assign & /milestone' do
let(:note_text) do
......@@ -301,6 +312,11 @@ RSpec.describe Notes::QuickActionsService do
let(:note) { build(:note_on_issue, project: project, noteable: issue) }
end
it_behaves_like 'note on noteable that supports quick actions' do
let_it_be(:incident, reload: true) { create(:incident, project: project) }
let(:note) { build(:note_on_issue, project: project, noteable: incident) }
end
it_behaves_like 'note on noteable that supports quick actions' do
let(:merge_request) { create(:merge_request, source_project: project) }
let(:note) { build(:note_on_merge_request, project: project, noteable: merge_request) }
......
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