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.pm81
1 files changed, 61 insertions, 20 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 133c83024..9c0018f38 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -9,6 +9,8 @@ use POSIX qw(strftime strcoll);
use Digest::SHA qw(sha1_hex);
use mySociety::EmailUtil qw(is_valid_email);
use if !$ENV{TRAVIS}, 'Image::Magick';
+use DateTime::Format::Strptime;
+
use FixMyStreet::SendReport;
@@ -130,9 +132,21 @@ sub index : Path : Args(0) {
$c->stash->{categories} = $c->cobrand->problems->categories_summary();
+ $c->stash->{total_bodies} = $c->model('DB::Body')->count();
+
return 1;
}
+sub config_page : Path( 'config' ) : Args(0) {
+ my ($self, $c) = @_;
+ my $dir = $c->stash->{additional_template_paths}->[0];
+ my $git_version = `cd $dir && git describe --tags`;
+ chomp $git_version;
+ $c->stash(
+ git_version => $git_version,
+ );
+}
+
sub timeline : Path( 'timeline' ) : Args(0) {
my ($self, $c) = @_;
@@ -411,7 +425,7 @@ sub update_contacts : Private {
sub body_params : Private {
my ( $self, $c ) = @_;
- my @fields = qw/name endpoint jurisdiction api_key send_method send_comments suppress_alerts send_extended_statuses comment_user_id can_be_devolved parent/;
+ my @fields = qw/name endpoint jurisdiction api_key send_method send_comments suppress_alerts send_extended_statuses comment_user_id can_be_devolved parent deleted/;
my %defaults = map { $_ => '' } @fields;
%defaults = ( %defaults,
send_comments => 0,
@@ -420,6 +434,7 @@ sub body_params : Private {
send_extended_statuses => 0,
can_be_devolved => 0,
parent => undef,
+ deleted => 0,
);
my %params = map { $_ => $c->req->param($_) || $defaults{$_} } @fields;
return \%params;
@@ -430,6 +445,7 @@ sub display_contacts : Private {
my $contacts = $c->stash->{body}->contacts->search(undef, { order_by => [ 'category' ] } );
$c->stash->{contacts} = $contacts;
+ $c->stash->{live_contacts} = $contacts->search({ deleted => 0 });
if ( $c->req->param('text') && $c->req->param('text') == 1 ) {
$c->stash->{template} = 'admin/council_contacts.txt';
@@ -546,10 +562,15 @@ sub reports : Path('reports') {
$query->{'-or'} = [
'me.areas' => { like => "%,$1,%" }
];
+ } elsif ($search =~ /^ref:(\d+)$/) {
+ $query->{'-or'} = [
+ 'me.external_id' => { like => "%$1%" }
+ ];
} else {
$query->{'-or'} = [
'me.id' => $search_n,
'user.email' => { ilike => $like_search },
+ 'me.external_id' => { ilike => $like_search },
'me.name' => { ilike => $like_search },
'me.title' => { ilike => $like_search },
detail => { ilike => $like_search },
@@ -749,11 +770,15 @@ sub report_edit : Path('report_edit') : Args(1) {
$problem->user( $user );
}
+ # Deal with photos
if ( $c->req->param('remove_photo') ) {
$problem->photo(undef);
}
+ if ( $new_state eq 'hidden' ) {
+ unlink glob FixMyStreet->path_to( 'web', 'photo', $problem->id . '.*' );
+ }
- if ( $new_state eq 'confirmed' and $old_state eq 'unconfirmed' ) {
+ if ( $problem->is_visible() and $old_state eq 'unconfirmed' ) {
$problem->confirmed( \'ms_current_timestamp()' );
}
@@ -894,7 +919,7 @@ sub update_edit : Path('update_edit') : Args(1) {
$update->name( $c->req->param('name') || '' );
$update->text( $c->req->param('text') );
$update->anonymous( $c->req->param('anonymous') );
- $update->state( $c->req->param('state') );
+ $update->state( $new_state );
if ( $c->req->param('email') ne $update->user->email ) {
my $user =
@@ -914,6 +939,10 @@ sub update_edit : Path('update_edit') : Args(1) {
}
}
+ if ( $new_state eq 'hidden' ) {
+ unlink glob FixMyStreet->path_to( 'web', 'photo', 'c', $update->id . '.*' );
+ }
+
$update->update;
$c->stash->{status_message} = '<p><em>' . _('Updated!') . '</em></p>';
@@ -954,6 +983,11 @@ sub user_add : Path('user_edit') : Args(0) {
$c->forward('check_token');
+ if ( $c->cobrand->moniker eq 'zurich' and $c->req->param('email') eq '' ) {
+ $c->stash->{field_errors}->{email} = _('Please enter a valid email');
+ return 1;
+ }
+
return unless $c->req->param('name') && $c->req->param('email');
my $user = $c->model('DB::User')->find_or_create( {
@@ -1001,6 +1035,11 @@ sub user_edit : Path('user_edit') : Args(1) {
$user->email( $c->req->param('email') );
$user->from_body( $c->req->param('body') || undef );
$user->flagged( $c->req->param('flagged') || 0 );
+
+ if ( $c->cobrand->moniker eq 'zurich' and $user->email eq '' ) {
+ $c->stash->{field_errors}->{email} = _('Please enter a valid email');
+ return 1;
+ }
$user->update;
if ($edited) {
@@ -1024,8 +1063,20 @@ sub flagged : Path('flagged') : Args(0) {
$c->stash->{problems} = [ $problems->all ];
my $users = $c->model('DB::User')->search( { flagged => 1 } );
+ my @users = $users->all;
+ my %email2user = map { $_->email => $_ } @users;
+ $c->stash->{users} = [ @users ];
- $c->stash->{users} = $users;
+ my @abuser_emails = $c->model('DB::Abuse')->all();
+
+ foreach my $email (@abuser_emails) {
+ # 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 };
+ }
+ }
return 1;
}
@@ -1042,26 +1093,15 @@ sub stats : Path('stats') : Args(0) {
if ( $c->req->param('getcounts') ) {
my ( $start_date, $end_date, @errors );
+ my $parser = DateTime::Format::Strptime->new( pattern => '%d/%m/%Y' );
- eval {
- $start_date = DateTime->new(
- year => $c->req->param('start_date_year'),
- month => $c->req->param('start_date_month'),
- day => $c->req->param('start_date_day'),
- );
- };
+ $start_date = $parser-> parse_datetime ( $c->req->param('start_date') );
- push @errors, _('Invalid start date') if $@;
+ push @errors, _('Invalid start date') unless defined $start_date;
- eval {
- $end_date = DateTime->new(
- year => $c->req->param('end_date_year'),
- month => $c->req->param('end_date_month'),
- day => $c->req->param('end_date_day'),
- );
- };
+ $end_date = $parser-> parse_datetime ( $c->req->param('end_date') ) ;
- push @errors, _('Invalid end date') if $@;
+ push @errors, _('Invalid end date') unless defined $end_date;
$c->stash->{errors} = \@errors;
$c->stash->{start_date} = $start_date;
@@ -1148,6 +1188,7 @@ sub set_allowed_pages : Private {
'users' => [_('Users'), 5],
'flagged' => [_('Flagged'), 6],
'stats' => [_('Stats'), 6],
+ 'config' => [ undef, undef ],
'user_edit' => [undef, undef],
'body' => [undef, undef],
'body_edit' => [undef, undef],