aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/ResultSet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/DB/ResultSet')
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Nearby.pm21
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm30
2 files changed, 37 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
index 2ebe309e3..af1142c3a 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
@@ -17,16 +17,16 @@ sub nearby {
}
my $params = {
- state => [ keys %{$args{states}} ],
+ 'problem.state' => [ keys %{$args{states}} ],
};
- $params->{id} = { -not_in => $args{ids} }
+ $params->{problem_id} = { -not_in => $args{ids} }
if $args{ids};
- $params->{category} = $args{categories} if $args{categories} && @{$args{categories}};
+ $params->{'problem.category'} = $args{categories} if $args{categories} && @{$args{categories}};
$params->{$c->stash->{report_age_field}} = { '>=', \"current_timestamp-'$args{report_age}'::interval" }
if $args{report_age};
- FixMyStreet::DB::ResultSet::Problem->non_public_if_possible($params, $c);
+ FixMyStreet::DB::ResultSet::Problem->non_public_if_possible($params, $c, 'problem');
$rs = $c->cobrand->problems_restriction($rs);
@@ -34,11 +34,22 @@ sub nearby {
$params = { %$params, %{$args{extra}} } if $args{extra};
my $attrs = {
- prefetch => 'problem',
+ prefetch => { problem => [] },
bind => [ $args{latitude}, $args{longitude}, $args{distance} ],
order_by => [ 'distance', { -desc => 'created' } ],
rows => $args{limit},
};
+ if ($c->user_exists) {
+ if ($c->user->from_body || $c->user->is_superuser) {
+ push @{$attrs->{prefetch}{problem}}, 'contact';
+ }
+ if ($c->user->has_body_permission_to('planned_reports')) {
+ push @{$attrs->{prefetch}{problem}}, 'user_planned_reports';
+ }
+ if ($c->user->has_body_permission_to('report_edit_priority') || $c->user->has_body_permission_to('report_inspect')) {
+ push @{$attrs->{prefetch}{problem}}, 'response_priority';
+ }
+ }
my @problems = mySociety::Locale::in_gb_locale { $rs->search( $params, $attrs )->all };
return \@problems;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index e23cf78e1..2ce4c04be 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -26,30 +26,31 @@ sub body_query {
# Edits PARAMS in place to either hide non_public reports, or show them
# if user is superuser (all) or inspector (correct body)
sub non_public_if_possible {
- my ($rs, $params, $c) = @_;
+ my ($rs, $params, $c, $table) = @_;
+ $table ||= 'me';
if ($c->user_exists) {
my $only_non_public = $c->stash->{only_non_public} ? 1 : 0;
if ($c->user->is_superuser) {
# See all reports, no restriction
- $params->{non_public} = 1 if $only_non_public;
+ $params->{"$table.non_public"} = 1 if $only_non_public;
} elsif ($c->user->has_body_permission_to('report_inspect') ||
$c->user->has_body_permission_to('report_mark_private')) {
if ($only_non_public) {
$params->{'-and'} = [
- non_public => 1,
+ "$table.non_public" => 1,
$rs->body_query($c->user->from_body->id),
];
} else {
$params->{'-or'} = [
- non_public => 0,
+ "$table.non_public" => 0,
$rs->body_query($c->user->from_body->id),
];
}
} else {
- $params->{non_public} = 0;
+ $params->{"$table.non_public"} = 0;
}
} else {
- $params->{non_public} = 0;
+ $params->{"$table.non_public"} = 0;
}
}
@@ -175,22 +176,33 @@ sub around_map {
my ( $rs, $c, %p) = @_;
my $attr = {
order_by => $p{order},
+ rows => $c->cobrand->reports_per_page,
};
- $attr->{rows} = $c->cobrand->reports_per_page;
+ if ($c->user_exists) {
+ if ($c->user->from_body || $c->user->is_superuser) {
+ push @{$attr->{prefetch}}, 'contact';
+ }
+ if ($c->user->has_body_permission_to('planned_reports')) {
+ push @{$attr->{prefetch}}, 'user_planned_reports';
+ }
+ if ($c->user->has_body_permission_to('report_edit_priority') || $c->user->has_body_permission_to('report_inspect')) {
+ push @{$attr->{prefetch}}, 'response_priority';
+ }
+ }
unless ( $p{states} ) {
$p{states} = FixMyStreet::DB::Result::Problem->visible_states();
}
my $q = {
- state => [ keys %{$p{states}} ],
+ 'me.state' => [ keys %{$p{states}} ],
latitude => { '>=', $p{min_lat}, '<', $p{max_lat} },
longitude => { '>=', $p{min_lon}, '<', $p{max_lon} },
};
$q->{$c->stash->{report_age_field}} = { '>=', \"current_timestamp-'$p{report_age}'::interval" } if
$p{report_age};
- $q->{category} = $p{categories} if $p{categories} && @{$p{categories}};
+ $q->{'me.category'} = $p{categories} if $p{categories} && @{$p{categories}};
$rs->non_public_if_possible($q, $c);