aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-09-27 14:46:46 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-09-30 15:04:06 +0100
commitc7d98f98bf4faa1a60552dd11195eb134445b6b3 (patch)
tree47028cce45ce2ac77c5208f18bdb02b45d7220c2
parentd0ae2a420905dbd0b79141d88e2c47956d1d65b2 (diff)
Adapt things that assume email will be present.
This includes stopping some emails being sent (moderation, alert, questionnaire), dealing with Open311/email report sending, and tokenised_url.
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Moderate.pm28
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm11
-rw-r--r--perllib/FixMyStreet/Script/Alerts.pm20
-rw-r--r--perllib/FixMyStreet/Script/Questionnaires.pm6
-rw-r--r--perllib/FixMyStreet/Script/Reports.pm4
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm11
-rw-r--r--perllib/Open311.pm12
-rw-r--r--templates/email/default/submit.html8
-rw-r--r--templates/email/default/submit.txt6
-rw-r--r--templates/email/fiksgatami/nn/submit.txt6
-rw-r--r--templates/email/fiksgatami/submit.txt6
-rw-r--r--templates/email/fixamingata/submit.html8
-rw-r--r--templates/email/fixamingata/submit.txt6
-rw-r--r--templates/email/fixmystreet.com/submit.html8
-rw-r--r--templates/email/fixmystreet.com/submit.txt6
16 files changed, 103 insertions, 46 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm
index a6a6378da..0b156ddd3 100644
--- a/perllib/FixMyStreet/App/Controller/Auth.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth.pm
@@ -216,7 +216,8 @@ sub token : Path('/M') : Args(1) {
$c->stash->{token_not_found} = 1, return
if $data->{old_email} && (!$c->user_exists || $c->user->email ne $data->{old_email});
- $c->detach( '/auth/process_login', [ $data, 'email' ] );
+ my $type = $data->{login_type} || 'email';
+ $c->detach( '/auth/process_login', [ $data, $type ] );
}
sub process_login : Private {
diff --git a/perllib/FixMyStreet/App/Controller/Moderate.pm b/perllib/FixMyStreet/App/Controller/Moderate.pm
index e2ab16b6b..1313b5071 100644
--- a/perllib/FixMyStreet/App/Controller/Moderate.pm
+++ b/perllib/FixMyStreet/App/Controller/Moderate.pm
@@ -106,19 +106,21 @@ sub report_moderate_audit : Private {
reason => (sprintf '%s (%s)', $reason, $types_csv),
});
- my $token = $c->model("DB::Token")->create({
- scope => 'moderation',
- data => { id => $problem->id }
- });
-
- $c->send_email( 'problem-moderated.txt', {
- to => [ [ $problem->user->email, $problem->name ] ],
- types => $types_csv,
- user => $problem->user,
- problem => $problem,
- report_uri => $c->stash->{report_uri},
- report_complain_uri => $c->stash->{cobrand_base} . '/contact?m=' . $token->token,
- });
+ if ($problem->user->email_verified) {
+ my $token = $c->model("DB::Token")->create({
+ scope => 'moderation',
+ data => { id => $problem->id }
+ });
+
+ $c->send_email( 'problem-moderated.txt', {
+ to => [ [ $problem->user->email, $problem->name ] ],
+ types => $types_csv,
+ user => $problem->user,
+ problem => $problem,
+ report_uri => $c->stash->{report_uri},
+ report_complain_uri => $c->stash->{cobrand_base} . '/contact?m=' . $token->token,
+ });
+ }
}
sub report_moderate_hide : Private {
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index b954a68ab..56601480d 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -485,12 +485,21 @@ Return a url for this problem report that logs a user in
sub tokenised_url {
my ($self, $user, $params) = @_;
+ my %params;
+ if ($user->email_verified) {
+ $params{email} = $user->email;
+ } elsif ($user->phone_verified) {
+ $params{phone} = $user->phone;
+ # This is so the email token can look up/ log in a phone user
+ $params{login_type} = 'phone';
+ }
+
my $token = FixMyStreet::App->model('DB::Token')->create(
{
scope => 'email_sign_in',
data => {
+ %params,
id => $self->id,
- email => $user->email,
r => $self->url,
p => $params,
}
diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm
index c001cc311..86f11c7b5 100644
--- a/perllib/FixMyStreet/Script/Alerts.pm
+++ b/perllib/FixMyStreet/Script/Alerts.pm
@@ -109,7 +109,7 @@ sub send() {
my $user = $schema->resultset('User')->find( {
id => $row->{alert_user_id}
} );
- $data{alert_email} = $user->email;
+ $data{alert_user} = $user;
my $token_obj = $schema->resultset('Token')->create( {
scope => 'alert_to_reporter',
data => {
@@ -209,7 +209,7 @@ sub send() {
template => $template,
data => [],
alert_id => $alert->id,
- alert_email => $alert->user->email,
+ alert_user => $alert->user,
lang => $alert->lang,
cobrand => $cobrand,
cobrand_data => $alert->cobrand_data,
@@ -258,16 +258,20 @@ sub _send_aggregated_alert_email(%) {
$cobrand->set_lang_and_domain( $data{lang}, 1, FixMyStreet->path_to('locale')->stringify );
FixMyStreet::Map::set_map_class($cobrand->map_type);
- if (!$data{alert_email}) {
+ if (!$data{alert_user}) {
my $user = $data{schema}->resultset('User')->find( {
id => $data{alert_user_id}
} );
- $data{alert_email} = $user->email;
+ $data{alert_user} = $user;
}
- my ($domain) = $data{alert_email} =~ m{ @ (.*) \z }x;
+ # Ignore phone-only users
+ return unless $data{alert_user}->email_verified;
+
+ my $email = $data{alert_user}->email;
+ my ($domain) = $email =~ m{ @ (.*) \z }x;
return if $data{schema}->resultset('Abuse')->search( {
- email => [ $data{alert_email}, $domain ]
+ email => [ $email, $domain ]
} )->first;
my $token = $data{schema}->resultset("Token")->new_result( {
@@ -275,7 +279,7 @@ sub _send_aggregated_alert_email(%) {
data => {
id => $data{alert_id},
type => 'unsubscribe',
- email => $data{alert_email},
+ email => $email,
}
} );
$data{unsubscribe_url} = $cobrand->base_url( $data{cobrand_data} ) . '/A/' . $token->token;
@@ -286,7 +290,7 @@ sub _send_aggregated_alert_email(%) {
"$data{template}.txt",
\%data,
{
- To => $data{alert_email},
+ To => $email,
},
$sender,
0,
diff --git a/perllib/FixMyStreet/Script/Questionnaires.pm b/perllib/FixMyStreet/Script/Questionnaires.pm
index ec6139d2d..5fc01512d 100644
--- a/perllib/FixMyStreet/Script/Questionnaires.pm
+++ b/perllib/FixMyStreet/Script/Questionnaires.pm
@@ -49,7 +49,11 @@ sub send_questionnaires_period {
# Not all cobrands send questionnaires
next unless $cobrand->send_questionnaires;
- next if $row->is_from_abuser;
+
+ if ($row->is_from_abuser || !$row->user->email_verified) {
+ $row->update( { send_questionnaire => 0 } );
+ next;
+ }
# Cobranded and non-cobranded messages can share a database. In this case, the conf file
# should specify a vhost to send the reports for each cobrand, so that they don't get sent
diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm
index 1e5fd55bb..1ea98342c 100644
--- a/perllib/FixMyStreet/Script/Reports.pm
+++ b/perllib/FixMyStreet/Script/Reports.pm
@@ -84,7 +84,6 @@ sub send(;$) {
$h{query} = $row->postcode;
$h{url} = $email_base_url . $row->url;
$h{admin_url} = $row->admin_url($cobrand);
- $h{phone_line} = $h{phone} ? _('Phone:') . " $h{phone}\n\n" : '';
if ($row->photo) {
$h{has_photo} = _("This web page also contains a photo of the problem, provided by the user.") . "\n\n";
$h{image_url} = $email_base_url . $row->photos->[0]->{url_full};
@@ -299,6 +298,9 @@ sub _send_report_sent_email {
my $nomail = shift;
my $cobrand = shift;
+ # Don't send 'report sent' text
+ return unless $row->user->email_verified;
+
FixMyStreet::Email::send_cron(
$row->result_source->schema,
'confirm_report_sent.txt',
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index eefb14553..0aacc14a1 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -74,14 +74,21 @@ sub send {
my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new();
my $params = {
To => $self->to,
- From => $self->send_from( $row ),
};
$cobrand->call_hook(munge_sendreport_params => $row, $h, $params);
$params->{Bcc} = $self->bcc if @{$self->bcc};
- my $sender = FixMyStreet::Email::unique_verp_id('report', $row->id);
+ my $sender;
+ if ($row->user->email && $row->user->email_verified) {
+ $sender = FixMyStreet::Email::unique_verp_id('report', $row->id);
+ $params->{From} = $self->send_from( $row );
+ } else {
+ $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL');
+ my $name = sprintf(_("On behalf of %s"), $params->{From}[1]);
+ $params->{From} = [ $sender, $name ];
+ }
if (FixMyStreet::Email::test_dmarc($params->{From}[0])
|| Utils::Email::same_domain($params->{From}, $params->{To})) {
diff --git a/perllib/Open311.pm b/perllib/Open311.pm
index da5a0a377..90b593256 100644
--- a/perllib/Open311.pm
+++ b/perllib/Open311.pm
@@ -127,13 +127,15 @@ sub _populate_service_request_params {
my ( $firstname, $lastname ) = ( $problem->name =~ /(\w+)\.?\s+(.+)/ );
my $params = {
- email => $problem->user->email,
description => $description,
service_code => $service_code,
first_name => $firstname,
last_name => $lastname || '',
};
+ $params->{phone} = $problem->user->phone if $problem->user->phone;
+ $params->{email} = $problem->user->email if $problem->user->email;
+
# if you click nearby reports > skip map then it's possible
# to end up with used_map = f and nothing in postcode
if ( $problem->used_map || $self->always_send_latlong
@@ -153,10 +155,6 @@ sub _populate_service_request_params {
$params->{address_string} = $problem->postcode;
}
- if ( $problem->user->phone ) {
- $params->{ phone } = $problem->user->phone;
- }
-
if ( $extra->{image_url} ) {
$params->{media_url} = $extra->{image_url};
}
@@ -327,12 +325,14 @@ sub _populate_service_request_update_params {
updated_datetime => DateTime::Format::W3CDTF->format_datetime($comment->confirmed->set_nanosecond(0)),
service_request_id => $comment->problem->external_id,
status => $status,
- email => $comment->user->email,
description => $comment->text,
last_name => $lastname,
first_name => $firstname,
};
+ $params->{phone} = $comment->user->phone if $comment->user->phone;
+ $params->{email} = $comment->user->email if $comment->user->email;
+
if ( $self->use_extended_updates ) {
$params->{public_anonymity_required} = $comment->anonymous ? 'TRUE' : 'FALSE',
$params->{update_id_ext} = $comment->id;
diff --git a/templates/email/default/submit.html b/templates/email/default/submit.html
index 85511b2e4..582670f98 100644
--- a/templates/email/default/submit.html
+++ b/templates/email/default/submit.html
@@ -27,7 +27,13 @@ of a local problem that they believe might require your attention.</p>
</tr>
<tr>
<th style="[% contact_th_style %]">Email</th>
- <td style="[% contact_td_style %]"><a href="mailto:[% email | html %]">[% email | html %]</a></td>
+ <td style="[% contact_td_style %]">
+ [%~ IF email ~%]
+ <a href="mailto:[% email | html %]">[% email | html %]</a>
+ [%~ ELSE ~%]
+ <strong>No email address provided, only phone number</strong>
+ [%~ END ~%]
+ </td>
</tr>
[%~ IF phone %]
<tr>
diff --git a/templates/email/default/submit.txt b/templates/email/default/submit.txt
index 5d79f3b41..8c88a17f8 100644
--- a/templates/email/default/submit.txt
+++ b/templates/email/default/submit.txt
@@ -15,9 +15,11 @@ please visit the following link:
Name: [% name %]
-Email: [% email %]
+Email: [% email OR "None provided" %]
-[% phone_line %][% category_line %]Subject: [% title %]
+Phone: [% phone OR "None provided" %]
+
+[% category_line %]Subject: [% title %]
Details: [% detail %]
diff --git a/templates/email/fiksgatami/nn/submit.txt b/templates/email/fiksgatami/nn/submit.txt
index 32a895632..dfbdd9457 100644
--- a/templates/email/fiksgatami/nn/submit.txt
+++ b/templates/email/fiksgatami/nn/submit.txt
@@ -15,9 +15,11 @@ problemet, ver venleg og besøk følgjande lenkje:
Namn: [% name %]
-E-post: [% email %]
+E-post: [% email OR '-' %]
-[% phone_line %][% category_line %]Tema: [% title %]
+Telefon: [% phone OR '-' %]
+
+[% category_line %]Tema: [% title %]
Detaljer: [% detail %]
diff --git a/templates/email/fiksgatami/submit.txt b/templates/email/fiksgatami/submit.txt
index a0e0687eb..165b804f1 100644
--- a/templates/email/fiksgatami/submit.txt
+++ b/templates/email/fiksgatami/submit.txt
@@ -15,9 +15,11 @@ vennligst besøk følgende lenke:
Navn: [% name %]
-E-post: [% email %]
+E-post: [% email OR '-' %]
-[% phone_line %][% category_line %]Tema: [% title %]
+Telefon: [% phone OR '-' %]
+
+[% category_line %]Tema: [% title %]
Detajer: [% detail %]
diff --git a/templates/email/fixamingata/submit.html b/templates/email/fixamingata/submit.html
index da4e7f48f..dfc56589a 100644
--- a/templates/email/fixamingata/submit.html
+++ b/templates/email/fixamingata/submit.html
@@ -27,8 +27,14 @@ tror medborgaren behöver er uppmärksamhet.</p>
</tr>
<tr>
<th style="[% contact_th_style %]">Epost</th>
- <td style="[% contact_td_style %]"><a href="mailto:[% email | html %]">[% email | html %]</a></td>
+ <td style="[% contact_td_style %]">
+ [%~ IF email ~%]
+ <a href="mailto:[% email | html %]">[% email | html %]</a>
+ [%~ ELSE ~%]
+ [%~ END ~%]
+ </td>
</tr>
+ [% END %]
[%~ IF phone %]
<tr>
<th style="[% contact_th_style %]">Telefon</th>
diff --git a/templates/email/fixamingata/submit.txt b/templates/email/fixamingata/submit.txt
index 95365b87e..fc8b65886 100644
--- a/templates/email/fixamingata/submit.txt
+++ b/templates/email/fixamingata/submit.txt
@@ -16,9 +16,11 @@ tror medborgaren behöver er uppmärksamhet.
Namn: [% name %]
-Epost: [% email %]
+Epost: [% email OR '-' %]
-[% phone_line %]** Information om ärendet
+Telefonnummer: [% phone OR '-' %]
+
+** Information om ärendet
ID: [% id %]
diff --git a/templates/email/fixmystreet.com/submit.html b/templates/email/fixmystreet.com/submit.html
index fc2b6c095..22e025085 100644
--- a/templates/email/fixmystreet.com/submit.html
+++ b/templates/email/fixmystreet.com/submit.html
@@ -27,7 +27,13 @@ of a local problem that they believe might require your attention.</p>
</tr>
<tr>
<th style="[% contact_th_style %]">Email</th>
- <td style="[% contact_td_style %]"><a href="mailto:[% email | html %]">[% email | html %]</a></td>
+ <td style="[% contact_td_style %]">
+ [%~ IF email ~%]
+ <a href="mailto:[% email | html %]">[% email | html %]</a>
+ [%~ ELSE ~%]
+ <strong>No email address provided, only phone number</strong>
+ [%~ END ~%]
+ </td>
</tr>
[%~ IF phone %]
<tr>
diff --git a/templates/email/fixmystreet.com/submit.txt b/templates/email/fixmystreet.com/submit.txt
index aa05316bf..5a0845b14 100644
--- a/templates/email/fixmystreet.com/submit.txt
+++ b/templates/email/fixmystreet.com/submit.txt
@@ -15,9 +15,11 @@ please visit the following link:
Name: [% name %]
-Email: [% email %]
+Email: [% email OR 'None provided' %]
-[% phone_line %][% category_line %]Subject: [% title %]
+Phone: [% phone OR 'None provided' %]
+
+[% category_line %]Subject: [% title %]
Details: [% detail %]