Skip to content

Commit ca55ce9

Browse files
committed
MBS-9426: Allow removing usernames from locked list
1 parent 7ac3389 commit ca55ce9

File tree

6 files changed

+92
-1
lines changed

6 files changed

+92
-1
lines changed

lib/MusicBrainz/Server/Controller/Admin.pm

+22
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,28 @@ sub locked_username_search : Path('/admin/locked-usernames/search') Args(0) Requ
239239
);
240240
}
241241

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+
242264
1;
243265

244266
=head1 COPYRIGHT AND LICENSE

lib/MusicBrainz/Server/Data/Editor.pm

+8
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,14 @@ sub search_old_editor_names {
274274
@{ $self->sql->select_single_column_array($query, $name) };
275275
}
276276

277+
sub unlock_old_editor_name {
278+
my ($self, $name) = @_;
279+
280+
my $query = "DELETE FROM old_editor_name WHERE name = ?";
281+
282+
$self->sql->do($query, $name);
283+
}
284+
277285
sub update_email
278286
{
279287
my ($self, $editor, $email) = @_;

root/admin/LockedUsernameSearch.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import FormRowText from '../components/FormRowText';
1414
import FormSubmit from '../components/FormSubmit';
1515
import Layout from '../layout';
1616
import expand2react from '../static/scripts/common/i18n/expand2react';
17+
import bracketed from '../static/scripts/common/utility/bracketed';
1718

1819
type Props = {
1920
+form: FormT<{
@@ -71,7 +72,15 @@ const LockedUsernameSearch = ({
7172
{results?.length ? (
7273
<ul>
7374
{results.map(result => (
74-
<li key={result}>{result}</li>
75+
<li key={result}>
76+
{result}
77+
{' '}
78+
{bracketed(
79+
<a href={`/admin/locked-usernames/unlock/${result}`}>
80+
{'unlock'}
81+
</a>,
82+
)}
83+
</li>
7584
))}
7685
</ul>
7786
) : (

root/admin/LockedUsernameUnlock.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 FormCsrfToken from '../components/FormCsrfToken';
13+
import FormSubmit from '../components/FormSubmit';
14+
import Layout from '../layout';
15+
import expand2text from '../static/scripts/common/i18n/expand2text';
16+
17+
type Props = {
18+
+$c: CatalystContextT,
19+
+form: SecureConfirmFormT,
20+
+username: string,
21+
};
22+
23+
const LockedUsernameUnlock = ({
24+
$c,
25+
form,
26+
username,
27+
}: Props): React.Element<typeof Layout> => (
28+
<Layout fullWidth title="Unlock username">
29+
<div id="content">
30+
<h1>{'Unlock username'}</h1>
31+
<p>
32+
{expand2text(
33+
`Are you sure you wish to unlock
34+
the username “{username}” for reuse?`,
35+
{username: username},
36+
)}
37+
</p>
38+
<form action={$c.req.uri} method="post" name="confirm">
39+
<FormCsrfToken form={form} />
40+
<FormSubmit
41+
label="Yes, I’m sure"
42+
name="confirm.submit"
43+
value="1"
44+
/>
45+
</form>
46+
</div>
47+
</Layout>
48+
);
49+
50+
export default LockedUsernameUnlock;

root/server/components.js

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ module.exports = {
3939
'admin/EmailSearch': require('../admin/EmailSearch'),
4040
'admin/IpLookup': require('../admin/IpLookup'),
4141
'admin/LockedUsernameSearch': require('../admin/LockedUsernameSearch'),
42+
'admin/LockedUsernameUnlock': require('../admin/LockedUsernameUnlock'),
4243
'admin/attributes/Attribute': require('../admin/attributes/Attribute'),
4344
'admin/attributes/CannotRemoveAttribute': require('../admin/attributes/CannotRemoveAttribute'),
4445
'admin/attributes/Index': require('../admin/attributes/Index'),

t/lib/t/MusicBrainz/Server/Controller/UnconfirmedEmailAddresses.pm

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ test 'Paths that allow browsing without a confirmed email address' => sub {
9191
'Controller::Admin::email_search',
9292
'Controller::Admin::ip_lookup',
9393
'Controller::Admin::locked_username_search',
94+
'Controller::Admin::unlock_username',
9495
'Controller::Ajax::filter_artist_recordings_form',
9596
'Controller::Ajax::filter_artist_release_groups_form',
9697
'Controller::Ajax::filter_artist_releases_form',

0 commit comments

Comments
 (0)