aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Tokens.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm10
-rw-r--r--perllib/FixMyStreet/Cobrand/LichfieldDC.pm10
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm4
-rw-r--r--t/app/model/problem.t119
-rw-r--r--templates/web/default/tokens/confirm_problem.html7
7 files changed, 100 insertions, 54 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 5bf184ae6..87bdc1fd0 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -1063,7 +1063,7 @@ sub redirect_or_confirm_creation : Private {
if ( $report->confirmed ) {
# Subscribe problem reporter to email updates
$c->forward( 'create_reporter_alert' );
- my $report_uri = $c->uri_for( '/report', $report->id );
+ my $report_uri = $c->cobrand->base_url_for_report( $report ) . $report->url;
$c->log->info($report->user->id . ' was logged in, redirecting to /report/' . $report->id);
$c->res->redirect($report_uri);
$c->detach;
diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm
index 8bab84979..03dc69b00 100644
--- a/perllib/FixMyStreet/App/Controller/Tokens.pm
+++ b/perllib/FixMyStreet/App/Controller/Tokens.pm
@@ -79,7 +79,7 @@ sub confirm_problem : Path('/P') {
$c->set_session_cookie_expire(0);
if ( FixMyStreet::DB::Result::Problem->visible_states()->{$old_state} ) {
- my $report_uri = $c->uri_for( '/report', $problem->id );
+ my $report_uri = $c->cobrand->base_url_for_report( $problem ) . $problem->url;
$c->res->redirect($report_uri);
}
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 0323edfd5..bcf773d37 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -99,16 +99,16 @@ Return the base url for the cobranded version of the site
sub base_url { mySociety::Config::get('BASE_URL') }
-=head2 url_for_report
+=head2 base_url_for_report
-Return the url for a report (might be different in a two-tier county, but
+Return the base url for a report (might be different in a two-tier county, but
most of the time will be same as base_url).
=cut
-sub url_for_report {
- my ( $self, $problem ) = @_;
- return $self->base_url . $problem->url;
+sub base_url_for_report {
+ my ( $self, $report ) = @_;
+ return $self->base_url;
}
=head2 base_host
diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
index fb00aec48..5c8a04681 100644
--- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
+++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
@@ -27,13 +27,13 @@ sub disambiguate_location {
}
# If we ever link to a county problem report, needs to be to main FixMyStreet
-sub url_for_report {
- my ( $self, $problem ) = @_;
- my %councils = map { $_ => 1 } @{$problem->councils};
+sub base_url_for_report {
+ my ( $self, $report ) = @_;
+ my %councils = map { $_ => 1 } @{$report->councils};
if ( $councils{2434} ) {
- return $self->base_url . $problem->url;
+ return $self->base_url;
} else {
- return FixMyStreet->config('BASE_URL') . $problem->url;
+ return FixMyStreet->config('BASE_URL');
}
}
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 370c15913..a1f0c196a 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -250,13 +250,13 @@ sub send_reports {
}
# Template variables for the email
- my $email_base_url = $cobrand->base_url($row->cobrand_data);
+ my $email_base_url = $cobrand->base_url_for_report($row);
my %h = map { $_ => $row->$_ } qw/id title detail name category latitude longitude used_map/;
map { $h{$_} = $row->user->$_ } qw/email phone/;
$h{confirmed} = DateTime::Format::Pg->format_datetime( $row->confirmed->truncate (to => 'second' ) );
$h{query} = $row->postcode;
- $h{url} = $email_base_url . '/report/' . $row->id;
+ $h{url} = $email_base_url . $row->url;
$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";
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index a7415851b..818f115d1 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -348,44 +348,52 @@ for my $test (
my $mech = FixMyStreet::TestMech->new();
-FixMyStreet::App->model('DB::Contact')->find_or_create(
- {
- area_id => 2651,
- category => 'potholes',
- email => 'test@example.org',
- confirmed => 1,
- deleted => 0,
- editor => 'test',
- whenedited => \'ms_current_timestamp()',
- note => '',
- }
-);
-
-FixMyStreet::App->model('DB::Contact')->find_or_create(
- {
- area_id => 2226,
- category => 'potholes',
- email => '2226@example.org',
- confirmed => 1,
- deleted => 0,
- editor => 'test',
- whenedited => \'ms_current_timestamp()',
- note => '',
- }
-);
-
-FixMyStreet::App->model('DB::Contact')->find_or_create(
- {
- area_id => 2326,
- category => 'potholes',
- email => '2326@example.org',
- confirmed => 1,
- deleted => 0,
- editor => 'test',
- whenedited => \'ms_current_timestamp()',
- note => '',
- }
+my %contact_params = (
+ confirmed => 1,
+ deleted => 0,
+ editor => 'Test',
+ whenedited => \'ms_current_timestamp()',
+ note => 'Created for test',
);
+# Let's make some contacts to send things to!
+FixMyStreet::App->model('DB::Contact')->search( {
+ email => { 'like', '%example.com' },
+} )->delete;
+my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ area_id => 2651, # Edinburgh
+ category => 'potholes',
+ email => 'test@example.org',
+} );
+my $contact2 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ area_id => 2226, # Gloucestershire
+ category => 'potholes',
+ email => '2226@example.org',
+} );
+my $contact3 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ area_id => 2326, # Cheltenham
+ category => 'potholes',
+ email => '2326@example.org',
+} );
+my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ area_id => 2434, # Lichfield
+ category => 'potholes',
+ email => 'trees@example.com',
+} );
+my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ area_id => 2240, # Staffordshire
+ category => 'potholes',
+ email => 'highways@example.com',
+} );
+ok $contact1, "created test contact 1";
+ok $contact2, "created test contact 2";
+ok $contact3, "created test contact 3";
+ok $contact4, "created test contact 4";
+ok $contact5, "created test contact 5";
foreach my $test ( {
desc => 'sends an email',
@@ -427,6 +435,30 @@ foreach my $test ( {
council => '2226|2649',
missing => qr'problem might be the responsibility of Fife.*Council'ms,
},
+ {
+ desc => 'email to two tier council that only shows district, district',
+ unset_whendef => 1,
+ email_count => 1,
+ email => 'system_user@example.com',
+ name => 'Andrew Smith',
+ to => qr'Lichfield District Council',
+ dear => qr'Dear Lichfield District Council,',
+ council => '2434',
+ cobrand => 'lichfielddc',
+ url => 'lichfielddc.',
+ },
+ {
+ desc => 'email to two tier council that only shows district, county',
+ unset_whendef => 1,
+ email_count => 1,
+ email => 'system_user@example.com',
+ name => 'Andrew Smith',
+ to => qr'Staffordshire County Council',
+ dear => qr'Dear Staffordshire County Council,',
+ council => '2240',
+ cobrand => 'lichfielddc',
+ url => '',
+ },
) {
subtest $test->{ desc } => sub {
$mech->clear_emails_ok;
@@ -445,6 +477,7 @@ foreach my $test ( {
whensent => $test->{ unset_whendef } ? undef : \'ms_current_timestamp()',
category => 'potholes',
name => $test->{ name },
+ cobrand => $test->{ cobrand } || 'fixmystreet',
} );
FixMyStreet::App->model('DB::Problem')->send_reports();
@@ -465,6 +498,12 @@ foreach my $test ( {
like $email->body, $test->{ missing }, 'missing council information correct';
}
+ if ( $test->{url} ) {
+ (my $base_url = FixMyStreet->config('BASE_URL')) =~ s{http://}{};
+ my $id = $problem->id;
+ like $email->body, qr[$test->{url}$base_url/report/$id], 'URL present is correct';
+ }
+
$problem->discard_changes;
ok defined( $problem->whensent ), 'whensent set';
}
@@ -475,4 +514,10 @@ $problem->comments->delete;
$problem->delete;
$user->delete;
+$contact1->delete;
+$contact2->delete;
+$contact3->delete;
+$contact4->delete;
+$contact5->delete;
+
done_testing();
diff --git a/templates/web/default/tokens/confirm_problem.html b/templates/web/default/tokens/confirm_problem.html
index 2437c1cd9..b6d82968f 100644
--- a/templates/web/default/tokens/confirm_problem.html
+++ b/templates/web/default/tokens/confirm_problem.html
@@ -6,7 +6,7 @@
[% IF c.cobrand.is_council %]
Thank you. You have successfully confirmed your report
and this will now be investigated by the council.
-You can <a href="[% c.cobrand.url_for_report( problem ) %]">view the problem on this site</a>.
+You can <a href="[% c.cobrand.base_url_for_report( problem ) %][% problem.url %]">view the problem on this site</a>.
</p>
<p>Your reference for this problem is [% problem.id %], please quote it in any enquiries.
@@ -19,8 +19,9 @@ You can <a href="[% c.cobrand.url_for_report( problem ) %]">view the problem on
END;
tprintf(
- loc( '. You can <a href="%s">view the problem on this site</a>.' ),
- c.cobrand.url_for_report( problem )
+ loc( '. You can <a href="%s%s">view the problem on this site</a>.' ),
+ c.cobrand.base_url_for_report( problem ),
+ problem.url
);
%]
[% END %]