Commit 763d5577 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Allow relate quick action on issue create

Allow the use of the `/relate` quick action in the issue description
when the issue is first created. This enables users to use this feature
in issue templates.

Changelog: added
parent b5247dec
...@@ -17,11 +17,17 @@ module Gitlab ...@@ -17,11 +17,17 @@ module Gitlab
params '#issue' params '#issue'
types Issue types Issue
condition do 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 end
command :relate do |related_param| command :relate do |related_reference|
IssueLinks::CreateService.new(quick_action_target, current_user, { issuable_references: [related_param] }).execute 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 end
end end
......
...@@ -1935,6 +1935,21 @@ RSpec.describe QuickActions::InterpretService do ...@@ -1935,6 +1935,21 @@ RSpec.describe QuickActions::InterpretService do
it_behaves_like 'relate command' it_behaves_like 'relate command'
end 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 context 'empty relate command' do
let(:issues_related) { [] } let(:issues_related) { [] }
let(:content) { '/relate' } 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