Commit 46123116 authored by Igor Drozdov's avatar Igor Drozdov

Merge branch '336724-allow-relate-when-creating-issue' into 'master'

Allow relate quick action on issue create

See merge request gitlab-org/gitlab!71193
parents 416820bd 763d5577
......@@ -17,11 +17,17 @@ module Gitlab
params '#issue'
types Issue
condition do
quick_action_target.persisted? &&
current_user.can?(:"update_#{quick_action_target.to_ability_name}", quick_action_target)
current_user.can?(:"update_#{quick_action_target.to_ability_name}", quick_action_target)
end
command :relate do |related_param|
IssueLinks::CreateService.new(quick_action_target, current_user, { issuable_references: [related_param] }).execute
command :relate do |related_reference|
service = IssueLinks::CreateService.new(quick_action_target, current_user, { issuable_references: [related_reference] })
create_issue_link = proc { service.execute }
if quick_action_target.persisted?
create_issue_link.call
else
quick_action_target.run_after_commit(&create_issue_link)
end
end
end
end
......
......@@ -1935,6 +1935,21 @@ RSpec.describe QuickActions::InterpretService do
it_behaves_like 'relate command'
end
context 'when quick action target is unpersisted' do
let(:issue) { build(:issue, project: project) }
let(:other_issue) { create(:issue, project: project) }
let(:issues_related) { [other_issue] }
let(:content) { "/relate #{other_issue.to_reference}" }
it 'relates the issues after the issue is persisted' do
service.execute(content, issue)
issue.save!
expect(IssueLink.where(source: issue).map(&:target)).to match_array(issues_related)
end
end
context 'empty relate command' do
let(:issues_related) { [] }
let(:content) { '/relate' }
......
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