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
class BaseService < IssuableBaseService
extend ::Gitlab::Utils::Override
attr_reader :group, :parent_epic
attr_reader :group, :parent_epic, :child_epic
def initialize(group, current_user, params = {})
@group, @current_user, @params = group, current_user, params
......@@ -21,6 +21,7 @@ module Epics
def set_quick_action_params
@parent_epic = params.delete(:quick_action_assign_to_parent_epic)
@child_epic = params.delete(:quick_action_assign_child_epic)
end
def assign_parent_epic_for(epic)
......@@ -29,6 +30,12 @@ module Epics
EpicLinks::CreateService.new(parent_epic, current_user, { target_issuable: epic }).execute
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
@available_labels ||= LabelsFinder.new(
current_user,
......
......@@ -24,6 +24,7 @@ module Epics
def after_create(epic)
assign_parent_epic_for(epic)
assign_child_epic_for(epic)
end
def set_date_params
......
......@@ -22,6 +22,7 @@ module Epics
end
assign_parent_epic_for(epic)
assign_child_epic_for(epic)
epic
end
......
---
title: Support /child quick action when creating epics
merge_request: 53073
author:
type: added
......@@ -15,12 +15,12 @@ module EE
_("Adds %{epic_ref} as child epic.") % { epic_ref: child_epic.to_reference(quick_action_target) } if child_epic
end
types Epic
condition { action_allowed_only_on_update? }
condition { action_allowed? }
params '<&epic | group&epic | Epic URL>'
command :child_epic do |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
desc _('Remove child epic from an epic')
......@@ -102,12 +102,12 @@ module EE
epic.child?(target_epic.id) || target_epic.child?(epic.id)
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(:already_related) if epics_related?(child_epic, target_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) }
end
......
......@@ -84,12 +84,12 @@ RSpec.describe Epics::CreateService do
end
context 'when description param has quick action' do
context 'for /parent_epic' do
before do
stub_licensed_features(epics: true, subepics: true)
group.add_developer(user)
end
before do
stub_licensed_features(epics: true, subepics: true)
group.add_developer(user)
end
context 'for /parent_epic' do
it 'assigns parent epic' do
parent_epic = create(:epic, group: group)
description = "/parent_epic #{parent_epic.to_reference}"
......@@ -113,6 +113,31 @@ RSpec.describe Epics::CreateService do
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
......
......@@ -308,6 +308,11 @@ RSpec.describe Epics::UpdateService do
end
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
let(:label) { create(:group_label, group: group) }
......@@ -319,11 +324,6 @@ RSpec.describe Epics::UpdateService do
end
context 'for /parent_epic' do
before do
stub_licensed_features(epics: true, subepics: true)
group.add_developer(user)
end
it 'assigns parent epic' do
parent_epic = create(:epic, group: epic.group)
......@@ -343,6 +343,26 @@ RSpec.describe Epics::UpdateService do
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
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