aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm33
-rw-r--r--perllib/FixMyStreet/App/Controller/Dashboard.pm16
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm8
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm28
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Rss.pm4
5 files changed, 29 insertions, 60 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 0134dad5d..f9ea383f8 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -70,8 +70,6 @@ sub index : Path : Args(0) {
return $c->cobrand->admin();
}
- my $site_restriction = $c->cobrand->site_restriction();
-
my $problems = $c->cobrand->problems->summary_count;
my %prob_counts =
@@ -85,7 +83,7 @@ sub index : Path : Args(0) {
for ( FixMyStreet::DB::Result::Problem->visible_states() );
$c->stash->{total_problems_users} = $c->cobrand->problems->unique_users;
- my $comments = $c->model('DB::Comment')->summary_count( $site_restriction );
+ my $comments = $c->model('DB::Comment')->summary_count( $c->cobrand->body_restriction );
my %comment_counts =
map { $_->state => $_->get_column('state_count') } $comments->all;
@@ -150,7 +148,6 @@ sub config_page : Path( 'config' ) : Args(0) {
sub timeline : Path( 'timeline' ) : Args(0) {
my ($self, $c) = @_;
- my $site_restriction = $c->cobrand->site_restriction();
my %time;
$c->model('DB')->schema->storage->sql_maker->quote_char( '"' );
@@ -171,7 +168,7 @@ sub timeline : Path( 'timeline' ) : Args(0) {
push @{$time{$_->whenanswered->epoch}}, { type => 'quesAnswered', date => $_->whenanswered, obj => $_ } if $_->whenanswered;
}
- my $updates = $c->model('DB::Comment')->timeline( $site_restriction );
+ my $updates = $c->model('DB::Comment')->timeline( $c->cobrand->body_restriction );
foreach ($updates->all) {
push @{$time{$_->created->epoch}}, { type => 'update', date => $_->created, obj => $_} ;
@@ -538,8 +535,6 @@ sub reports : Path('reports') {
if (my $search = $c->get_param('search')) {
$c->stash->{searched} = $search;
- my $site_restriction = $c->cobrand->site_restriction;
-
my $search_n = 0;
$search_n = int($search) if $search =~ /^\d+$/;
@@ -616,9 +611,10 @@ sub reports : Path('reports') {
}
if (@$query) {
- my $updates = $c->model('DB::Comment')->search(
+ my $updates = $c->model('DB::Comment')
+ ->to_body($c->cobrand->body_restriction)
+ ->search(
{
- %{ $site_restriction },
-or => $query,
},
{
@@ -650,8 +646,6 @@ sub reports : Path('reports') {
sub report_edit : Path('report_edit') : Args(1) {
my ( $self, $c, $id ) = @_;
- my $site_restriction = $c->cobrand->site_restriction;
-
my $problem = $c->cobrand->problems->search( { id => $id } )->first;
$c->detach( '/page_error_404_not_found' )
@@ -874,13 +868,9 @@ sub users: Path('users') : Args(0) {
sub update_edit : Path('update_edit') : Args(1) {
my ( $self, $c, $id ) = @_;
- my $site_restriction = $c->cobrand->site_restriction;
- my $update = $c->model('DB::Comment')->search(
- {
- id => $id,
- %{$site_restriction},
- }
- )->first;
+ my $update = $c->model('DB::Comment')
+ ->to_body($c->cobrand->body_restriction)
+ ->search({ id => $id })->first;
$c->detach( '/page_error_404_not_found' )
unless $update;
@@ -1121,9 +1111,6 @@ sub stats : Path('stats') : Args(0) {
my $bymonth = $c->get_param('bymonth');
$c->stash->{bymonth} = $bymonth;
- my ( %body, %dates );
- $body{bodies_str} = { like => $c->get_param('body') }
- if $c->get_param('body');
$c->stash->{selected_body} = $c->get_param('body');
@@ -1154,14 +1141,12 @@ sub stats : Path('stats') : Args(0) {
);
}
- my $p = $c->cobrand->problems->search(
+ my $p = $c->cobrand->problems->to_body($c->get_param('body'))->search(
{
-AND => [
$field => { '>=', $start_date},
$field => { '<=', $end_date + $one_day },
],
- %body,
- %dates,
},
\%select,
);
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm
index c3aa35008..faddaa89e 100644
--- a/perllib/FixMyStreet/App/Controller/Dashboard.pm
+++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm
@@ -89,6 +89,7 @@ sub index : Path : Args(0) {
my ( $self, $c ) = @_;
my $body = $c->forward('check_page_allowed');
+ $c->stash->{body} = $body;
# Set up the data for the dropdowns
@@ -112,7 +113,6 @@ sub index : Path : Args(0) {
$c->stash->{category} = $c->get_param('category');
my %where = (
- bodies_str => $body->id, # XXX Does this break in a two tier council? Restriction needs looking at...
'problem.state' => [ FixMyStreet::DB::Result::Problem->visible_states() ],
);
$where{areas} = { 'like', '%,' . $c->stash->{ward} . ',%' }
@@ -155,7 +155,7 @@ sub index : Path : Args(0) {
%$prob_where,
'me.confirmed' => { '>=', $dtf->format_datetime( $now->clone->subtract( days => 30 ) ) },
};
- my $problems_rs = $c->cobrand->problems->search( $params );
+ my $problems_rs = $c->cobrand->problems->to_body($body)->search( $params );
my @problems = $problems_rs->all;
my %problems;
@@ -270,12 +270,14 @@ sub export_as_csv {
sub updates_search : Private {
my ( $self, $c, $time ) = @_;
+ my $body = $c->stash->{body};
+
my $params = {
%{$c->stash->{where}},
'me.confirmed' => { '>=', $time },
};
- my $comments = $c->model('DB::Comment')->search(
+ my $comments = $c->model('DB::Comment')->to_body($body)->search(
$params,
{
group_by => [ 'problem_state' ],
@@ -302,7 +304,7 @@ sub updates_search : Private {
my $col = shift @$vars;
my $substmt = "select min(id) from comment where me.problem_id=comment.problem_id and problem_state in ('"
. join("','", @$vars) . "')";
- $comments = $c->model('DB::Comment')->search(
+ $comments = $c->model('DB::Comment')->to_body($body)->search(
{ %$params,
problem_state => $vars,
'me.id' => \"= ($substmt)",
@@ -319,7 +321,7 @@ sub updates_search : Private {
$counts{$col} = int( ($comments->get_column('time')||0) / 60 / 60 / 24 + 0.5 );
}
- $counts{fixed_user} = $c->model('DB::Comment')->search(
+ $counts{fixed_user} = $c->model('DB::Comment')->to_body($body)->search(
{ %$params, mark_fixed => 1, problem_state => undef }, { join => 'problem' }
)->count;
@@ -327,7 +329,7 @@ sub updates_search : Private {
%{$c->stash->{prob_where}},
'me.confirmed' => { '>=', $time },
};
- $counts{total} = $c->cobrand->problems->search( $params )->count;
+ $counts{total} = $c->cobrand->problems->to_body($body)->search( $params )->count;
$params = {
%{$c->stash->{prob_where}},
@@ -335,7 +337,7 @@ sub updates_search : Private {
state => 'confirmed',
'(select min(id) from comment where me.id=problem_id and problem_state is not null)' => undef,
};
- $counts{not_marked} = $c->cobrand->problems->search( $params )->count;
+ $counts{not_marked} = $c->cobrand->problems->to_body($body)->search( $params )->count;
return \%counts;
}
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index 83d5f7adb..9db9386f5 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -37,10 +37,6 @@ sub my : Path : Args(0) {
my $params = {
state => [ keys %$states ],
};
- $params = {
- %{ $c->cobrand->problems_clause },
- %$params
- } if $c->cobrand->problems_clause;
my $category = $c->get_param('filter_category');
if ( $category ) {
@@ -48,7 +44,9 @@ sub my : Path : Args(0) {
$c->stash->{filter_category} = $category;
}
- my $rs = $c->user->problems->search( $params, {
+ my $rs = $c->user->problems
+ ->to_body($c->cobrand->body_restriction)
+ ->search( $params, {
order_by => { -desc => 'confirmed' },
rows => 50
} )->page( $p_page );
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 4582843bd..25d5cd82e 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -269,9 +269,7 @@ sub rss_ward : Path('/rss/reports') : Args(2) {
# Problems sent to a council
$c->stash->{type} = 'council_problems';
$c->stash->{title_params} = { COUNCIL => $c->stash->{body}->name };
- # XXX This looks up in both bodies_str and areas, but is only using body ID.
- # This will not work properly in any install where body IDs are not === area IDs.
- $c->stash->{db_params} = [ $c->stash->{body}->id, $c->stash->{body}->id ];
+ $c->stash->{db_params} = [ $c->stash->{body}->id ];
}
# Send on to the RSS generation
@@ -417,29 +415,16 @@ sub load_and_group_problems : Private {
$where->{category} = $category;
}
+ my $problems = $c->cobrand->problems;
+
if ($c->stash->{ward}) {
$where->{areas} = { 'like', '%,' . $c->stash->{ward}->{id} . ',%' };
- $where->{bodies_str} = [
- undef,
- $c->stash->{body}->id,
- { 'like', $c->stash->{body}->id . ',%' },
- { 'like', '%,' . $c->stash->{body}->id },
- ];
+ $problems = $problems->to_body($c->stash->{body});
} elsif ($c->stash->{body}) {
- # XXX FixMyStreet used to have the following line so that reports not
- # currently sent anywhere could still be listed in the appropriate
- # (body/area), as they were the same. Now they're not, not sure if
- # there's a way to do this easily.
- #$where->{areas} = { 'like', '%,' . $c->stash->{body}->id . ',%' };
- $where->{bodies_str} = [
- # undef,
- $c->stash->{body}->id,
- { 'like', $c->stash->{body}->id . ',%' },
- { 'like', '%,' . $c->stash->{body}->id },
- ];
+ $problems = $problems->to_body($c->stash->{body});
}
- my $problems = $c->cobrand->problems->search(
+ $problems = $problems->search(
$where,
{
order_by => $c->cobrand->reports_ordering,
@@ -463,7 +448,6 @@ sub load_and_group_problems : Private {
}
} else {
# Add to bodies it was sent to
- # XXX Assumes body ID matches "council ID"
my $bodies = $problem->bodies_str_ids;
foreach ( @$bodies ) {
next if $_ != $c->stash->{body}->id;
diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm
index 7aafc99ff..b58b79937 100755
--- a/perllib/FixMyStreet/App/Controller/Rss.pm
+++ b/perllib/FixMyStreet/App/Controller/Rss.pm
@@ -264,9 +264,9 @@ sub add_row : Private {
(my $link = $alert_type->item_link) =~ s/{{(.*?)}}/$row->{$1}/g;
(my $desc = _($alert_type->item_description)) =~ s/{{(.*?)}}/$row->{$1}/g;
- my $hashref_restriction = $c->cobrand->site_restriction;
+ my $hashref_restriction = $c->cobrand->body_restriction;
my $base_url = $c->cobrand->base_url;
- if ( $hashref_restriction && $hashref_restriction->{bodies_str} && $row->{bodies_str} && $row->{bodies_str} ne $hashref_restriction->{bodies_str} ) {
+ if ( $hashref_restriction && $row->{bodies_str} && $row->{bodies_str} ne $hashref_restriction ) {
$base_url = $c->config->{BASE_URL};
}
my $url = $base_url . $link;