Commit 27ca980b authored by Felipe Artur's avatar Felipe Artur

Support /child_epic quick action when creating epics

Allow to assign child epics with quick actions when creating epics
parent 643b55f6
...@@ -4,7 +4,7 @@ module Epics ...@@ -4,7 +4,7 @@ module Epics
class BaseService < IssuableBaseService class BaseService < IssuableBaseService
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
attr_reader :group, :parent_epic attr_reader :group, :parent_epic, :child_epic
def initialize(group, current_user, params = {}) def initialize(group, current_user, params = {})
@group, @current_user, @params = group, current_user, params @group, @current_user, @params = group, current_user, params
...@@ -21,6 +21,7 @@ module Epics ...@@ -21,6 +21,7 @@ module Epics
def set_quick_action_params def set_quick_action_params
@parent_epic = params.delete(:quick_action_assign_to_parent_epic) @parent_epic = params.delete(:quick_action_assign_to_parent_epic)
@child_epic = params.delete(:quick_action_assign_child_epic)
end end
def assign_parent_epic_for(epic) def assign_parent_epic_for(epic)
...@@ -29,6 +30,12 @@ module Epics ...@@ -29,6 +30,12 @@ module Epics
EpicLinks::CreateService.new(parent_epic, current_user, { target_issuable: epic }).execute EpicLinks::CreateService.new(parent_epic, current_user, { target_issuable: epic }).execute
end end
def assign_child_epic_for(epic)
return unless child_epic
EpicLinks::CreateService.new(epic, current_user, { target_issuable: child_epic }).execute
end
def available_labels def available_labels
@available_labels ||= LabelsFinder.new( @available_labels ||= LabelsFinder.new(
current_user, current_user,
......
...@@ -24,6 +24,7 @@ module Epics ...@@ -24,6 +24,7 @@ module Epics
def after_create(epic) def after_create(epic)
assign_parent_epic_for(epic) assign_parent_epic_for(epic)
assign_child_epic_for(epic)
end end
def set_date_params def set_date_params
......
...@@ -22,6 +22,7 @@ module Epics ...@@ -22,6 +22,7 @@ module Epics
end end
assign_parent_epic_for(epic) assign_parent_epic_for(epic)
assign_child_epic_for(epic)
epic epic
end end
......
---
title: Support /child quick action when creating epics
merge_request: 53073
author:
type: added
...@@ -15,12 +15,12 @@ module EE ...@@ -15,12 +15,12 @@ module EE
_("Adds %{epic_ref} as child epic.") % { epic_ref: child_epic.to_reference(quick_action_target) } if child_epic _("Adds %{epic_ref} as child epic.") % { epic_ref: child_epic.to_reference(quick_action_target) } if child_epic
end end
types Epic types Epic
condition { action_allowed_only_on_update? } condition { action_allowed? }
params '<&epic | group&epic | Epic URL>' params '<&epic | group&epic | Epic URL>'
command :child_epic do |epic_param| command :child_epic do |epic_param|
child_epic = extract_epic(epic_param) child_epic = extract_epic(epic_param)
@execution_message[:child_epic] = add_child_epic(quick_action_target, child_epic) @execution_message[:child_epic] = set_child_epic_update(quick_action_target, child_epic)
end end
desc _('Remove child epic from an epic') desc _('Remove child epic from an epic')
...@@ -102,12 +102,12 @@ module EE ...@@ -102,12 +102,12 @@ module EE
epic.child?(target_epic.id) || target_epic.child?(epic.id) epic.child?(target_epic.id) || target_epic.child?(epic.id)
end end
def add_child_epic(target_epic, child_epic) def set_child_epic_update(target_epic, child_epic)
return child_error_message(:not_present) unless child_epic.present? return child_error_message(:not_present) unless child_epic.present?
return child_error_message(:already_related) if epics_related?(child_epic, target_epic) return child_error_message(:already_related) if epics_related?(child_epic, target_epic)
return child_error_message(:no_permission) unless current_user.can?(:read_epic, child_epic) return child_error_message(:no_permission) unless current_user.can?(:read_epic, child_epic)
EpicLinks::CreateService.new(target_epic, current_user, { target_issuable: child_epic }).execute @updates[:quick_action_assign_child_epic] = child_epic
_("Added %{epic_ref} as a child epic.") % { epic_ref: child_epic.to_reference(target_epic) } _("Added %{epic_ref} as a child epic.") % { epic_ref: child_epic.to_reference(target_epic) }
end end
......
...@@ -84,12 +84,12 @@ RSpec.describe Epics::CreateService do ...@@ -84,12 +84,12 @@ RSpec.describe Epics::CreateService do
end end
context 'when description param has quick action' do context 'when description param has quick action' do
context 'for /parent_epic' do before do
before do stub_licensed_features(epics: true, subepics: true)
stub_licensed_features(epics: true, subepics: true) group.add_developer(user)
group.add_developer(user) end
end
context 'for /parent_epic' do
it 'assigns parent epic' do it 'assigns parent epic' do
parent_epic = create(:epic, group: group) parent_epic = create(:epic, group: group)
description = "/parent_epic #{parent_epic.to_reference}" description = "/parent_epic #{parent_epic.to_reference}"
...@@ -113,6 +113,31 @@ RSpec.describe Epics::CreateService do ...@@ -113,6 +113,31 @@ RSpec.describe Epics::CreateService do
end end
end end
end end
context 'for /child_epic' do
it 'sets a child epic' do
child_epic = create(:epic, group: group)
description = "/child_epic #{child_epic.to_reference}"
params = { title: 'New epic with child', description: description }
epic = described_class.new(group, user, params).execute
expect(epic.reload.children).to include(child_epic)
end
context 'when child epic cannot be assigned' do
it 'does not set child epic' do
other_group = create(:group, :private)
child_epic = create(:epic, group: other_group)
description = "/child_epic #{child_epic.to_reference(group)}"
params = { title: 'New epic with child', description: description }
epic = described_class.new(group, user, params).execute
expect(epic.reload.children).to be_empty
end
end
end
end end
end end
end end
......
...@@ -308,6 +308,11 @@ RSpec.describe Epics::UpdateService do ...@@ -308,6 +308,11 @@ RSpec.describe Epics::UpdateService do
end end
context 'with quick actions in the description' do context 'with quick actions in the description' do
before do
stub_licensed_features(epics: true, subepics: true)
group.add_developer(user)
end
context 'for /label' do context 'for /label' do
let(:label) { create(:group_label, group: group) } let(:label) { create(:group_label, group: group) }
...@@ -319,11 +324,6 @@ RSpec.describe Epics::UpdateService do ...@@ -319,11 +324,6 @@ RSpec.describe Epics::UpdateService do
end end
context 'for /parent_epic' do context 'for /parent_epic' do
before do
stub_licensed_features(epics: true, subepics: true)
group.add_developer(user)
end
it 'assigns parent epic' do it 'assigns parent epic' do
parent_epic = create(:epic, group: epic.group) parent_epic = create(:epic, group: epic.group)
...@@ -343,6 +343,26 @@ RSpec.describe Epics::UpdateService do ...@@ -343,6 +343,26 @@ RSpec.describe Epics::UpdateService do
end end
end end
end end
context 'for /child_epic' do
it 'sets a child epic' do
child_epic = create(:epic, group: group)
update_epic(description: "/child_epic #{child_epic.to_reference}")
expect(epic.reload.children).to include(child_epic)
end
context 'when child epic cannot be assigned' do
it 'does not set child epic' do
other_group = create(:group, :private)
child_epic = create(:epic, group: other_group)
update_epic(description: "/child_epic #{child_epic.to_reference(group)}")
expect(epic.reload.children).to be_empty
end
end
end
end end
end end
end end
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