Commit 1c7690a5 authored by Eugenia Grieff's avatar Eugenia Grieff

Add missing error handling for epic quick actions

Include error messages for epic quick actions when
epics don't exist, are already related, or user
has no permission to read them
parent 23b553ee
---
title: Add missing error handling for epic quick actions
merge_request: 15648
author:
type: fixed
...@@ -20,17 +20,14 @@ module EE ...@@ -20,17 +20,14 @@ module EE
command :child_epic do |epic_param| command :child_epic do |epic_param|
child_epic = extract_epic(epic_param) child_epic = extract_epic(epic_param)
if child_epic && !quick_action_target.child?(child_epic.id) @execution_message[:child_epic] = add_child_epic(quick_action_target, child_epic)
EpicLinks::CreateService.new(quick_action_target, current_user, { target_issuable: child_epic }).execute
@execution_message[:child_epic] = _("Added %{epic_ref} as child epic.") % { epic_ref: child_epic.to_reference(quick_action_target) }
end
end end
desc _('Remove child epic from an epic') desc _('Remove child epic from an epic')
explanation do |epic_param| explanation do |epic_param|
child_epic = extract_epic(epic_param) child_epic = extract_epic(epic_param)
_("Removes %{epic_ref} from child epics.") % { epic_ref: child_epic.to_reference(quick_action_target) } _("Removes %{epic_ref} from child epics.") % { epic_ref: child_epic.to_reference(quick_action_target) } if child_epic
end end
types Epic types Epic
condition { action_allowed? } condition { action_allowed? }
...@@ -38,10 +35,14 @@ module EE ...@@ -38,10 +35,14 @@ module EE
command :remove_child_epic do |epic_param| command :remove_child_epic do |epic_param|
child_epic = extract_epic(epic_param) child_epic = extract_epic(epic_param)
if child_epic && quick_action_target.child?(child_epic.id) @execution_message[:remove_child_epic] =
EpicLinks::DestroyService.new(child_epic, current_user).execute if child_epic && quick_action_target.child?(child_epic.id)
@execution_message[:remove_child_epic] = _("Removed %{epic_ref} from child epics.") % { epic_ref: child_epic.to_reference(quick_action_target) } EpicLinks::DestroyService.new(child_epic, current_user).execute
end
_("Removed %{epic_ref} from child epics.") % { epic_ref: child_epic.to_reference(quick_action_target) }
else
_("Child epic does not exist.")
end
end end
desc _('Set parent epic to an epic') desc _('Set parent epic to an epic')
...@@ -56,26 +57,28 @@ module EE ...@@ -56,26 +57,28 @@ module EE
command :parent_epic do |epic_param| command :parent_epic do |epic_param|
parent_epic = extract_epic(epic_param) parent_epic = extract_epic(epic_param)
if parent_epic && !parent_epic.child?(quick_action_target.id) @execution_message[:parent_epic] = set_parent_epic(quick_action_target, parent_epic)
EpicLinks::CreateService.new(parent_epic, current_user, { target_issuable: quick_action_target }).execute
@execution_message[:parent_epic] = _("Set %{epic_ref} as parent epic.") % { epic_ref: parent_epic.to_reference(quick_action_target) }
end
end end
desc _('Remove parent epic from an epic') desc _('Remove parent epic from an epic')
explanation do explanation do
parent_epic = quick_action_target.parent parent_epic = quick_action_target.parent
_('Removes parent epic %{epic_ref}.') % { epic_ref: parent_epic.to_reference(quick_action_target) } _('Removes parent epic %{epic_ref}.') % { epic_ref: parent_epic.to_reference(quick_action_target) } if parent_epic
end end
types Epic types Epic
condition do condition { action_allowed? }
action_allowed? && quick_action_target.parent.present?
end
command :remove_parent_epic do command :remove_parent_epic do
parent_epic = quick_action_target.parent parent_epic = quick_action_target.parent
EpicLinks::DestroyService.new(quick_action_target, current_user).execute
@execution_message[:remove_parent_epic] = _('Removed parent epic %{epic_ref}.') % { epic_ref: parent_epic.to_reference(quick_action_target) } @execution_message[:remove_parent_epic] =
if parent_epic
EpicLinks::DestroyService.new(quick_action_target, current_user).execute
_('Removed parent epic %{epic_ref}.') % { epic_ref: parent_epic.to_reference(quick_action_target) }
else
_("Parent epic is not present.")
end
end end
private private
...@@ -90,6 +93,52 @@ module EE ...@@ -90,6 +93,52 @@ module EE
quick_action_target.group&.feature_available?(:epics) && quick_action_target.group&.feature_available?(:epics) &&
current_user.can?(:"admin_#{quick_action_target.to_ability_name}", quick_action_target) current_user.can?(:"admin_#{quick_action_target.to_ability_name}", quick_action_target)
end end
def epics_related?(epic, target_epic)
epic.child?(target_epic.id) || target_epic.child?(epic.id)
end
def add_child_epic(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
_("Added %{epic_ref} as a child epic.") % { epic_ref: child_epic.to_reference(target_epic) }
end
def set_parent_epic(target_epic, parent_epic)
return parent_error_message(:not_present) unless parent_epic.present?
return parent_error_message(:already_related) if epics_related?(parent_epic, target_epic)
return parent_error_message(:no_permission) unless current_user.can?(:read_epic, parent_epic)
EpicLinks::CreateService.new(parent_epic, current_user, { target_issuable: target_epic }).execute
_("Set %{epic_ref} as the parent epic.") % { epic_ref: parent_epic.to_reference(target_epic) }
end
def parent_error_message(reason)
case reason
when :not_present
_("Parent epic doesn't exist.")
when :already_related
_("Given epic is already related to this epic.")
when :no_permission
_("You don't have sufficient permission to perform this action.")
end
end
def child_error_message(reason)
case reason
when :not_present
_("Child epic doesn't exist.")
when :already_related
_("Given epic is already related to this epic.")
when :no_permission
_("You don't have sufficient permission to perform this action.")
end
end
end end
end end
end end
......
...@@ -10,7 +10,6 @@ module EE ...@@ -10,7 +10,6 @@ module EE
included do included do
desc _('Add to epic') desc _('Add to epic')
explanation _('Adds an issue to an epic.') explanation _('Adds an issue to an epic.')
execution_message _('Added an issue to an epic.')
types Issue types Issue
condition do condition do
quick_action_target.project.group&.feature_available?(:epics) && quick_action_target.project.group&.feature_available?(:epics) &&
...@@ -18,7 +17,16 @@ module EE ...@@ -18,7 +17,16 @@ module EE
end end
params '<&epic | group&epic | Epic URL>' params '<&epic | group&epic | Epic URL>'
command :epic do |epic_param| command :epic do |epic_param|
@updates[:epic] = extract_epic(epic_param) epic = extract_epic(epic_param)
if epic && current_user.can?(:read_epic, epic)
@updates[:epic] = epic
message = _('Added an issue to an epic.')
else
message = _("This epic does not exist or you don't have sufficient permission.")
end
@execution_message[:epic] = message
end end
desc _('Remove from epic') desc _('Remove from epic')
......
...@@ -985,7 +985,7 @@ msgstr "" ...@@ -985,7 +985,7 @@ msgstr ""
msgid "Added" msgid "Added"
msgstr "" msgstr ""
msgid "Added %{epic_ref} as child epic." msgid "Added %{epic_ref} as a child epic."
msgstr "" msgstr ""
msgid "Added %{label_references} %{label_text}." msgid "Added %{label_references} %{label_text}."
...@@ -2934,6 +2934,12 @@ msgstr "" ...@@ -2934,6 +2934,12 @@ msgstr ""
msgid "Cherry-pick this merge request" msgid "Cherry-pick this merge request"
msgstr "" msgstr ""
msgid "Child epic does not exist."
msgstr ""
msgid "Child epic doesn't exist."
msgstr ""
msgid "Choose <strong>Create archive</strong> and wait for archiving to complete." msgid "Choose <strong>Create archive</strong> and wait for archiving to complete."
msgstr "" msgstr ""
...@@ -7652,6 +7658,9 @@ msgstr "" ...@@ -7652,6 +7658,9 @@ msgstr ""
msgid "Given access %{time_ago}" msgid "Given access %{time_ago}"
msgstr "" msgstr ""
msgid "Given epic is already related to this epic."
msgstr ""
msgid "Global Shortcuts" msgid "Global Shortcuts"
msgstr "" msgstr ""
...@@ -11087,6 +11096,12 @@ msgstr "" ...@@ -11087,6 +11096,12 @@ msgstr ""
msgid "Parameter" msgid "Parameter"
msgstr "" msgstr ""
msgid "Parent epic doesn't exist."
msgstr ""
msgid "Parent epic is not present."
msgstr ""
msgid "Part of merge request changes" msgid "Part of merge request changes"
msgstr "" msgstr ""
...@@ -14243,7 +14258,7 @@ msgstr "" ...@@ -14243,7 +14258,7 @@ msgstr ""
msgid "Session expiration, projects limit and attachment size." msgid "Session expiration, projects limit and attachment size."
msgstr "" msgstr ""
msgid "Set %{epic_ref} as parent epic." msgid "Set %{epic_ref} as the parent epic."
msgstr "" msgstr ""
msgid "Set a default template for issue descriptions." msgid "Set a default template for issue descriptions."
...@@ -16074,6 +16089,9 @@ msgstr "" ...@@ -16074,6 +16089,9 @@ msgstr ""
msgid "This environment has no deployments yet." msgid "This environment has no deployments yet."
msgstr "" msgstr ""
msgid "This epic does not exist or you don't have sufficient permission."
msgstr ""
msgid "This feature requires local storage to be enabled" msgid "This feature requires local storage to be enabled"
msgstr "" msgstr ""
...@@ -18282,6 +18300,9 @@ msgstr "" ...@@ -18282,6 +18300,9 @@ msgstr ""
msgid "You don't have any recent searches" msgid "You don't have any recent searches"
msgstr "" msgstr ""
msgid "You don't have sufficient permission to perform this action."
msgstr ""
msgid "You don’t have access to Cycle Analytics for this group" msgid "You don’t have access to Cycle Analytics for this group"
msgstr "" 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