aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm63
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm15
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth/Phone.pm8
-rw-r--r--perllib/FixMyStreet/App/Controller/Auth/Profile.pm4
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm11
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm2
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/State.pm6
-rw-r--r--perllib/FixMyStreet/SMS.pm4
-rw-r--r--perllib/FixMyStreet/Script/Alerts.pm21
-rw-r--r--t/app/controller/alert_new.t229
-rw-r--r--t/app/controller/around.t23
-rw-r--r--t/app/controller/auth_phone.t8
-rw-r--r--templates/web/base/around/lookup_by_ref.html6
-rw-r--r--templates/web/oxfordshire/_email_sent_extra.html3
16 files changed, 334 insertions, 73 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 65c832c55..fa06d8ccf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,9 +12,11 @@
- Fix encoded entities in RSS output. #1859
- Only save category changes if staff user update valid #1857
- Only create one update when staff user updating category #1857
+ - Do not include blank updates in email alerts #1857
- Admin improvements:
- Character length limit can be placed on report detailed information #1848
- Inspector panel shows nearest address if available #1850
+ - Return a 200 rather than 404 for ref ID lookup.
* v2.2 (13th September 2017)
- New features:
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index b854f16f5..719b04cf6 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -797,6 +797,19 @@ sub reports : Path('reports') {
}
+sub update_user : Private {
+ my ($self, $c, $object) = @_;
+ my $parsed = FixMyStreet::SMS->parse_username($c->get_param('username'));
+ if ($parsed->{email} || ($parsed->{phone} && $parsed->{may_be_mobile})) {
+ my $user = $c->model('DB::User')->find_or_create({ $parsed->{type} => $parsed->{username} });
+ if ($user->id && $user->id != $object->user->id) {
+ $object->user( $user );
+ return 1;
+ }
+ }
+ return 0;
+}
+
sub report_edit : Path('report_edit') : Args(1) {
my ( $self, $c, $id ) = @_;
@@ -901,14 +914,7 @@ sub report_edit : Path('report_edit') : Args(1) {
$problem->set_inflated_columns(\%columns);
$c->forward( '/admin/report_edit_category', [ $problem ] );
-
- my $parsed = FixMyStreet::SMS->parse_username($c->get_param('username'));
- if ($parsed->{email} || ($parsed->{phone} && $parsed->{phone}->is_mobile)) {
- my $user = $c->model('DB::User')->find_or_create({ $parsed->{type} => $parsed->{username} });
- if ($user->id && $user->id != $problem->user->id) {
- $problem->user( $user );
- }
- }
+ $c->forward('update_user', [ $problem ]);
# Deal with photos
my $remove_photo_param = $self->_get_remove_photo_param($c);
@@ -1256,14 +1262,7 @@ sub update_edit : Path('update_edit') : Args(1) {
$update->anonymous( $c->get_param('anonymous') );
$update->state( $new_state );
- my $parsed = FixMyStreet::SMS->parse_username($c->get_param('username'));
- if ($parsed->{email} || ($parsed->{phone} && $parsed->{phone}->is_mobile)) {
- my $user = $c->model('DB::User')->find_or_create({ $parsed->{type} => $parsed->{username} });
- if ($user->id && $user->id != $update->user->id) {
- $edited = 1;
- $update->user( $user );
- }
- }
+ $edited = 1 if $c->forward('update_user', [ $update ]);
if ( $new_state eq 'confirmed' and $old_state eq 'unconfirmed' ) {
$update->confirmed( \'current_timestamp' );
@@ -1303,6 +1302,18 @@ sub update_edit : Path('update_edit') : Args(1) {
return 1;
}
+sub phone_check : Private {
+ my ($self, $c, $phone) = @_;
+ my $parsed = FixMyStreet::SMS->parse_username($phone);
+ if ($parsed->{phone} && $parsed->{may_be_mobile}) {
+ return $parsed->{username};
+ } elsif ($parsed->{phone}) {
+ $c->stash->{field_errors}->{phone} = _('Please enter a mobile number');
+ } else {
+ $c->stash->{field_errors}->{phone} = _('Please check your phone number is correct');
+ }
+}
+
sub user_add : Path('user_edit') : Args(0) {
my ( $self, $c ) = @_;
@@ -1334,14 +1345,8 @@ sub user_add : Path('user_edit') : Args(0) {
}
if ($phone_v) {
- my $parsed = FixMyStreet::SMS->parse_username($phone);
- if ($parsed->{phone} && $parsed->{phone}->is_mobile) {
- $phone = $parsed->{username};
- } elsif ($parsed->{phone}) {
- $c->stash->{field_errors}->{phone} = _('Please enter a mobile number');
- } else {
- $c->stash->{field_errors}->{phone} = _('Please check your phone number is correct');
- }
+ my $parsed_phone = $c->forward('phone_check', [ $phone ]);
+ $phone = $parsed_phone if $parsed_phone;
}
my $existing_email = $email_v && $c->model('DB::User')->find( { email => $email } );
@@ -1422,14 +1427,8 @@ sub user_edit : Path('user_edit') : Args(1) {
}
if ($phone_v) {
- my $parsed = FixMyStreet::SMS->parse_username($phone);
- if ($parsed->{phone} && $parsed->{phone}->is_mobile) {
- $phone = $parsed->{username};
- } elsif ($parsed->{phone}) {
- $c->stash->{field_errors}->{phone} = _('Please enter a mobile number');
- } else {
- $c->stash->{field_errors}->{phone} = _('Please check your phone number is correct');
- }
+ my $parsed_phone = $c->forward('phone_check', [ $phone ]);
+ $phone = $parsed_phone if $parsed_phone;
}
unless ($user->name) {
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index b872084ff..30c023317 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -8,6 +8,7 @@ use FixMyStreet::Map;
use Encode;
use JSON::MaybeXS;
use Utils;
+use Try::Tiny;
=head1 NAME
@@ -366,13 +367,17 @@ sub lookup_by_ref : Private {
external_id => $ref
]);
- if ( $problems->count == 0) {
- $c->detach( '/page_error_404_not_found', [] );
- } elsif ( $problems->count == 1 ) {
- $c->res->redirect( $c->uri_for( '/report', $problems->first->id ) );
- } else {
+ my $count = try {
+ $problems->count;
+ } catch {
+ 0;
+ };
+
+ if ($count > 1) {
$c->stash->{ref} = $ref;
$c->stash->{matching_reports} = [ $problems->all ];
+ } elsif ($count == 1) {
+ $c->res->redirect( $c->uri_for( '/report', $problems->first->id ) );
}
}
diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm
index b453f593b..80e407147 100644
--- a/perllib/FixMyStreet/App/Controller/Auth.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth.pm
@@ -119,7 +119,7 @@ sub code_sign_in : Private {
my $parsed = FixMyStreet::SMS->parse_username($username);
if ($parsed->{type} eq 'phone' && FixMyStreet->config('SMS_AUTHENTICATION')) {
- $c->forward('phone/sign_in', [ $parsed->{phone} ]);
+ $c->forward('phone/sign_in', [ $parsed ]);
} else {
$c->forward('email_sign_in', [ $parsed->{username} ]);
}
diff --git a/perllib/FixMyStreet/App/Controller/Auth/Phone.pm b/perllib/FixMyStreet/App/Controller/Auth/Phone.pm
index 4e9f92596..e4ffc2205 100644
--- a/perllib/FixMyStreet/App/Controller/Auth/Phone.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth/Phone.pm
@@ -45,19 +45,19 @@ and sets up the token/etc to deal with the response.
=cut
sub sign_in : Private {
- my ( $self, $c, $phone ) = @_;
+ my ( $self, $c, $parsed ) = @_;
- unless ($phone) {
+ unless ($parsed->{phone}) {
$c->stash->{username_error} = 'other_phone';
return;
}
- unless ($phone->is_mobile) {
+ unless ($parsed->{may_be_mobile}) {
$c->stash->{username_error} = 'nonmobile';
return;
}
- (my $number = $phone->format) =~ s/\s+//g;
+ (my $number = $parsed->{phone}->format) =~ s/\s+//g;
if ( FixMyStreet->config('SIGNUPS_DISABLED')
&& !$c->model('DB::User')->find({ phone => $number })
diff --git a/perllib/FixMyStreet/App/Controller/Auth/Profile.pm b/perllib/FixMyStreet/App/Controller/Auth/Profile.pm
index ecf009150..acffd3019 100644
--- a/perllib/FixMyStreet/App/Controller/Auth/Profile.pm
+++ b/perllib/FixMyStreet/App/Controller/Auth/Profile.pm
@@ -118,14 +118,14 @@ sub change_phone : Path('/auth/change_phone') {
# If we've not used a mobile and we're not specifically verifying,
# and phone isn't our only verified way of logging in,
# then allow change of number (for e.g. landline).
- if (!FixMyStreet->config('SMS_AUTHENTICATION') || (!$parsed->{phone}->is_mobile && !$c->stash->{verifying} && $c->user->email_verified)) {
+ if (!FixMyStreet->config('SMS_AUTHENTICATION') || (!$parsed->{may_be_mobile} && !$c->stash->{verifying} && $c->user->email_verified)) {
$c->user->update({ phone => $phone, phone_verified => 0 });
$c->flash->{flash_message} = _('You have successfully added your phone number.');
$c->res->redirect('/my');
$c->detach;
}
- $c->forward('/auth/phone/sign_in', [ $parsed->{phone} ]);
+ $c->forward('/auth/phone/sign_in', [ $parsed ]);
}
sub verify_item : Path('/auth/verify') : Args(1) {
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index 562f29693..409a6e1ab 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -274,14 +274,9 @@ sub problem_state_display {
return FixMyStreet::DB->resultset("State")->display('confirmed', 1);
} elsif ($self->problem_state) {
my $state = $self->problem_state;
- if ($state eq 'not responsible') {
- $update_state = _( "not the council's responsibility" );
- if ($cobrand eq 'bromley' || $self->problem->to_body_named('Bromley')) {
- $update_state = 'third party responsibility';
- }
- } else {
- $update_state = FixMyStreet::DB->resultset("State")->display($state, 1);
- }
+ my $cobrand_name = $cobrand;
+ $cobrand_name = 'bromley' if $self->problem->to_body_named('Bromley');
+ $update_state = FixMyStreet::DB->resultset("State")->display($state, 1, $cobrand_name);
}
return $update_state;
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index 296cf997d..d02039ac3 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -196,7 +196,7 @@ sub check_for_errors {
my $parsed = FixMyStreet::SMS->parse_username($self->phone);
if (!$parsed->{phone}) {
$errors{username} = _('Please check your phone number is correct');
- } elsif (!$parsed->{phone}->is_mobile) {
+ } elsif (!$parsed->{may_be_mobile}) {
$errors{username} = _('Please enter a mobile number');
}
}
diff --git a/perllib/FixMyStreet/DB/ResultSet/State.pm b/perllib/FixMyStreet/DB/ResultSet/State.pm
index de56c738c..3e6169aeb 100644
--- a/perllib/FixMyStreet/DB/ResultSet/State.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/State.pm
@@ -58,7 +58,7 @@ sub fixed { [ $_[0]->_filter(sub { $_->type eq 'fixed' }) ] }
# This function can be used to return that label's display name.
sub display {
- my ($rs, $label, $single_fixed) = @_;
+ my ($rs, $label, $single_fixed, $cobrand) = @_;
my $unchanging = {
unconfirmed => _("Unconfirmed"),
hidden => _("Hidden"),
@@ -72,6 +72,10 @@ sub display {
};
$label = 'fixed' if $single_fixed && $label =~ /^fixed - (council|user)$/;
return $unchanging->{$label} if $unchanging->{$label};
+ if ($cobrand && $label eq 'not responsible') {
+ return 'third party responsibility' if $cobrand eq 'bromley';
+ return _("not the council's responsibility");
+ }
my ($state) = $rs->_filter(sub { $_->label eq $label });
return $label unless $state;
$state->name($translate_now->{$label}) if $translate_now->{$label};
diff --git a/perllib/FixMyStreet/SMS.pm b/perllib/FixMyStreet/SMS.pm
index ec9251a1a..c71cceadc 100644
--- a/perllib/FixMyStreet/SMS.pm
+++ b/perllib/FixMyStreet/SMS.pm
@@ -94,15 +94,19 @@ sub parse_username {
}
};
+ my $may_be_mobile = 0;
if ($phone) {
$type = 'phone';
# Store phone without spaces
($username = $phone->format) =~ s/\s+//g;
+ # Is this mobile definitely or possibly a mobile? (+1 numbers)
+ $may_be_mobile = 1 if $phone->is_mobile || (!defined $phone->is_mobile && $phone->is_geographic);
}
return {
type => $type,
phone => $phone,
+ may_be_mobile => $may_be_mobile,
username => $username,
};
}
diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm
index 86f11c7b5..4b5641f9e 100644
--- a/perllib/FixMyStreet/Script/Alerts.pm
+++ b/perllib/FixMyStreet/Script/Alerts.pm
@@ -39,6 +39,7 @@ sub send() {
$item_table.name as item_name, $item_table.anonymous as item_anonymous,
$item_table.confirmed as item_confirmed,
$item_table.photo as item_photo,
+ $item_table.problem_state as item_problem_state,
$head_table.*
from alert, $item_table, $head_table
where alert.parameter::integer = $head_table.id
@@ -65,6 +66,7 @@ sub send() {
$query = FixMyStreet::DB->schema->storage->dbh->prepare($query);
$query->execute();
my $last_alert_id;
+ my $last_problem_state = '';
my %data = ( template => $alert_type->template, data => [], schema => $schema );
while (my $row = $query->fetchrow_hashref) {
@@ -86,7 +88,26 @@ sub send() {
alert_id => $row->{alert_id},
parameter => $row->{item_id},
} );
+
+ # this is currently only for new_updates
+ if (defined($row->{item_text})) {
+ # this might throw up the odd false positive but only in cases where the
+ # state has changed and there was already update text
+ if ($row->{item_problem_state} &&
+ !( $last_problem_state eq '' && $row->{item_problem_state} eq 'confirmed' ) &&
+ $last_problem_state ne $row->{item_problem_state}
+ ) {
+ my $state = FixMyStreet::DB->resultset("State")->display($row->{item_problem_state}, 1, $cobrand);
+
+ my $update = _('State changed to:') . ' ' . $state;
+ $row->{item_text} = $row->{item_text} ? $row->{item_text} . "\n\n" . $update :
+ $update;
+ }
+ next unless $row->{item_text};
+ }
+
if ($last_alert_id && $last_alert_id != $row->{alert_id}) {
+ $last_problem_state = '';
_send_aggregated_alert_email(%data);
%data = ( template => $alert_type->template, data => [], schema => $schema );
}
diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t
index 97a19b3b8..4e8fd1b29 100644
--- a/t/app/controller/alert_new.t
+++ b/t/app/controller/alert_new.t
@@ -475,7 +475,7 @@ subtest "Test normal alert signups and that alerts are sent" => sub {
$mech->delete_user($user2);
};
-subtest "Test alerts are correct for no-text updates" => sub {
+subtest "Test alerts are not sent for no-text updates" => sub {
$mech->delete_user( 'reporter@example.com' );
$mech->delete_user( 'alerts@example.com' );
@@ -513,6 +513,40 @@ subtest "Test alerts are correct for no-text updates" => sub {
my $report_id = $report->id;
ok $report, "created test report - $report_id";
+ my $report2 = FixMyStreet::App->model('DB::Problem')->create( {
+ postcode => 'EH1 1BB',
+ bodies_str => '1',
+ areas => ',11808,135007,14419,134935,2651,20728,',
+ category => 'Street lighting',
+ title => 'Testing',
+ detail => 'Testing Detail',
+ used_map => 1,
+ name => $user1->name,
+ anonymous => 0,
+ state => 'fixed - user',
+ confirmed => $dt_parser->format_datetime($dt),
+ lastupdate => $dt_parser->format_datetime($dt),
+ whensent => $dt_parser->format_datetime($dt->clone->add( minutes => 5 )),
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 1,
+ latitude => '55.951963',
+ longitude => '-3.189944',
+ user_id => $user1->id,
+ } );
+ my $report2_id = $report2->id;
+ ok $report2, "created test report - $report2_id";
+
+ # Must be first
+ my $alert2 = FixMyStreet::App->model('DB::Alert')->create( {
+ parameter => $report2_id,
+ alert_type => 'new_updates',
+ user => $user2,
+ } )->confirm;
+ ok $alert2, 'created alert for other user';
+
my $alert = FixMyStreet::App->model('DB::Alert')->create( {
parameter => $report_id,
alert_type => 'new_updates',
@@ -533,6 +567,92 @@ subtest "Test alerts are correct for no-text updates" => sub {
my $update_id = $update->id;
ok $update, "created test update from staff user - $update_id";
+ my $update2 = FixMyStreet::App->model('DB::Comment')->create( {
+ problem_id => $report2_id,
+ user_id => $user3->id,
+ name => 'Staff User',
+ mark_fixed => 'false',
+ text => 'This is a normal update',
+ state => 'confirmed',
+ confirmed => $dt->clone->add( hours => 9 ),
+ anonymous => 'f',
+ } );
+ my $update2_id = $update2->id;
+ ok $update2, "created test update from staff user - $update2_id";
+
+ $mech->clear_emails_ok;
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ FixMyStreet::Script::Alerts::send();
+ };
+
+ $mech->email_count_is(1);
+
+ $mech->delete_user($user1);
+ $mech->delete_user($user2);
+ $mech->delete_user($user3);
+};
+
+subtest "Test no marked as confirmed added to alerts" => sub {
+ $mech->delete_user( 'reporter@example.com' );
+ $mech->delete_user( 'alerts@example.com' );
+
+ my $user1 = $mech->create_user_ok('reporter@example.com', name => 'Reporter User' );
+ my $user2 = $mech->create_user_ok('alerts@example.com', name => 'Alert User' );
+ my $user3 = $mech->create_user_ok('staff@example.com', name => 'Staff User', from_body => $gloucester );
+ my $dt = DateTime->now(time_zone => 'Europe/London')->add(days => 2);
+
+ my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser;
+
+ my $report_time = '2011-03-01 12:00:00';
+ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
+ postcode => 'EH1 1BB',
+ bodies_str => '1',
+ areas => ',11808,135007,14419,134935,2651,20728,',
+ category => 'Street lighting',
+ title => 'Testing',
+ detail => 'Testing Detail',
+ used_map => 1,
+ name => $user1->name,
+ anonymous => 0,
+ state => 'confirmed',
+ confirmed => $dt_parser->format_datetime($dt),
+ lastupdate => $dt_parser->format_datetime($dt),
+ whensent => $dt_parser->format_datetime($dt->clone->add( minutes => 5 )),
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 1,
+ latitude => '55.951963',
+ longitude => '-3.189944',
+ user_id => $user1->id,
+ } );
+ my $report_id = $report->id;
+ ok $report, "created test report - $report_id";
+
+ my $alert = FixMyStreet::App->model('DB::Alert')->create( {
+ parameter => $report_id,
+ alert_type => 'new_updates',
+ user => $user2,
+ } )->confirm;
+ ok $alert, 'created alert for other user';
+
+ my $update = FixMyStreet::App->model('DB::Comment')->create( {
+ problem_id => $report_id,
+ user_id => $user3->id,
+ name => 'Staff User',
+ mark_fixed => 'false',
+ text => 'this is update',
+ state => 'confirmed',
+ problem_state => 'confirmed',
+ confirmed => $dt->clone->add( hours => 9 ),
+ anonymous => 'f',
+ } );
+ my $update_id = $update->id;
+ ok $update, "created test update from staff user - $update_id";
+
$mech->clear_emails_ok;
FixMyStreet::override_config {
MAPIT_URL => 'http://mapit.uk/',
@@ -545,15 +665,116 @@ subtest "Test alerts are correct for no-text updates" => sub {
my $body = $mech->get_text_body_from_email($email);
like $body, qr/The following updates have been left on this report:/, 'email is about updates to existing report';
like $body, qr/Staff User/, 'Update comes from correct user';
-
- my @urls = $mech->get_link_from_email($email, 1);
- is $urls[0], "http://www.example.org/report/" . $report_id, "Correct report URL in email";
+ unlike $body, qr/State changed to: Open/s, 'no marked as confirmed text';
$mech->delete_user($user1);
$mech->delete_user($user2);
$mech->delete_user($user3);
};
+for my $test (
+ {
+ update_text => '',
+ problem_state => 'investigating',
+ expected_text => 'State changed to: Investigating',
+ desc => 'comment changing status included in email',
+ },
+ {
+ update_text => 'Category changed to Potholes',
+ problem_state => '',
+ expected_text => 'Category changed to Potholes',
+ desc => 'comment about category included',
+ },
+ {
+ update_text => 'Category changed to Potholes',
+ problem_state => 'investigating',
+ expected_text => 'Category changed to Potholes.*Investigating',
+ desc => 'comment about category and status change included',
+ },
+) {
+ subtest $test->{desc} => sub {
+ $mech->delete_user( 'reporter@example.com' );
+ $mech->delete_user( 'alerts@example.com' );
+
+ my $user1 = $mech->create_user_ok('reporter@example.com', name => 'Reporter User' );
+ my $user2 = $mech->create_user_ok('alerts@example.com', name => 'Alert User' );
+ my $user3 = $mech->create_user_ok('staff@example.com', name => 'Staff User', from_body => $gloucester );
+ my $dt = DateTime->now(time_zone => 'Europe/London')->add(days => 2);
+
+ my $dt_parser = FixMyStreet::App->model('DB')->schema->storage->datetime_parser;
+
+ my $report_time = '2011-03-01 12:00:00';
+ my $report = FixMyStreet::App->model('DB::Problem')->find_or_create( {
+ postcode => 'EH1 1BB',
+ bodies_str => '1',
+ areas => ',11808,135007,14419,134935,2651,20728,',
+ category => 'Street lighting',
+ title => 'Testing',
+ detail => 'Testing Detail',
+ used_map => 1,
+ name => $user1->name,
+ anonymous => 0,
+ state => 'confirmed',
+ confirmed => $dt_parser->format_datetime($dt),
+ lastupdate => $dt_parser->format_datetime($dt),
+ whensent => $dt_parser->format_datetime($dt->clone->add( minutes => 5 )),
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 1,
+ latitude => '55.951963',
+ longitude => '-3.189944',
+ user_id => $user1->id,
+ } );
+ my $report_id = $report->id;
+ ok $report, "created test report - $report_id";
+
+ my $alert = FixMyStreet::App->model('DB::Alert')->create( {
+ parameter => $report_id,
+ alert_type => 'new_updates',
+ user => $user2,
+ } )->confirm;
+ ok $alert, 'created alert for other user';
+
+ my $update = FixMyStreet::App->model('DB::Comment')->create( {
+ problem_id => $report_id,
+ user_id => $user3->id,
+ name => 'Staff User',
+ mark_fixed => 'false',
+ text => $test->{update_text},
+ problem_state => $test->{problem_state},
+ state => 'confirmed',
+ confirmed => $dt->clone->add( hours => 9 ),
+ anonymous => 'f',
+ } );
+ my $update_id = $update->id;
+ ok $update, "created test update from staff user - $update_id";
+
+ $mech->clear_emails_ok;
+ FixMyStreet::override_config {
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ FixMyStreet::Script::Alerts::send();
+ };
+
+ $mech->email_count_is(1);
+ my $expected_text = $test->{expected_text};
+ my $email = $mech->get_email;
+ my $body = $mech->get_text_body_from_email($email);
+ like $body, qr/The following updates have been left on this report:/, 'email is about updates to existing report';
+ like $body, qr/Staff User/, 'Update comes from correct user';
+ like $body, qr/$expected_text/s, 'Expected text present';
+
+ my @urls = $mech->get_link_from_email($email, 1);
+ is $urls[0], "http://www.example.org/report/" . $report_id, "Correct report URL in email";
+
+ $mech->delete_user($user1);
+ $mech->delete_user($user2);
+ $mech->delete_user($user3);
+ };
+}
+
subtest "Test signature template is used from cobrand" => sub {
$mech->delete_user( 'reporter@example.com' );
$mech->delete_user( 'alerts@example.com' );
diff --git a/t/app/controller/around.t b/t/app/controller/around.t
index fbb4e76cd..cdaeaf363 100644
--- a/t/app/controller/around.t
+++ b/t/app/controller/around.t
@@ -92,15 +92,22 @@ foreach my $test (
};
}
-subtest 'check non public reports are not displayed on around page' => sub {
- my $params = {
- postcode => 'EH1 1BB',
- latitude => 55.9519637512,
- longitude => -3.17492254484,
- };
- my @edinburgh_problems =
- $mech->create_problems_for_body( 5, 2651, 'Around page', $params );
+my @edinburgh_problems = $mech->create_problems_for_body( 5, 2651, 'Around page', {
+ postcode => 'EH1 1BB',
+ latitude => 55.9519637512,
+ longitude => -3.17492254484,
+});
+subtest 'check lookup by reference' => sub {
+ $mech->get_ok('/');
+ $mech->submit_form_ok( { with_fields => { pc => 'ref:12345' } }, 'bad ref');
+ $mech->content_contains('Searching found no reports');
+ my $id = $edinburgh_problems[0]->id;
+ $mech->submit_form_ok( { with_fields => { pc => "ref:$id" } }, 'good ref');
+ is $mech->uri->path, "/report/$id", "redirected to report page";
+};
+
+subtest 'check non public reports are not displayed on around page' => sub {
$mech->get_ok('/');
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ],
diff --git a/t/app/controller/auth_phone.t b/t/app/controller/auth_phone.t
index 8673f5c62..435ea7552 100644
--- a/t/app/controller/auth_phone.t
+++ b/t/app/controller/auth_phone.t
@@ -47,7 +47,7 @@ subtest 'Log in using mobile, by text' => sub {
}, sub {
$mech->submit_form_ok({
form_name => 'general_auth',
- fields => { username => '+61491570156', password_register => 'secret' },
+ fields => { username => '+18165550100', password_register => 'secret' },
button => 'sign_in_by_code',
}, "sign in using mobile");
@@ -61,7 +61,7 @@ subtest 'Log in using mobile, by text' => sub {
with_fields => { code => $code }
}, 'submit correct code');
- my $user = FixMyStreet::App->model('DB::User')->find( { phone => '+61491570156' } );
+ my $user = FixMyStreet::App->model('DB::User')->find( { phone => '+18165550100' } );
ok $user, "user created";
is $mech->uri->path, '/my', "redirected to the 'my' section of site";
$mech->logged_in_ok;
@@ -76,13 +76,13 @@ subtest 'Log in using mobile, by password' => sub {
$mech->get_ok('/auth');
$mech->submit_form_ok({
form_name => 'general_auth',
- fields => { username => '+61491570156', password_sign_in => 'incorrect' },
+ fields => { username => '+18165550100', password_sign_in => 'incorrect' },
button => 'sign_in_by_password',
}, "sign in using wrong password");
$mech->content_contains('There was a problem');
$mech->submit_form_ok({
form_name => 'general_auth',
- fields => { username => '+61491570156', password_sign_in => 'secret' },
+ fields => { username => '+18165550100', password_sign_in => 'secret' },
button => 'sign_in_by_password',
}, "sign in using password");
diff --git a/templates/web/base/around/lookup_by_ref.html b/templates/web/base/around/lookup_by_ref.html
index aded05638..5c08a7ceb 100644
--- a/templates/web/base/around/lookup_by_ref.html
+++ b/templates/web/base/around/lookup_by_ref.html
@@ -1,7 +1,7 @@
[% pre_container_extra = INCLUDE 'around/postcode_form.html', pc = ref %]
[% INCLUDE 'header.html', title = loc('Reporting a problem'), bodyclass = 'frontpage fullwidthpage' %]
-<div class="tablewrapper">
+[% IF matching_reports %]
<p>[% loc('We found more than one match for that problem reference:') %]</p>
<ul class="pc_alternatives">
[% FOREACH report IN matching_reports %]
@@ -13,6 +13,8 @@
</li>
[% END %]
</ul>
-</div>
+ [% ELSE %]
+ <p>[% loc('Searching found no reports.') %]</p>
+[% END %]
[% INCLUDE 'footer.html' %]
diff --git a/templates/web/oxfordshire/_email_sent_extra.html b/templates/web/oxfordshire/_email_sent_extra.html
index 5fdcd3bfd..f01c2d5fb 100644
--- a/templates/web/oxfordshire/_email_sent_extra.html
+++ b/templates/web/oxfordshire/_email_sent_extra.html
@@ -1 +1,2 @@
-[% INCLUDE '_response_time.html' problem=report %]
+[% DEFAULT problem = report %]
+[% IF problem %][% INCLUDE '_response_time.html' %][% END %]