diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-10-10 13:16:12 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-10-10 13:21:36 +0100 |
commit | f8a4d8f97dfc2e61854bb423594e669de7e63aef (patch) | |
tree | a42d9c5808fa6806454deaee9436f892de160750 | |
parent | 8f99184aec230770c62237e060bc9af02b06a3e6 (diff) |
Have body.url work in hashref lookup.
body.url could still be in use by old-school /reports table index pages
(though they were dropped in 2.1, so a cobrand would have to have
overridden it since then) and the update to speed up body lists in #2248
broke it. This puts it back in minimal form.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Body.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Body.pm | 8 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 2 | ||||
-rw-r--r-- | t/app/controller/reports.t | 15 | ||||
-rw-r--r-- | templates/web/base/admin/body.html | 2 |
7 files changed, 34 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b71e3081..ea022caed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Bugfixes: - Add perl 5.26/5.28 support. - Fix subcategory issues when visiting /report/new directly #2276 + - Have body.url work in hashref lookup. #2284 - Internal things: - Move send-comments code to package for testing. diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm index 74a38f225..d459d5f02 100644 --- a/perllib/FixMyStreet/DB/Result/Body.pm +++ b/perllib/FixMyStreet/DB/Result/Body.pm @@ -138,10 +138,17 @@ use namespace::clean; with 'FixMyStreet::Roles::Translatable', 'FixMyStreet::Roles::Extra'; +sub _url { + my ( $obj, $cobrand, $args ) = @_; + my $uri = URI->new('/reports/' . $cobrand->short_name($obj)); + $uri->query_form($args) if $args; + return $uri; +} + sub url { my ( $self, $c, $args ) = @_; - # XXX $areas_info was used here for Norway parent - needs body parents, I guess - return $c->uri_for( '/reports/' . $c->cobrand->short_name( $self ), $args || {} ); + my $cobrand = $self->result_source->schema->cobrand; + return _url($self, $cobrand, $args); } __PACKAGE__->might_have( diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 2192158d3..a222c78cd 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -663,7 +663,7 @@ sub body { my @body_names = sort map { my $name = $_->name; if ($c and FixMyStreet->config('AREA_LINKS_FROM_PROBLEMS')) { - '<a href="' . $_->url($c) . '">' . $name . '</a>'; + '<a href="' . $_->url . '">' . $name . '</a>'; } else { $name; } diff --git a/perllib/FixMyStreet/DB/ResultSet/Body.pm b/perllib/FixMyStreet/DB/ResultSet/Body.pm index 1855a45c1..4e9661d2e 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Body.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Body.pm @@ -149,9 +149,17 @@ sub all_sorted { })->all; @bodies = sort { strcoll($a->{msgstr} || $a->{name}, $b->{msgstr} || $b->{name}) } @bodies; + my $cobrand = $rs->result_source->schema->cobrand; + foreach my $body (@bodies) { $body->{parent} = { id => $body->{parent}, name => $body->{parent_name} } if $body->{parent}; + # DEPRECATED: url(c, query_params) -> url + $body->{url} = sub { + my ($c, $args) = @_; + return FixMyStreet::DB::Result::Body::_url($body, $cobrand, $args); + }; + # DEPRECATED: get_column('area_count') -> area_count next unless defined $body->{area_count}; $body->{get_column} = sub { diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 2fc4fde9f..a20eec005 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -151,7 +151,7 @@ subtest "test duration string" => sub { AREA_LINKS_FROM_PROBLEMS => 1, }, sub { $mech->get_ok("/report/$report_id"); - $mech->content_contains('Sent to <a href="http://localhost/reports/Westminster+City+Council">Westminster'); + $mech->content_contains('Sent to <a href="/reports/Westminster+City+Council">Westminster'); }; }; diff --git a/t/app/controller/reports.t b/t/app/controller/reports.t index 3c18b1383..66af2778d 100644 --- a/t/app/controller/reports.t +++ b/t/app/controller/reports.t @@ -95,8 +95,19 @@ $fife_problems[10]->update( { state => 'hidden', }); -# Run the cron script old-data (for the table no longer used by default) -FixMyStreet::Script::UpdateAllReports::generate(1); +FixMyStreet::override_config { + ALLOWED_COBRANDS => 'fixmystreet', +}, sub { + subtest 'Test the cron script old-data (for the table no longer used by default)' => sub { + FixMyStreet::Script::UpdateAllReports::generate(1); + + # Old style page no longer exists in core, but let's just check the code works okay + my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('fixmystreet')->new(); + FixMyStreet::DB->schema->cobrand($cobrand); + my @bodies = FixMyStreet::DB->resultset('Body')->active->translated->all_sorted; + is $bodies[0]->{url}->(), '/reports/Birmingham'; + }; +}; # Run the cron script that makes the data for /reports so we don't get an error. my $data = FixMyStreet::Script::UpdateAllReports::generate_dashboard(); diff --git a/templates/web/base/admin/body.html b/templates/web/base/admin/body.html index 2d77f10ce..37ab24496 100644 --- a/templates/web/base/admin/body.html +++ b/templates/web/base/admin/body.html @@ -28,7 +28,7 @@ [% END %] [% END %] <br> - <a href="[% c.uri_for_email(body.url(c)) %]" class="admin-offsite-link">[% loc('List all reported problems' ) %]</a> | + <a href="[% c.uri_for_email(body.url) %]" class="admin-offsite-link">[% loc('List all reported problems' ) %]</a> | <a href="[% c.uri_for( 'body', body_id, { text => 1 } ) %]">[% loc('Text only version') %]</a> </p> |