Skip to content

Commit 159e5e2

Browse files
committed
MBS-10076: Friendlier error when deleting attribute that has children
Right now this just ISEs - an actual error explaining the issue seems friendlier. This is just an admin page, but we might as well.
1 parent 69be2be commit 159e5e2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/MusicBrainz/Server/Controller/Admin/Attributes.pm

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package MusicBrainz::Server::Controller::Admin::Attributes;
22
use Moose;
33

4+
use MusicBrainz::Server::Translation qw( l ln );
5+
46
no if $] >= 5.018, warnings => "experimental::smartmatch";
57

68
BEGIN { extends 'MusicBrainz::Server::Controller' };
@@ -125,9 +127,18 @@ sub delete : Chained('attribute_base') Args(1) RequireAuth(account_admin) Secure
125127

126128
$c->detach;
127129
}
130+
131+
if ($c->model($model)->has_children($id)) {
132+
my $error_message = l('You cannot remove the attribute “{name}” because it is the parent of other attributes.', { name => $attr->name });
133+
134+
$c->stash(
135+
current_view => 'Node',
136+
component_path => 'admin/attributes/CannotRemoveAttribute',
137+
component_props => {message => $error_message}
138+
);
139+
128140
$c->detach;
129141
}
130-
131142
if ($c->form_posted_and_valid($form)) {
132143
$c->model('MB')->with_transaction(sub {
133144
$c->model($model)->delete($id);

lib/MusicBrainz/Server/Data/Role/Attribute.pm

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ sub _column_mapping {
1919
};
2020
}
2121

22+
sub has_children {
23+
my ($self, $id) = @_;
24+
return $self->sql->select_single_value(
25+
'SELECT 1 FROM ' . $self->_table . ' WHERE parent = ? LIMIT 1',
26+
$id);
27+
}
28+
2229
no Moose;
2330
1;
2431

0 commit comments

Comments
 (0)