Commit cfa7a76e authored by John Hope's avatar John Hope Committed by Vasilii Iakliushin

Return a readable error message for epic assignment failure

parent 170ac699
......@@ -18,8 +18,12 @@ module Mutations
authorize_admin_rights!(epic)
::Issues::UpdateService.new(project: project, current_user: current_user, params: { epic: epic })
.execute(issue)
begin
::Issues::UpdateService.new(project: project, current_user: current_user, params: { epic: epic })
.execute(issue)
rescue EE::Issues::BaseService::EpicAssignmentError => error
issue.errors.add(:base, error.message)
end
{
issue: issue,
......
......@@ -37,7 +37,7 @@ class EpicIssue < ApplicationRecord
return unless epic && issue
if epic.confidential? && !issue.confidential?
errors.add :issue, _('Cannot set confidential epic for a non-confidential issue')
errors.add :issue, _('Cannot assign a confidential epic to a non-confidential issue. Make the issue confidential and try again')
end
end
end
......@@ -59,6 +59,14 @@ RSpec.describe Mutations::Issues::SetEpic do
expect(mutated_issue.epic).to eq(nil)
end
end
context 'when epic is confidential but issue is public' do
let(:epic) { create(:epic, group: group, confidential: true) }
it 'returns an error with appropriate message' do
expect(subject[:errors].first).to include("Cannot assign a confidential epic to a non-confidential issue. Make the issue confidential and try again")
end
end
end
end
end
......
......@@ -235,8 +235,8 @@ RSpec.describe EpicIssues::CreateService do
expect(subject).to eq(
status: :error,
http_status: 422,
message: "#{invalid_issue1.to_reference} cannot be added: Cannot set confidential epic for a non-confidential issue. "\
"#{invalid_issue2.to_reference} cannot be added: Cannot set confidential epic for a non-confidential issue"
message: "#{invalid_issue1.to_reference} cannot be added: Cannot assign a confidential epic to a non-confidential issue. Make the issue confidential and try again. "\
"#{invalid_issue2.to_reference} cannot be added: Cannot assign a confidential epic to a non-confidential issue. Make the issue confidential and try again"
)
end
end
......
......@@ -6225,6 +6225,9 @@ msgstr ""
msgid "Cancelling Preview"
msgstr ""
msgid "Cannot assign a confidential epic to a non-confidential issue. Make the issue confidential and try again"
msgstr ""
msgid "Cannot be assigned to other projects."
msgstr ""
......@@ -6276,9 +6279,6 @@ msgstr ""
msgid "Cannot refer to a group %{timebox_type} by an internal id!"
msgstr ""
msgid "Cannot set confidential epic for a non-confidential issue"
msgstr ""
msgid "Cannot show preview. For previews on sketch files, they must have the file format introduced by Sketch version 43 and above."
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