diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-12-02 17:33:48 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2015-12-15 17:02:11 +0000 |
commit | 92dfeac83378cd49fbb59591685e5bf849d317e6 (patch) | |
tree | f87175f6539728e319dc5bd027b1b94fd7eaa26b /perllib/FixMyStreet/DB | |
parent | 64d24b8627879fc68f9f883d6e24a9c7cb72449f (diff) |
Fix cobrand restriction of My/Nearby.
5c79337 simplified a bit too far, as after then a particular cobrand
could in Nearby and My only filter reports to a particular body, not
any other criteria. To fix this, introduce more generic functions in
the default cobrand to allow more flexibility.
Make sure a few tests delete their bodies fully so that new tests
pass when run as part of the suite.
Fixes #1289.
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Comment.pm | 14 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Nearby.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 6 |
3 files changed, 15 insertions, 12 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Comment.pm b/perllib/FixMyStreet/DB/ResultSet/Comment.pm index 3059baab1..9f254a018 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Comment.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Comment.pm @@ -5,20 +5,20 @@ use strict; use warnings; sub to_body { - my ($rs, $body_restriction) = @_; - return FixMyStreet::DB::ResultSet::Problem::to_body($rs, $body_restriction); + my ($rs, $bodies) = @_; + return FixMyStreet::DB::ResultSet::Problem::to_body($rs, $bodies, 1); } sub timeline { - my ( $rs, $body_restriction ) = @_; + my ( $rs ) = @_; my $prefetch = $rs->result_source->storage->sql_maker->quote_char ? [ qw/user/ ] : []; - return $rs->to_body($body_restriction)->search( + return $rs->search( { state => 'confirmed', created => { '>=', \"current_timestamp-'7 days'::interval" }, @@ -30,17 +30,13 @@ sub timeline { } sub summary_count { - my ( $rs, $body_restriction ) = @_; + my ( $rs ) = @_; my $params = { group_by => ['me.state'], select => [ 'me.state', { count => 'me.id' } ], as => [qw/state state_count/], }; - if ($body_restriction) { - $rs = $rs->to_body($body_restriction); - $params->{join} = 'problem'; - } return $rs->search(undef, $params); } diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm index a6b00ef7b..9db1c6525 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm @@ -4,6 +4,11 @@ use base 'DBIx::Class::ResultSet'; use strict; use warnings; +sub to_body { + my ($rs, $bodies) = @_; + return FixMyStreet::DB::ResultSet::Problem::to_body($rs, $bodies, 1); +} + sub nearby { my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval, $category, $states ) = @_; @@ -21,7 +26,7 @@ sub nearby { if $ids; $params->{category} = $category if $category; - $rs = FixMyStreet::DB::ResultSet::Problem::to_body($rs, $c->cobrand->body_restriction); + $rs = $c->cobrand->problems_restriction($rs); my $attrs = { prefetch => 'problem', diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index f82f0135c..488030928 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -16,13 +16,15 @@ sub set_restriction { } sub to_body { - my ($rs, $bodies) = @_; + my ($rs, $bodies, $join) = @_; return $rs unless $bodies; unless (ref $bodies eq 'ARRAY') { $bodies = [ map { ref $_ ? $_->id : $_ } $bodies ]; } + $join = { join => 'problem' } if $join; $rs = $rs->search( - \[ "regexp_split_to_array(bodies_str, ',') && ?", [ {} => $bodies ] ] + \[ "regexp_split_to_array(bodies_str, ',') && ?", [ {} => $bodies ] ], + $join ); return $rs; } |