aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZarino Zappia <mail@zarino.co.uk>2019-08-20 11:16:53 +0100
committerZarino Zappia <mail@zarino.co.uk>2019-08-23 10:38:29 +0100
commit3c4d48f5fd5f499736f07ac2a5d17c1d4bab6c14 (patch)
tree59df44c764e803c679c01f17296a01fdb7813619
parent169c8960d9c32e35f5a2603c611857757d8b1044 (diff)
Include user admin links in contact form emails
If a message is sent via the contact form, with a stated email address matching a user in the database, the resulting email will now include quick links to: - Admin page for editing the user - Admin page for viewing the user’s reports And if the user has made at least one report, also: - Admin page for the user’s most recent report This should speed up admin email triage considerably.
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Contact.pm15
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Develop.pm10
-rw-r--r--t/app/controller/contact.t64
-rw-r--r--templates/email/default/_email_settings.html1
-rw-r--r--templates/email/default/contact.html13
-rw-r--r--templates/email/default/contact.txt8
7 files changed, 111 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e92d541bf..401241388 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@
- Pass ‘filter_category’ param to front page to pre-filter map.
- Admin improvements:
- Add new roles system, to group permissions and apply to users. #2483
+ - Contact form emails now include user admin links.
- New features:
- Categories can be listed under more than one group #2475
- OpenID Connect login support. #2523
diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm
index e2b76ca60..90ea18ca2 100644
--- a/perllib/FixMyStreet/App/Controller/Contact.pm
+++ b/perllib/FixMyStreet/App/Controller/Contact.pm
@@ -197,6 +197,21 @@ sub prepare_params_for_email : Private {
my $base_url = $c->cobrand->base_url();
my $admin_url = $c->cobrand->admin_base_url;
+ my $user = $c->cobrand->users->find( { email => $c->stash->{em} } );
+ if ( $user ) {
+ $c->stash->{user_admin_url} = $admin_url . '/users/' . $user->id;
+ $c->stash->{user_reports_admin_url} = $admin_url . '/reports?search=' . $user->email;
+
+ my $user_latest_problem = $user->problems->search({
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ]
+ }, {
+ order_by => { -desc => 'id' }
+ })->single;
+ if ( $user_latest_problem) {
+ $c->stash->{user_latest_report_admin_url} = $admin_url . '/report_edit/' . $user_latest_problem->id;
+ }
+ }
+
if ( $c->stash->{update} ) {
$c->stash->{problem_url} = $base_url . $c->stash->{update}->url;
diff --git a/perllib/FixMyStreet/App/Controller/Develop.pm b/perllib/FixMyStreet/App/Controller/Develop.pm
index 38f0c2437..e6845ac02 100755
--- a/perllib/FixMyStreet/App/Controller/Develop.pm
+++ b/perllib/FixMyStreet/App/Controller/Develop.pm
@@ -130,6 +130,16 @@ sub email_previewer : Path('/_dev/email') : Args(1) {
);
$vars->{problem_url} = $c->cobrand->base_url() . '/report/' . $vars->{problem}->id;
$vars->{admin_url} = $c->cobrand->admin_base_url . '/report_edit/' . $vars->{problem}->id;
+ $vars->{user_admin_url} = $c->cobrand->admin_base_url . '/users/' . $c->user->id;
+ $vars->{user_reports_admin_url} = $c->cobrand->admin_base_url . '/reports?search=' . $c->user->email;
+ my $user_latest_problem = $c->user->problems->search({
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ]
+ }, {
+ order_by => { -desc => 'id' }
+ })->single;
+ if ( $user_latest_problem ) {
+ $vars->{user_latest_report_admin_url} = $c->cobrand->admin_base_url . '/report_edit/' . $user_latest_problem->id;
+ }
}
my $email = $c->construct_email("$template.txt", $vars);
diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t
index c74aaa5ff..908ec971b 100644
--- a/t/app/controller/contact.t
+++ b/t/app/controller/contact.t
@@ -337,6 +337,70 @@ for my $test (
}
for my $test (
+ { fields => \%common }
+ )
+{
+ subtest 'check email contains user details' => sub {
+ my $user = $mech->create_user_ok(
+ $test->{fields}->{em},
+ name => $test->{fields}->{name}
+ );
+
+ my $older_unhidden_problem = FixMyStreet::App->model('DB::Problem')->create(
+ {
+ title => 'Some problem or other',
+ detail => 'More detail on the problem',
+ postcode => 'EH99 1SP',
+ confirmed => '2011-05-04 10:44:28.145168',
+ anonymous => 0,
+ name => $test->{fields}->{name},
+ state => 'confirmed',
+ user => $user,
+ latitude => 0,
+ longitude => 0,
+ areas => 0,
+ used_map => 0,
+ }
+ );
+
+ my $newer_hidden_problem = FixMyStreet::App->model('DB::Problem')->create(
+ {
+ title => 'A hidden problem',
+ detail => 'Shhhh secret',
+ postcode => 'EH99 1SP',
+ confirmed => '2012-06-05 10:44:28.145168',
+ anonymous => 0,
+ name => $test->{fields}->{name},
+ state => 'hidden',
+ user => $user,
+ latitude => 0,
+ longitude => 0,
+ areas => 0,
+ used_map => 0,
+ }
+ );
+
+ $mech->clear_emails_ok;
+ $mech->get_ok('/contact');
+ $mech->submit_form_ok( { with_fields => $test->{fields} } );
+
+ my $email = $mech->get_email;
+ my $body = $mech->get_text_body_from_email($email);
+
+ my $user_id = $user->id;
+ my $user_email = $user->email;
+ my $older_unhidden_problem_id = $older_unhidden_problem->id;
+ my $newer_hidden_problem_id = $newer_hidden_problem->id;
+
+ like $body, qr/admin\/users\/$user_id/, 'email contains admin link to edit user';
+ like $body, qr/admin\/reports\?search=$user_email/, 'email contains admin link to show users reports';
+ like $body, qr/admin\/report_edit\/$older_unhidden_problem_id/, 'email contains admin link for users latest unhidden report';
+ unlike $body, qr/admin\/report_edit\/$newer_hidden_problem_id/, 'email does not link to hidden reports';
+
+ };
+}
+
+for my $test (
{
fields => { %common, dest => undef },
page_errors =>
diff --git a/templates/email/default/_email_settings.html b/templates/email/default/_email_settings.html
index 94045bd3c..bdb8af692 100644
--- a/templates/email/default/_email_settings.html
+++ b/templates/email/default/_email_settings.html
@@ -108,6 +108,7 @@ list_item_photo_style = "float: right; margin: 0 0 1em 1em; border: none;"
contact_meta_style = "padding: 15px ${ column_padding }px; vertical-align: top; background-color: $secondary_column_background_color; border-bottom: 1px solid $column_divider_color;"
contact_th_style = "vertical-align: top; padding: 0.4em 1em 0 0; white-space: nowrap; text-align: left;"
contact_td_style = "vertical-align: top; padding: 0.4em 0 0.4em 0; width: 100%;"
+contact_admin_links_style = "display: block;"
# The below is so the buttons work okay in Outlook: https://litmus.com/blog/a-guide-to-bulletproof-buttons-in-email-design
button_style = "display: inline-block; border: 10px solid $button_background_color; border-width: 10px 15px; border-radius: $button_border_radius; background-color: $button_background_color; color: $button_text_color; font-size: 18px; line-height: 21px; font-weight: $button_font_weight; text-decoration: underline;"
diff --git a/templates/email/default/contact.html b/templates/email/default/contact.html
index 8dc9f3af0..33c858dfb 100644
--- a/templates/email/default/contact.html
+++ b/templates/email/default/contact.html
@@ -16,7 +16,18 @@ INCLUDE '_email_top.html';
<table [% table_reset %]>
<tr>
<th style="[% contact_th_style %]">From</th>
- <td style="[% contact_td_style %]">[% name %] &lt;<a href="mailto:[% em | html %]">[% em | html %]</a>&gt;</td>
+ <td style="[% contact_td_style %]">
+ [% name %] &lt;<a href="mailto:[% em | html %]">[% em | html %]</a>&gt;
+ [%~ IF user_admin_url %]
+ <small style="[% contact_admin_links_style %]">
+ <a href="[% user_admin_url | html %]">Edit user</a> –
+ [%~ IF user_latest_report_admin_url %]
+ <a href="[% user_latest_report_admin_url | html %]">Edit latest report</a> –
+ [%~ END %]
+ <a href="[% user_reports_admin_url | html %]">Show all reports</a>
+ </small>
+ [%~ END %]
+ </td>
</tr>
</table>
</th>
diff --git a/templates/email/default/contact.txt b/templates/email/default/contact.txt
index bd97d17a6..67ff6f610 100644
--- a/templates/email/default/contact.txt
+++ b/templates/email/default/contact.txt
@@ -6,6 +6,14 @@ Subject: [% site_name %] message: [% subject %]
[ [% complaint %] - [% problem_url %] - [% admin_url %] ]
[% END %]
+[%~ IF user_admin_url %]
+[ Edit user: [% user_admin_url %] ]
+[%~ IF user_latest_report_admin_url %]
+[ Edit latest report: [% user_latest_report_admin_url %] ]
+[%~ END %]
+[ Show all reports: [% user_reports_admin_url %] ]
+[%~ END %]
+
--
Sent by contact form on [% host %].
IP address [% ip %], user agent [% user_agent %]