From 7d9117e6474604bdacb68be31602c62bada8d1b2 Mon Sep 17 00:00:00 2001 From: Karen Etheridge Date: Mon, 18 Jan 2021 15:32:19 -0800 Subject: [PATCH] if a user's email address is changed, also send an email to the old address --- lib/Conch/Controller/User.pm | 11 +++++++++++ t/integration/users.t | 18 +++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/Conch/Controller/User.pm b/lib/Conch/Controller/User.pm index 784fd4ad2..b09273c4b 100644 --- a/lib/Conch/Controller/User.pm +++ b/lib/Conch/Controller/User.pm @@ -409,6 +409,17 @@ sub update ($c) { orig_data => \%orig_columns, new_data => \%dirty_columns, ); + + # also send to old email address, if it was changed! + $c->send_mail( + template_file => 'updated_user_account', + From => 'noreply', + To => '"'.$orig_columns{name}.'" <'.$orig_columns{email}.'>', + Subject => 'Your Conch account has been updated', + orig_data => \%orig_columns, + new_data => \%dirty_columns, + ) + if exists $dirty_columns{email} and fc $input->{email} ne fc $orig_columns{email}; } $c->log->debug('updating user '.$user->email.': '.$c->req->text); diff --git a/t/integration/users.t b/t/integration/users.t index 8bbaf253c..38fe1ef4b 100644 --- a/t/integration/users.t +++ b/t/integration/users.t @@ -183,15 +183,23 @@ subtest 'User' => sub { { email => 'cONcH@cONCh.joyent.us' }, { name => 'conch' }; - $t->post_ok('/user/me', json => { email => 'rO_USer@cONCh.joyent.us', name => 'rO_USer' }) + $t->post_ok('/user/me', json => { email => 'rO_USer_new@cONCh.joyent.us', name => 'rO_USer' }) ->status_is(204) ->location_is('/user/'.$ro_user->id) - ->email_cmp_deeply({ - To => '"rO_USer" ', + ->email_cmp_deeply([ + { + To => '"rO_USer" ', From => 'noreply@joyent.com', Subject => 'Your Conch account has been updated', - body => re(qr/^Your account at \Q$JOYENT\E has been updated:\R\R {7}email: ro_user\@conch.joyent.us -> rO_USer\@cONCh.joyent.us\R {8}name: ro_user -> rO_USer\R\R/m), - }); + body => re(qr/^Your account at \Q$JOYENT\E has been updated:\R\R {7}email: ro_user\@conch.joyent.us -> rO_USer_new\@cONCh.joyent.us\R {8}name: ro_user -> rO_USer\R\R/m), + }, + { + To => '"ro_user" ', + From => 'noreply@joyent.com', + Subject => 'Your Conch account has been updated', + body => re(qr/^Your account at \Q$JOYENT\E has been updated:\R\R {7}email: ro_user\@conch.joyent.us -> rO_USer_new\@cONCh.joyent.us\R {8}name: ro_user -> rO_USer\R\R/m), + }, + ]); $ro_user->discard_changes;