File tree 5 files changed +60
-5
lines changed
5 files changed +60
-5
lines changed Original file line number Diff line number Diff line change 1
1
package MusicBrainz::Server::Controller::Admin::Attributes ;
2
2
use Moose;
3
3
4
+ use MusicBrainz::Server::Translation qw( l ln ) ;
5
+
4
6
no if $] >= 5.018, warnings => " experimental::smartmatch" ;
5
7
6
8
BEGIN { extends ' MusicBrainz::Server::Controller' };
@@ -115,10 +117,28 @@ sub delete : Chained('attribute_base') Args(1) RequireAuth(account_admin) Secure
115
117
$c -> stash-> {attribute } = $attr ;
116
118
117
119
if ($c -> model($model )-> in_use($id )) {
118
- $c -> stash-> {template } = ' admin/attributes/in_use.tt' ;
120
+ my $error_message = l(' You cannot remove the attribute "{name}" because it is still in use.' , { name => $attr -> name });
121
+
122
+ $c -> stash(
123
+ current_view => ' Node' ,
124
+ component_path => ' admin/attributes/CannotRemoveAttribute' ,
125
+ component_props => {message => $error_message }
126
+ );
127
+
119
128
$c -> detach;
120
129
}
121
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
+
140
+ $c -> detach;
141
+ }
122
142
if ($c -> form_posted_and_valid($form )) {
123
143
$c -> model(' MB' )-> with_transaction(sub {
124
144
$c -> model($model )-> delete ($id );
Original file line number Diff line number Diff line change @@ -19,6 +19,13 @@ sub _column_mapping {
19
19
};
20
20
}
21
21
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
+
22
29
no Moose;
23
30
1;
24
31
Original file line number Diff line number Diff line change
1
+ /*
2
+ * @flow strict-local
3
+ * Copyright (C) 2021 MetaBrainz Foundation
4
+ *
5
+ * This file is part of MusicBrainz, the open internet music database,
6
+ * and is licensed under the GPL version 2, or (at your option) any
7
+ * later version: http://www.gnu.org/licenses/gpl-2.0.txt
8
+ */
9
+
10
+ import * as React from 'react' ;
11
+
12
+ import Layout from '../../layout' ;
13
+
14
+ type Props = {
15
+ + $c : CatalystContextT ,
16
+ + message : string ,
17
+ } ;
18
+
19
+ const CannotRemoveAttribute = ( {
20
+ $c,
21
+ message,
22
+ } : Props ) : React . Element < typeof Layout > => (
23
+ < Layout $c = { $c } fullWidth title = { l ( 'Cannot Remove Attribute' ) } >
24
+ < h1 > { l ( 'Cannot Remove Attribute' ) } </ h1 >
25
+ < p >
26
+ { message }
27
+ </ p >
28
+ </ Layout >
29
+ ) ;
30
+
31
+ export default CannotRemoveAttribute ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ module.exports = {
39
39
'admin/EmailSearch' : require ( '../admin/EmailSearch' ) ,
40
40
'admin/IpLookup' : require ( '../admin/IpLookup' ) ,
41
41
'admin/attributes/Attribute' : require ( '../admin/attributes/Attribute' ) ,
42
+ 'admin/attributes/CannotRemoveAttribute' : require ( '../admin/attributes/CannotRemoveAttribute' ) ,
42
43
'admin/attributes/Index' : require ( '../admin/attributes/Index' ) ,
43
44
'admin/attributes/Language' : require ( '../admin/attributes/Language' ) ,
44
45
'admin/attributes/Script' : require ( '../admin/attributes/Script' ) ,
You can’t perform that action at this time.
0 commit comments