@@ -5,6 +5,7 @@ use Try::Tiny;
5
5
BEGIN { extends ' MusicBrainz::Server::Controller' };
6
6
7
7
use MusicBrainz::Server::Translation qw( l ln ) ;
8
+ use MusicBrainz::Server::Data::Utils qw( boolean_to_json ) ;
8
9
9
10
sub edit_user : Path(' /admin/user/edit' ) Args(1) RequireAuth HiddenOnSlaves SecureForm
10
11
{
@@ -202,6 +203,64 @@ sub ip_lookup : Path('/admin/ip-lookup') Args(1) RequireAuth(account_admin) Hidd
202
203
);
203
204
}
204
205
206
+ sub locked_username_search : Path(' /admin/locked-usernames/search' ) Args(0) RequireAuth(account_admin) HiddenOnSlaves {
207
+ my ($self , $c ) = @_ ;
208
+
209
+ my $form = $c -> form(form => ' Admin::LockedUsernameSearch' );
210
+ my @results ;
211
+ my $show_results = 0;
212
+
213
+ if ($c -> form_posted_and_valid($form , $c -> req-> body_params)) {
214
+ try {
215
+ @results = $c -> model(' Editor' )-> search_old_editor_names(
216
+ $form -> field(' username' )-> value // ' ' ,
217
+ $form -> field(' use_regular_expression' )-> value,
218
+ );
219
+ $show_results = 1;
220
+ } catch {
221
+ my $error = $_ ;
222
+ if (" $error " =~ m / invalid regular expression/ ) {
223
+ $form -> field(' username' )-> add_error(l(' Invalid regular expression.' ));
224
+ $c -> response-> status(400);
225
+ } else {
226
+ die $error ;
227
+ }
228
+ };
229
+ }
230
+
231
+ $c -> stash(
232
+ current_view => ' Node' ,
233
+ component_path => ' admin/LockedUsernameSearch' ,
234
+ component_props => {
235
+ form => $form -> TO_JSON,
236
+ @results ? (results => \@results ) : (),
237
+ showResults => boolean_to_json($show_results ),
238
+ },
239
+ );
240
+ }
241
+
242
+ sub unlock_username : Path(' /admin/locked-usernames/unlock' ) Args(1) RequireAuth(account_admin) HiddenOnSlaves {
243
+ my ($self , $c , $username ) = @_ ;
244
+
245
+ my $form = $c -> form(form => ' SecureConfirm' );
246
+
247
+ if ($c -> form_posted_and_valid($form )) {
248
+ $c -> model(' MB' )-> with_transaction(sub {
249
+ $c -> model(' Editor' )-> unlock_old_editor_name($username );
250
+ });
251
+ $c -> response-> redirect($c -> uri_for_action(' /admin/locked_username_search' ));
252
+ }
253
+
254
+ $c -> stash(
255
+ current_view => ' Node' ,
256
+ component_path => ' admin/LockedUsernameUnlock' ,
257
+ component_props => {
258
+ form => $form -> TO_JSON,
259
+ username => $username ,
260
+ },
261
+ );
262
+ }
263
+
205
264
1;
206
265
207
266
=head1 COPYRIGHT AND LICENSE
0 commit comments