Skip to content

Commit

Permalink
Have body.url work in hashref lookup.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dracos committed Oct 10, 2018
1 parent 6ade343 commit a2859ad
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
11 changes: 9 additions & 2 deletions perllib/FixMyStreet/DB/Result/Body.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/DB/Result/Problem.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions perllib/FixMyStreet/DB/ResultSet/Body.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion templates/web/base/admin/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down

0 comments on commit a2859ad

Please sign in to comment.