diff options
author | Matthew Somerville <matthew@mysociety.org> | 2012-11-26 10:42:52 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2012-11-26 11:13:23 +0000 |
commit | 41576452fe7e5ccc73ec6a8ff9c2e675cd1806f3 (patch) | |
tree | f69d617eca8bd8bc19a71633921333f60d0b7528 | |
parent | 9b2202050226af4b632880865d2d5ac39878d9ef (diff) |
Consolidate user searching to one admin page.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 49 | ||||
-rw-r--r-- | t/app/controller/admin.t | 5 | ||||
-rw-r--r-- | templates/web/default/admin/search_abuse.html | 21 | ||||
-rw-r--r-- | templates/web/default/admin/search_users.html | 4 |
4 files changed, 26 insertions, 53 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index b53b6ab06..4999d16f2 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -739,8 +739,24 @@ sub search_users: Path('search_users') : Args(0) { ] } ); + my @users = $users->all; + my %email2user = map { $_->email => $_ } @users; + $c->stash->{users} = [ @users ]; + + my $emails = $c->model('DB::Abuse')->search( + { + email => { ilike => $isearch } + } + ); + foreach my $email ($emails->all) { + # Slight abuse of the boolean flagged value + if ($email2user{$email->email}) { + $email2user{$email->email}->flagged( 2 ); + } else { + push @{$c->stash->{users}}, { email => $email->email, flagged => 2 }; + } + } - $c->stash->{users} = [ $users->all ]; } return 1; @@ -847,26 +863,6 @@ sub update_edit : Path('update_edit') : Args(1) { return 1; } -sub search_abuse : Path('search_abuse') : Args(0) { - my ( $self, $c ) = @_; - - $c->forward('check_page_allowed'); - - my $search = $c->req->param('search'); - - if ($search) { - my $emails = $c->model('DB::Abuse')->search( - { - email => { ilike => "\%$search\%" } - } - ); - - $c->stash->{emails} = [ $emails->all ]; - } - - return 1; -} - sub user_edit : Path('user_edit') : Args(1) { my ( $self, $c, $id ) = @_; @@ -1033,13 +1029,12 @@ sub set_allowed_pages : Private { if( !$pages ) { $pages = { 'summary' => [_('Summary'), 0], - 'council_list' => [_('Council contacts'), 1], - 'search_reports' => [_('Search Reports'), 2], + 'council_list' => [_('Bodies'), 1], + 'search_reports' => [_('Reports'), 2], 'timeline' => [_('Timeline'), 3], - 'questionnaire' => [_('Survey Results'), 4], - 'search_users' => [_('Search Users'), 5], - 'search_abuse' => [_('Search Abuse'), 5], - 'list_flagged' => [_('List Flagged'), 6], + 'questionnaire' => [_('Survey'), 4], + 'search_users' => [_('Users'), 5], + 'list_flagged' => [_('Flagged'), 6], 'stats' => [_('Stats'), 6], 'user_edit' => [undef, undef], 'council_contacts' => [undef, undef], diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index 839bfd6b9..9ec15ec21 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -1066,9 +1066,8 @@ subtest 'report search' => sub { }; subtest 'search abuse' => sub { - $mech->get_ok( '/admin/search_abuse?search=example' ); - - $mech->content_contains('test4@example.com'); + $mech->get_ok( '/admin/search_users?search=example' ); + $mech->content_like(qr/test4\@example.com.*\n.*\n.*Email in abuse table/); }; subtest 'show flagged entries' => sub { diff --git a/templates/web/default/admin/search_abuse.html b/templates/web/default/admin/search_abuse.html deleted file mode 100644 index 0984e85cf..000000000 --- a/templates/web/default/admin/search_abuse.html +++ /dev/null @@ -1,21 +0,0 @@ -[% INCLUDE 'admin/header.html' title=loc('Search Abuse Table') %] - -<form method="get" action="[% c.uri_for('search_abuse') %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"> - <label for="search">[% loc('Search:') %]</label> <input type="text" name="search" size="30" id="search"> -</form> - - -[% IF emails.size > 0 %] -<table cellspacing="0" cellpadding="2" border="1"> - <tr> - <th>[% loc('Email') %]</th> - </tr> -[%- FOREACH foo IN emails %] - <tr> - <td>[%- foo.email | html -%]</td> - </tr> -[%- END -%] -</table> -[% END %] - -[% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/default/admin/search_users.html b/templates/web/default/admin/search_users.html index 18c964dfe..0b4ba88e7 100644 --- a/templates/web/default/admin/search_users.html +++ b/templates/web/default/admin/search_users.html @@ -20,8 +20,8 @@ <td>[% PROCESS value_or_nbsp value=user.name %]</td> <td><a href="[% c.uri_for( 'search_reports', search => user.email ) %]">[% PROCESS value_or_nbsp value=user.email %]</a></td> <td>[% PROCESS value_or_nbsp value=user.from_council %]</td> - <td>[% user.flagged ? loc('Yes') : ' ' %]</td> - <td><a href="[% c.uri_for( 'user_edit', user.id ) %]">[% loc('Edit') %]</a></td> + <td>[% user.flagged == 2 ? loc('(Email in abuse table)') : user.flagged ? loc('Yes') : ' ' %]</td> + <td>[% IF user.id %]<a href="[% c.uri_for( 'user_edit', user.id ) %]">[% loc('Edit') %]</a>[% END %]</td> </tr> [%- END -%] </table> |