aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-03-09 17:32:30 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-03-09 17:32:30 +0000
commit7074b5713d08636589be1682dcd31cd3d7542638 (patch)
treed9c2304d774f1170dc42eaf8817212bfd1ef3f3d
parent342b4ecff061fb11d47162389407ba58d6ac3d68 (diff)
parent286b4cb512c1e2d8c817318a2f082191efb39625 (diff)
Merge branch 'issues/forcouncils/174-dupe-user-tweaks'
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm40
1 files changed, 22 insertions, 18 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index a7b9fb169..87a4191af 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -789,11 +789,9 @@ sub report_edit : Path('report_edit') : Args(1) {
$c->forward( '/admin/report_edit_category', [ $problem ] );
- if ( $c->get_param('email') ne $problem->user->email ) {
- my $user = $c->model('DB::User')->find_or_create(
- { email => $c->get_param('email') }
- );
-
+ my $email = lc $c->get_param('email');
+ if ( $email ne $problem->user->email ) {
+ my $user = $c->model('DB::User')->find_or_create({ email => $email });
$user->insert unless $user->in_storage;
$problem->user( $user );
}
@@ -1117,8 +1115,9 @@ sub update_edit : Path('update_edit') : Args(1) {
# $update->name can be null which makes ne unhappy
my $name = $update->name || '';
+ my $email = lc $c->get_param('email');
if ( $c->get_param('name') ne $name
- || $c->get_param('email') ne $update->user->email
+ || $email ne $update->user->email
|| $c->get_param('anonymous') ne $update->anonymous
|| $c->get_param('text') ne $update->text ) {
$edited = 1;
@@ -1138,11 +1137,8 @@ sub update_edit : Path('update_edit') : Args(1) {
$update->anonymous( $c->get_param('anonymous') );
$update->state( $new_state );
- if ( $c->get_param('email') ne $update->user->email ) {
- my $user =
- $c->model('DB::User')
- ->find_or_create( { email => $c->get_param('email') } );
-
+ if ( $email ne $update->user->email ) {
+ my $user = $c->model('DB::User')->find_or_create({ email => $email });
$user->insert unless $user->in_storage;
$update->user($user);
}
@@ -1207,7 +1203,7 @@ sub user_add : Path('user_edit') : Args(0) {
my $user = $c->model('DB::User')->find_or_create( {
name => $c->get_param('name'),
- email => $c->get_param('email'),
+ email => lc $c->get_param('email'),
phone => $c->get_param('phone') || undef,
from_body => $c->get_param('body') || undef,
flagged => $c->get_param('flagged') || 0,
@@ -1257,7 +1253,8 @@ sub user_edit : Path('user_edit') : Args(1) {
my $edited = 0;
- if ( $user->email ne $c->get_param('email') ||
+ my $email = lc $c->get_param('email');
+ if ( $user->email ne $email ||
$user->name ne $c->get_param('name') ||
($user->phone || "") ne $c->get_param('phone') ||
($user->from_body && $c->get_param('body') && $user->from_body->id ne $c->get_param('body')) ||
@@ -1267,7 +1264,8 @@ sub user_edit : Path('user_edit') : Args(1) {
}
$user->name( $c->get_param('name') );
- $user->email( $c->get_param('email') );
+ my $original_email = $user->email;
+ $user->email( $email );
$user->phone( $c->get_param('phone') ) if $c->get_param('phone');
$user->flagged( $c->get_param('flagged') || 0 );
# Only superusers can grant superuser status
@@ -1368,11 +1366,17 @@ sub user_edit : Path('user_edit') : Args(1) {
return if %{$c->stash->{field_errors}};
my $existing_user = $c->model('DB::User')->search({ email => $user->email, id => { '!=', $user->id } })->first;
- if ($existing_user) {
+ my $existing_user_cobrand = $c->cobrand->users->search({ email => $user->email, id => { '!=', $user->id } })->first;
+ if ($existing_user_cobrand) {
$existing_user->adopt($user);
$c->forward( 'log_edit', [ $id, 'user', 'merge' ] );
$c->res->redirect( $c->uri_for( 'user_edit', $existing_user->id ) );
} else {
+ if ($existing_user) {
+ # Tried to change email to an existing one lacking permission
+ # so make sure it's switched back
+ $user->email($original_email);
+ }
$user->update;
if ($edited) {
$c->forward( 'log_edit', [ $id, 'user', 'edit' ] );
@@ -1627,7 +1631,7 @@ accordingly
sub ban_user : Private {
my ( $self, $c ) = @_;
- my $email = $c->get_param('email');
+ my $email = lc $c->get_param('email');
return unless $email;
@@ -1654,7 +1658,7 @@ Sets the flag on a user with the given email
sub flag_user : Private {
my ( $self, $c ) = @_;
- my $email = $c->get_param('email');
+ my $email = lc $c->get_param('email');
return unless $email;
@@ -1682,7 +1686,7 @@ Remove the flag on a user with the given email
sub remove_user_flag : Private {
my ( $self, $c ) = @_;
- my $email = $c->get_param('email');
+ my $email = lc $c->get_param('email');
return unless $email;