aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Admin.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm139
1 files changed, 30 insertions, 109 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 930739718..7af8bf098 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -39,19 +39,12 @@ Displays some summary information for the requests.
sub index : Path : Args(0) {
my ( $self, $c ) = @_;
- $c->forward('set_allowed_pages');
+ $c->forward('check_page_allowed');
my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction();
my $cobrand_restriction = $c->cobrand->moniker eq 'fixmystreet' ? {} : { cobrand => $c->cobrand->moniker };
- my $problems = $c->model('DB::Problem')->search(
- $site_restriction,
- {
- group_by => ['state'],
- select => [ 'state', { count => 'id' } ],
- as => [qw/state state_count/]
- }
- );
+ my $problems = $c->model('DB::Problem')->summary_count( $site_restriction );
my %prob_counts =
map { $_->state => $_->get_column('state_count') } $problems->all;
@@ -63,29 +56,14 @@ sub index : Path : Args(0) {
$c->stash->{total_problems_live} =
$prob_counts{confirmed} + $prob_counts{fixed};
- my $comments = $c->model('DB::Comment')->search(
- $site_restriction,
- {
- group_by => ['me.state'],
- select => [ 'me.state', { count => 'me.id' } ],
- as => [qw/state state_count/],
- join => 'problem'
- }
- );
+ my $comments = $c->model('DB::Comment')->summary_count( $site_restriction );
my %comment_counts =
map { $_->state => $_->get_column('state_count') } $comments->all;
$c->stash->{comments} = \%comment_counts;
- my $alerts = $c->model('DB::Alert')->search(
- $cobrand_restriction,
- {
- group_by => ['confirmed'],
- select => [ 'confirmed', { count => 'id' } ],
- as => [qw/confirmed confirmed_count/]
- }
- );
+ my $alerts = $c->model('DB::Alert')->summary_count( $cobrand_restriction );
my %alert_counts =
map { $_->confirmed => $_->get_column('confirmed_count') } $alerts->all;
@@ -95,14 +73,7 @@ sub index : Path : Args(0) {
$c->stash->{alerts} = \%alert_counts;
- my $contacts = $c->model('DB::Contact')->search(
- undef,
- {
- group_by => ['confirmed'],
- select => [ 'confirmed', { count => 'id' } ],
- as => [qw/confirmed confirmed_count/]
- }
- );
+ my $contacts = $c->model('DB::Contact')->summary_count;
my %contact_counts =
map { $_->confirmed => $_->get_column('confirmed_count') } $contacts->all;
@@ -113,15 +84,7 @@ sub index : Path : Args(0) {
$c->stash->{contacts} = \%contact_counts;
- my $questionnaires = $c->model('DB::Questionnaire')->search(
- $cobrand_restriction,
- {
- group_by => [ \'whenanswered is not null' ],
- select => [ \'(whenanswered is not null)', { count => 'me.id' } ],
- as => [qw/answered questionnaire_count/],
- join => 'problem'
- }
- );
+ my $questionnaires = $c->model('DB::Questionnaire')->summary_count( $cobrand_restriction );
my %questionnaire_counts = map {
$_->get_column('answered') => $_->get_column('questionnaire_count')
@@ -144,7 +107,7 @@ sub index : Path : Args(0) {
sub timeline : Path( 'timeline' ) : Args(0) {
my ($self, $c) = @_;
- $c->forward('set_allowed_pages');
+ $c->forward('check_page_allowed');
my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction();
my $cobrand_restriction = { cobrand => $c->cobrand->moniker };
@@ -195,7 +158,7 @@ sub timeline : Path( 'timeline' ) : Args(0) {
sub questionnaire : Path('questionnaire') : Args(0) {
my ( $self, $c ) = @_;
- $c->forward('set_allowed_pages');
+ $c->forward('check_page_allowed');
my $questionnaires = $c->model('DB::Questionnaire')->search(
{ whenanswered => \'is not null' }, { group_by => [ 'ever_reported' ], select => [ 'ever_reported', { count => 'me.id' } ], as => [qw/reported questionnaire_count/] }
@@ -218,7 +181,7 @@ sub questionnaire : Path('questionnaire') : Args(0) {
sub council_list : Path('council_list') : Args(0) {
my ( $self, $c ) = @_;
- $c->forward('set_allowed_pages');
+ $c->forward('check_page_allowed');
my $edit_activity = $c->model('DB::ContactsHistory')->search(
undef,
@@ -268,7 +231,7 @@ sub council_list : Path('council_list') : Args(0) {
sub council_contacts : Path('council_contacts') : Args(1) {
my ( $self, $c, $area_id ) = @_;
- $c->forward('set_allowed_pages');
+ $c->forward('check_page_allowed');
my $posted = $c->req->param('posted') || '';
$c->stash->{area_id} = $area_id;
@@ -392,7 +355,7 @@ sub setup_council_details : Private {
sub council_edit : Path('council_edit') : Args(2) {
my ( $self, $c, $area_id, $category ) = @_;
- $c->forward('set_allowed_pages');
+ $c->forward('check_page_allowed');
$c->stash->{area_id} = $area_id;
@@ -426,7 +389,7 @@ sub council_edit : Path('council_edit') : Args(2) {
sub search_reports : Path('search_reports') {
my ( $self, $c ) = @_;
- $c->forward('set_allowed_pages');
+ $c->forward('check_page_allowed');
if (my $search = $c->req->param('search')) {
$c->stash->{searched} = 1;
@@ -515,7 +478,7 @@ sub report_edit : Path('report_edit') : Args(1) {
$c->stash->{problem} = $problem;
$c->forward('get_token');
- $c->forward('set_allowed_pages');
+ $c->forward('check_page_allowed');
$c->stash->{updates} =
[ $c->model('DB::Comment')
@@ -722,7 +685,7 @@ sub update_edit : Path('update_edit') : Args(1) {
unless $update;
$c->forward('get_token');
- $c->forward('set_allowed_pages');
+ $c->forward('check_page_allowed');
$c->stash->{update} = $update;
@@ -791,64 +754,22 @@ sub update_edit : Path('update_edit') : Args(1) {
return 1;
}
-#
-#
-# sub main {
-# my $q = shift;
-#
-# my $logout = $q->param('logout');
-# my $timeout = $q->param('timeout');
-# if ($logout) {
-# if (!$timeout) {
-# print $q->redirect(-location => '?logout=1;timeout=' . (time() + 7));
-# return;
-# }
-# if (time() < $timeout) {
-# print $q->header(
-# -status => '401 Unauthorized',
-# -www_authenticate => 'Basic realm="www.fixmystreet.com admin pages"'
-# );
-# return;
-# }
-# }
-#
-# my $page = $q->param('page');
-# $page = "summary" if !$page;
-#
-# my $area_id = $q->param('area_id');
-# my $category = $q->param('category');
-# my $pages = allowed_pages($q);
-# my @allowed_actions = keys %$pages;
-#
-# if (!grep {$_ eq $page} @allowed_actions) {
-# not_found($q);
-# return;
-# }
-#
-# if ($page eq "councilslist") {
-# admin_councils_list($q);
-# } elsif ($page eq "councilcontacts") {
-# admin_council_contacts($q, $area_id);
-# } elsif ($page eq "counciledit") {
-# admin_council_edit($q, $area_id, $category);
-# } elsif ($page eq 'reports') {
-# admin_reports($q);
-# } elsif ($page eq 'report_edit') {
-# my $id = $q->param('id');
-# admin_edit_report($q, $id);
-# } elsif ($page eq 'update_edit') {
-# my $id = $q->param('id');
-# admin_edit_update($q, $id);
-# } elsif ($page eq 'timeline') {
-# admin_timeline($q);
-# } elsif ($page eq 'questionnaire') {
-# admin_questionnaire($q);
-# } else {
-# admin_summary($q);
-# }
-# }
-# Page::do_fastcgi(\&main);
-#
+sub check_page_allowed : Private {
+ my ( $self, $c ) = @_;
+
+ $c->forward('set_allowed_pages');
+
+ (my $page = $c->req->action) =~ s#admin/##;
+
+ $page ||= 'summary';
+
+ if ( !grep { $_ eq $page } keys %{ $c->stash->{allowed_pages} } ) {
+ $c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] );
+ }
+
+ return 1;
+}
+
sub trim {
my $self = shift;
my $e = shift;