Commit 5d19a180 authored by charlie ablett's avatar charlie ablett

Merge branch 'issue_208974' into 'master'

Move promoting issues to UpdateService

See merge request gitlab-org/gitlab!27625
parents d6d47999 71559de9
......@@ -8,6 +8,8 @@ module EE
override :execute
def execute(issue)
handle_epic(issue)
handle_promotion(issue)
result = super
if issue.previous_changes.include?(:milestone_id) && issue.epic
......@@ -19,6 +21,12 @@ module EE
private
def handle_promotion(issue)
return unless params.delete(:promote_to_epic)
Epics::IssuePromoteService.new(issue.project, current_user).execute(issue)
end
def handle_epic(issue)
return unless params.key?(:epic)
......
......@@ -73,7 +73,7 @@ module EE
current_user.can?(:create_epic, project.group)
end
command :promote do
Epics::IssuePromoteService.new(quick_action_target.project, current_user).execute(quick_action_target)
@updates[:promote_to_epic] = true
@execution_message[:promote] = if quick_action_target.confidential?
_('Promoted confidential issue to a non-confidential epic. Information in this issue is no longer confidential as epics are public to group members.')
......
......@@ -164,5 +164,26 @@ describe Issues::UpdateService do
let(:execute) { described_class.new(project, user, params).execute(issue) }
let(:epic) { create(:epic, group: group) }
end
context 'promoting to epic' do
before do
stub_licensed_features(epics: true)
group.add_developer(user)
end
context 'when promote_to_epic param is present' do
it 'promotes issue to epic' do
expect { update_issue(promote_to_epic: true) }.to change { Epic.count }.by(1)
expect(issue.promoted_to_epic_id).not_to be_nil
end
end
context 'when promote_to_epic param is not present' do
it 'does not promote issue to epic' do
expect { update_issue(promote_to_epic: false) }.not_to change { Epic.count }
expect(issue.promoted_to_epic_id).to be_nil
end
end
end
end
end
......@@ -353,4 +353,69 @@ describe Notes::QuickActionsService do
end
end
end
context '/promote' do
let(:note_text) { "/promote" }
let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) }
context 'when epics are enabled' do
before do
stub_licensed_features(epics: true)
end
context 'when a user does not have permissions to promote an issue' do
it 'does not promote an issue to an epic' do
expect { execute(note) }.not_to change { Epic.count }
expect(issue.promoted_to_epic_id).to be_nil
end
end
context 'when a user has permissions to promote an issue' do
before do
group.add_developer(user)
end
it 'promotes an issue to an epic' do
expect { execute(note) }.to change { Epic.count }.by(1)
expect(issue.promoted_to_epic_id).to be_present
end
context 'with a double promote' do
let(:note_text) do
<<~HEREDOC
/promote
/promote
HEREDOC
end
it 'only creates one epic' do
expect { execute(note) }.to change { Epic.count }.by(1)
end
end
context 'when an issue belongs to a project without group' do
let(:user_project) { create(:project) }
let(:issue) { create(:issue, project: user_project) }
let(:note) { create(:note_on_issue, noteable: issue, project: user_project, note: note_text) }
before do
user_project.add_developer(user)
end
it 'does not promote an issue to an epic' do
expect { execute(note) }
.to raise_error(Epics::IssuePromoteService::PromoteError)
end
end
end
end
context 'when epics are disabled' do
it 'does not promote an issue to an epic' do
group.add_developer(user)
expect { execute(note) }.not_to change { Epic.count }
end
end
end
end
......@@ -292,56 +292,6 @@ describe QuickActions::InterpretService do
end
end
context 'promote command' do
let(:content) { "/promote" }
context 'when epics are enabled' do
context 'when a user does not have permissions to promote an issue' do
it 'does not promote an issue to an epic' do
expect { service.execute(content, issue) }.not_to change { Epic.count }
end
end
context 'when a user has permissions to promote an issue' do
before do
group.add_developer(current_user)
end
context 'when epics are enabled' do
before do
stub_licensed_features(epics: true)
end
it 'promotes an issue to an epic' do
expect { service.execute(content, issue) }.to change { Epic.count }.by(1)
end
context 'when an issue belongs to a project without group' do
let(:user_project) { create(:project) }
let(:issue) { create(:issue, project: user_project) }
before do
user_project.add_developer(user)
end
it 'does not promote an issue to an epic' do
expect { service.execute(content, issue) }
.to raise_error(Epics::IssuePromoteService::PromoteError)
end
end
end
end
end
context 'when epics are disabled' do
it 'does not promote an issue to an epic' do
group.add_developer(current_user)
expect { service.execute(content, issue) }.not_to change { Epic.count }
end
end
end
context 'child_epic command' do
let(:subgroup) { create(:group, parent: group) }
let(:another_group) { create(:group) }
......
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