Commit e999d1bd authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Merge branch...

Merge branch '337546-show-better-error-message-when-user-tries-to-assign-a-confidential-epic-to-non-confidential' into 'master'

Return a readable error message for epic assignment failure

See merge request gitlab-org/gitlab!70059
parents 44e251d6 cfa7a76e
...@@ -18,8 +18,12 @@ module Mutations ...@@ -18,8 +18,12 @@ module Mutations
authorize_admin_rights!(epic) authorize_admin_rights!(epic)
begin
::Issues::UpdateService.new(project: project, current_user: current_user, params: { epic: epic }) ::Issues::UpdateService.new(project: project, current_user: current_user, params: { epic: epic })
.execute(issue) .execute(issue)
rescue EE::Issues::BaseService::EpicAssignmentError => error
issue.errors.add(:base, error.message)
end
{ {
issue: issue, issue: issue,
......
...@@ -37,7 +37,7 @@ class EpicIssue < ApplicationRecord ...@@ -37,7 +37,7 @@ class EpicIssue < ApplicationRecord
return unless epic && issue return unless epic && issue
if epic.confidential? && !issue.confidential? 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 end
end end
...@@ -59,6 +59,14 @@ RSpec.describe Mutations::Issues::SetEpic do ...@@ -59,6 +59,14 @@ RSpec.describe Mutations::Issues::SetEpic do
expect(mutated_issue.epic).to eq(nil) expect(mutated_issue.epic).to eq(nil)
end end
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 end
end end
......
...@@ -235,8 +235,8 @@ RSpec.describe EpicIssues::CreateService do ...@@ -235,8 +235,8 @@ RSpec.describe EpicIssues::CreateService do
expect(subject).to eq( expect(subject).to eq(
status: :error, status: :error,
http_status: 422, http_status: 422,
message: "#{invalid_issue1.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 set confidential epic for a non-confidential issue" "#{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
end end
......
...@@ -6225,6 +6225,9 @@ msgstr "" ...@@ -6225,6 +6225,9 @@ msgstr ""
msgid "Cancelling Preview" msgid "Cancelling Preview"
msgstr "" 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." msgid "Cannot be assigned to other projects."
msgstr "" msgstr ""
...@@ -6276,9 +6279,6 @@ msgstr "" ...@@ -6276,9 +6279,6 @@ msgstr ""
msgid "Cannot refer to a group %{timebox_type} by an internal id!" msgid "Cannot refer to a group %{timebox_type} by an internal id!"
msgstr "" 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." msgid "Cannot show preview. For previews on sketch files, they must have the file format introduced by Sketch version 43 and above."
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