diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 87 |
1 files changed, 83 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index b55d02e5f..f7942c45a 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -56,10 +56,12 @@ sub index : Path : Args(0) { %prob_counts = map { $_ => $prob_counts{$_} || 0 } - qw(confirmed fixed unconfirmed hidden partial); + ('confirmed', 'investigating', 'in progress', 'closed', 'fixed - council', + 'fixed - user', 'fixed', 'unconfirmed', 'hidden', + 'partial', 'planned'); $c->stash->{problems} = \%prob_counts; - $c->stash->{total_problems_live} = - $prob_counts{confirmed} + $prob_counts{fixed}; + $c->stash->{total_problems_live} += $prob_counts{$_} + 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 ); @@ -646,6 +648,36 @@ sub report_edit : Path('report_edit') : Args(1) { return 1; } +sub search_users: Path('search_users') : Args(0) { + my ( $self, $c ) = @_; + + $c->forward('check_page_allowed'); + + if (my $search = $c->req->param('search')) { + $c->stash->{searched} = 1; + + my $search = $c->req->param('search'); + my $isearch = '%' . $search . '%'; + + my $search_n = 0; + $search_n = int($search) if $search =~ /^\d+$/; + + my $users = $c->model('DB::User')->search( + { + -or => [ + email => { ilike => $isearch }, + name => { ilike => $isearch }, + from_council => $search_n, + ] + } + ); + + $c->stash->{users} = [ $users->all ]; + } + + return 1; +} + sub update_edit : Path('update_edit') : Args(1) { my ( $self, $c, $id ) = @_; @@ -769,6 +801,51 @@ sub search_abuse : Path('search_abuse') : Args(0) { return 1; } +sub user_edit : Path('user_edit') : Args(1) { + my ( $self, $c, $id ) = @_; + + $c->forward('check_page_allowed'); + $c->forward('get_token'); + + my $user = $c->model('DB::User')->find( { id => $id } ); + $c->stash->{user} = $user; + + my @area_types = $c->cobrand->area_types; + my $areas = mySociety::MaPit::call('areas', \@area_types); + + my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas; + @councils_ids = $c->cobrand->filter_all_council_ids_list( @councils_ids ); + + $c->stash->{council_ids} = \@councils_ids; + $c->stash->{council_details} = $areas; + + if ( $c->req->param('submit') ) { + $c->forward('check_token'); + + my $edited = 0; + + if ( $user->email ne $c->req->param('email') || + $user->name ne $c->req->param('name' ) || + $user->from_council != $c->req->param('council') ) { + $edited = 1; + } + + $user->name( $c->req->param('name') ); + $user->email( $c->req->param('email') ); + $user->from_council( $c->req->param('council') || undef ); + $user->update; + + if ($edited) { + $c->forward( 'log_edit', [ $id, 'user', 'edit' ] ); + } + + $c->stash->{status_message} = + '<p><em>' . _('Updated!') . '</em></p>'; + } + + return 1; +} + sub list_flagged : Path('list_flagged') : Args(0) { my ( $self, $c ) = @_; @@ -872,9 +949,11 @@ sub set_allowed_pages : Private { 'search_reports' => [_('Search Reports'), 2], 'timeline' => [_('Timeline'), 3], 'questionnaire' => [_('Survey Results'), 4], + 'search_users' => [_('Search Users'), 5], 'search_abuse' => [_('Search Abuse'), 5], 'list_flagged' => [_('List Flagged'), 6], 'stats' => [_('Stats'), 6], + 'user_edit' => [undef, undef], 'council_contacts' => [undef, undef], 'council_edit' => [undef, undef], 'report_edit' => [undef, undef], @@ -922,7 +1001,7 @@ not then display 404 page sub check_token : Private { my ( $self, $c ) = @_; - if ( $c->req->param('token' ) ne $c->stash->{token} ) { + if ( !$c->req->param('token') || $c->req->param('token' ) ne $c->stash->{token} ) { $c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] ); } |