Commit 71559de9 authored by Felipe Artur's avatar Felipe Artur

Move promoting issues to UpdateService

Move promoting issues to epics code from
InterpretService to UpdateService.
parent b7b5cc99
...@@ -8,6 +8,8 @@ module EE ...@@ -8,6 +8,8 @@ module EE
override :execute override :execute
def execute(issue) def execute(issue)
handle_epic(issue) handle_epic(issue)
handle_promotion(issue)
result = super result = super
if issue.previous_changes.include?(:milestone_id) && issue.epic if issue.previous_changes.include?(:milestone_id) && issue.epic
...@@ -19,6 +21,12 @@ module EE ...@@ -19,6 +21,12 @@ module EE
private 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) def handle_epic(issue)
return unless params.key?(:epic) return unless params.key?(:epic)
......
...@@ -73,7 +73,7 @@ module EE ...@@ -73,7 +73,7 @@ module EE
current_user.can?(:create_epic, project.group) current_user.can?(:create_epic, project.group)
end end
command :promote do 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? @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.') _('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 ...@@ -164,5 +164,26 @@ describe Issues::UpdateService do
let(:execute) { described_class.new(project, user, params).execute(issue) } let(:execute) { described_class.new(project, user, params).execute(issue) }
let(:epic) { create(:epic, group: group) } let(:epic) { create(:epic, group: group) }
end 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
end end
...@@ -353,4 +353,69 @@ describe Notes::QuickActionsService do ...@@ -353,4 +353,69 @@ describe Notes::QuickActionsService do
end end
end 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 end
...@@ -292,56 +292,6 @@ describe QuickActions::InterpretService do ...@@ -292,56 +292,6 @@ describe QuickActions::InterpretService do
end end
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 context 'child_epic command' do
let(:subgroup) { create(:group, parent: group) } let(:subgroup) { create(:group, parent: group) }
let(:another_group) { create(: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