Skip to content

Commit

Permalink
Fix allows admin to edit user with verified landline
Browse files Browse the repository at this point in the history
#3295

* Stops validation of phone number on user edit
if edit does not change phone number

* Adds test to check changing name does not
revalidate phone number so edit is successful

* Adds test to check that changing the number
revalidates the phone number
  • Loading branch information
MorayMySoc committed Jul 9, 2021
1 parent 6938275 commit 728d20a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Fix moderation of update text.
- Only trigger one refresh going Back to list view. #3476
- Fix checked order of updates in dashboard export.
- Fix not able to edit user with verified landline #3295
- Admin improvements:
- Enable per-category hint customisation.
- Move ban/unban buttons to user edit admin page.
Expand Down
3 changes: 2 additions & 1 deletion perllib/FixMyStreet/App/Controller/Admin/Users.pm
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ sub edit : Chained('user') : PathPart('') : Args(0) {
$c->stash->{field_errors}->{email} = _('Please enter a valid email');
}

if ($phone_v) {
if ($phone_v && ($phone ne $user->phone)) {
my $parsed_phone = $c->forward('phone_check', [ $phone ]);
$phone = $parsed_phone if $parsed_phone;
}
Expand All @@ -276,6 +276,7 @@ sub edit : Chained('user') : PathPart('') : Args(0) {
my $existing_email_cobrand = $email_v && $c->cobrand->users->search($email_params)->first;
my $existing_phone_cobrand = $phone_v && $c->cobrand->users->search($phone_params)->first;
my $existing_user_cobrand = $existing_email_cobrand || $existing_phone_cobrand;

if ($existing_phone_cobrand && $existing_email_cobrand && $existing_email_cobrand->id != $existing_phone_cobrand->id) {
$c->stash->{field_errors}->{username} = _('User already exists');
}
Expand Down
20 changes: 20 additions & 0 deletions t/app/controller/admin/users.t
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,26 @@ FixMyStreet::override_config {
$mech->content_contains( 'Updated!' );
};

subtest "Test edit user name who has verified landline" => sub {
my $existing_user = $mech->create_user_ok('[email protected]', name => 'Existing User', phone => '01184960017', phone_verified => 1 );
$mech->get_ok( '/admin/users/' . $existing_user->id );
$mech->submit_form_ok( { with_fields => {
name => 'Existing E. User',
} } );
$mech->content_contains( 'Updated!' );
};

subtest "Test edit user number who has verified landline" => sub {
my $existing_user = $mech->create_user_ok('[email protected]', name => 'Existing User', phone => '01184960017', phone_verified => 1 );
$mech->get_ok( '/admin/users/' . $existing_user->id );
$mech->submit_form_ok( { with_fields => {
phone => '01184960018',
} } );
$mech->content_lacks( 'Updated!' );
};



subtest "Test changing user to an existing one" => sub {
my $existing_user = $mech->create_user_ok('[email protected]', name => 'Existing User');
$mech->create_problems_for_body(2, 2514, 'Title', { user => $existing_user });
Expand Down

0 comments on commit 728d20a

Please sign in to comment.