Commit 9d7837f5 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '238884-epic-error-messages' into 'master'

Improve errors when setting confidential epics

See merge request gitlab-org/gitlab!53078
parents 862c76f0 3944ce9c
......@@ -126,6 +126,11 @@ export const assignIssueToEpic = ({ state, dispatch }, epic) => {
epic,
});
})
.catch((error) => {
// Handle specific format "#ID cannot be added: reason"
const message = error.response.data.message.split(':')[1].trim();
dispatch('receiveIssueUpdateFailure', message);
})
.catch(() => {
// Shows flash error for Epic change failure
dispatch(
......
......@@ -276,8 +276,16 @@ module EE
return unless epic
if !confidential? && epic.confidential?
errors.add :issue, _('Cannot set confidential epic for a non-confidential issue')
errors.add :issue, confidentiality_error
end
end
def confidentiality_error
if changed_attribute_names_to_save.include?('confidential')
return _('this issue cannot be made public since it belongs to a confidential epic')
end
_('this issue cannot be assigned to a confidential epic since it is public')
end
end
end
---
title: Add a meaningful error message for assigning confidential epics to issues
merge_request: 53078
author:
type: added
......@@ -280,22 +280,70 @@ RSpec.describe Issue do
end
describe 'confidential' do
subject { build(:issue, :confidential) }
let_it_be(:epic) { create(:epic, :confidential) }
it 'is valid when changing to non-confidential and is associated with non-confidential epic' do
subject.epic = build(:epic)
context 'when assigning an epic to a new issue' do
let(:issue) { build(:issue, confidential: confidential) }
subject.confidential = false
context 'when an issue is not confidential' do
let(:confidential) { false }
expect(subject).to be_valid
it 'is not valid' do
issue.epic = epic
expect(issue).not_to be_valid
expect(issue.errors.messages[:issue]).to include(/this issue cannot be assigned to a confidential epic since it is public/)
end
end
context 'when an issue is confidential' do
let(:confidential) { true }
it 'is valid' do
issue.epic = epic
expect(issue).to be_valid
end
end
end
it 'is not valid when changing to non-confidential and is associated with confidential epic' do
subject.epic = build(:epic, :confidential)
context 'when updating an existing issue' do
let(:confidential) { true }
let(:issue) { create(:issue, confidential: confidential) }
subject.confidential = false
context 'when an issue is assigned to the confidential epic' do
before do
issue.update!(epic: epic)
end
expect(subject).not_to be_valid
context 'when changing issue to public' do
it 'is not valid' do
issue.confidential = false
expect(issue).not_to be_valid
expect(issue.errors.messages[:issue]).to include(/this issue cannot be made public since it belongs to a confidential epic/)
end
end
end
context 'when assigining a confidential issue' do
it 'is valid' do
issue.epic = epic
expect(issue).to be_valid
end
end
context 'when assigining a public issue' do
let(:confidential) { false }
it 'is not valid' do
issue.epic = epic
expect(issue).not_to be_valid
expect(issue.errors.messages[:issue]).to include(/this issue cannot be assigned to a confidential epic since it is public/)
end
end
end
end
end
......
......@@ -35309,6 +35309,12 @@ msgstr ""
msgid "this document"
msgstr ""
msgid "this issue cannot be assigned to a confidential epic since it is public"
msgstr ""
msgid "this issue cannot be made public since it belongs to a confidential epic"
msgstr ""
msgid "time summary"
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