Commit 084c18cf authored by Ash McKenzie's avatar Ash McKenzie

Merge branch '7330-child-epics-quick-actions' into 'master'

Quick actions for adding/removing epic child relations

Closes #7330

See merge request gitlab-org/gitlab-ee!12772
parents 9ab04f9b ff7c8182
......@@ -283,6 +283,10 @@ module EE
issues.any? || descendants.any?
end
def child?(id)
children.where(id: id).exists?
end
def hierarchy
::Gitlab::ObjectHierarchy.new(self.class.where(id: id))
end
......
......@@ -8,6 +8,7 @@ module EE
# as doing so would clear any existing command definitions.
prepended do
# rubocop: disable Cop/InjectEnterpriseEditionModule
include EE::Gitlab::QuickActions::EpicActions
include EE::Gitlab::QuickActions::IssueActions
include EE::Gitlab::QuickActions::MergeRequestActions
include EE::Gitlab::QuickActions::IssueAndMergeRequestActions
......
---
title: Add quick actions for adding and removing child epic relations to epic
merge_request: 12772
author:
type: added
# frozen_string_literal: true
module EE
module Gitlab
module QuickActions
module EpicActions
extend ActiveSupport::Concern
include ::Gitlab::QuickActions::Dsl
included do
desc _('Add child epic to an epic')
explanation do |epic_param|
child_epic = extract_epic(epic_param)
_("Adds %{epic_ref} as child epic.") % { epic_ref: child_epic.to_reference(quick_action_target) } if child_epic
end
types Epic
condition { action_allowed? }
params '<&epic | group&epic | Epic URL>'
command :child_epic do |epic_param|
child_epic = extract_epic(epic_param)
if child_epic && !quick_action_target.child?(child_epic.id)
EpicLinks::CreateService.new(quick_action_target, current_user, { target_issuable: child_epic }).execute
end
end
desc _('Remove child epic from an epic')
explanation do |epic_param|
child_epic = extract_epic(epic_param)
_("Removes %{epic_ref} from child epics.") % { epic_ref: child_epic.to_reference(quick_action_target) } if child_epic
end
types Epic
condition { action_allowed? }
params '<&epic | group&epic | Epic URL>'
command :remove_child_epic do |epic_param|
child_epic = extract_epic(epic_param)
if child_epic && quick_action_target.child?(child_epic.id)
EpicLinks::DestroyService.new(child_epic, current_user).execute
end
end
private
def extract_epic(params)
return if params.nil?
extract_references(params, :epic).first
end
def action_allowed?
quick_action_target.group&.feature_available?(:epics) &&
current_user.can?(:"admin_#{quick_action_target.to_ability_name}", quick_action_target)
end
end
end
end
end
end
......@@ -103,7 +103,7 @@ describe Groups::AutocompleteService do
it 'returns available commands' do
expect(subject.commands(epic).map { |c| c[:name] })
.to match_array(
[:todo, :unsubscribe, :award, :shrug, :tableflip, :cc, :title, :close]
[:todo, :unsubscribe, :award, :shrug, :tableflip, :cc, :title, :close, :child_epic, :remove_child_epic]
)
end
end
......
......@@ -663,6 +663,9 @@ msgstr ""
msgid "Add bold text"
msgstr ""
msgid "Add child epic to an epic"
msgstr ""
msgid "Add comment now"
msgstr ""
......@@ -735,6 +738,9 @@ msgstr ""
msgid "Adds"
msgstr ""
msgid "Adds %{epic_ref} as child epic."
msgstr ""
msgid "Adds a todo."
msgstr ""
......@@ -10406,6 +10412,9 @@ msgstr ""
msgid "Remove avatar"
msgstr ""
msgid "Remove child epic from an epic"
msgstr ""
msgid "Remove due date"
msgstr ""
......@@ -10448,6 +10457,9 @@ msgstr ""
msgid "Removed projects cannot be restored!"
msgstr ""
msgid "Removes %{epic_ref} from child epics."
msgstr ""
msgid "Removes %{milestone_reference} milestone."
msgstr ""
......
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