aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/ResultSet/Problem.pm
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2019-10-30 19:28:55 +0100
committerMarius Halden <marius.h@lden.org>2019-10-30 19:28:55 +0100
commit377bd96aab7cad3434185c30eb908c9da447fe40 (patch)
tree7ec5527e205d5b62caaa862a7de8cd25199c8bf0 /perllib/FixMyStreet/DB/ResultSet/Problem.pm
parent56f61b1441070aa0b9ddcfc74aca46c20313609f (diff)
parent92b253904062edd533e55c22824de6fd01e2f7c1 (diff)
Merge tag 'v2.6' into fiksgatami-dev
Diffstat (limited to 'perllib/FixMyStreet/DB/ResultSet/Problem.pm')
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm43
1 files changed, 30 insertions, 13 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index ef078ed08..37fc34057 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -28,13 +28,23 @@ sub body_query {
sub non_public_if_possible {
my ($rs, $params, $c) = @_;
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
- } elsif ($c->user->has_body_permission_to('report_inspect')) {
- $params->{'-or'} = [
- non_public => 0,
- $rs->body_query($c->user->from_body->id),
- ];
+ $params->{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,
+ $rs->body_query($c->user->from_body->id),
+ ];
+ } else {
+ $params->{'-or'} = [
+ non_public => 0,
+ $rs->body_query($c->user->from_body->id),
+ ];
+ }
} else {
$params->{non_public} = 0;
}
@@ -57,6 +67,10 @@ sub to_body {
# Front page statistics
+sub _cache_timeout {
+ FixMyStreet->config('CACHE_TIMEOUT') // 3600;
+}
+
sub recent_fixed {
my $rs = shift;
my $key = "recent_fixed:$site_key";
@@ -66,7 +80,7 @@ sub recent_fixed {
state => [ FixMyStreet::DB::Result::Problem->fixed_states() ],
lastupdate => { '>', \"current_timestamp-'1 month'::interval" },
} )->count;
- Memcached::set($key, $result, 3600);
+ Memcached::set($key, $result, _cache_timeout());
}
return $result;
}
@@ -80,7 +94,7 @@ sub number_comments {
{ 'comments.state' => 'confirmed' },
{ join => 'comments' }
)->count;
- Memcached::set($key, $result, 3600);
+ Memcached::set($key, $result, _cache_timeout());
}
return $result;
}
@@ -95,7 +109,7 @@ sub recent_new {
state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
confirmed => { '>', \"current_timestamp-'$interval'::interval" },
} )->count;
- Memcached::set($key, $result, 3600);
+ Memcached::set($key, $result, _cache_timeout());
}
return $result;
}
@@ -144,10 +158,10 @@ sub _recent {
# Need to reattach schema so that confirmed column gets reinflated.
$probs->[0]->result_source->schema( $rs->result_source->schema ) if $probs->[0];
# Catch any cached ones since hidden
- $probs = [ grep { ! $_->is_hidden } @$probs ];
+ $probs = [ grep { $_->photo && ! $_->is_hidden } @$probs ];
} else {
$probs = [ $rs->search( $query, $attrs )->all ];
- Memcached::set($key, $probs, 3600);
+ Memcached::set($key, $probs, _cache_timeout());
}
}
@@ -172,6 +186,9 @@ sub around_map {
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}};
$rs->non_public_if_possible($q, $c);
@@ -198,9 +215,9 @@ sub timeline {
return $rs->search(
{
-or => {
- created => { '>=', \"current_timestamp-'7 days'::interval" },
- confirmed => { '>=', \"current_timestamp-'7 days'::interval" },
- whensent => { '>=', \"current_timestamp-'7 days'::interval" },
+ 'me.created' => { '>=', \"current_timestamp-'7 days'::interval" },
+ 'me.confirmed' => { '>=', \"current_timestamp-'7 days'::interval" },
+ 'me.whensent' => { '>=', \"current_timestamp-'7 days'::interval" },
}
},
{