diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 89 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Alert.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 5 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 10 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Status.pm | 2 |
8 files changed, 87 insertions, 44 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index f54a862ab..4e288556f 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -71,25 +71,7 @@ sub index : Path : Args(0) { return $c->cobrand->admin(); } - my $problems = $c->cobrand->problems->summary_count; - - my %prob_counts = - map { $_->state => $_->get_column('state_count') } $problems->all; - - %prob_counts = - map { $_ => $prob_counts{$_} || 0 } - ( FixMyStreet::DB::Result::Problem->all_states() ); - $c->stash->{problems} = \%prob_counts; - $c->stash->{total_problems_live} += $prob_counts{$_} ? $prob_counts{$_} : 0 - for ( FixMyStreet::DB::Result::Problem->visible_states() ); - $c->stash->{total_problems_users} = $c->cobrand->problems->unique_users; - - my $comments = $c->cobrand->updates->summary_count; - - my %comment_counts = - map { $_->state => $_->get_column('state_count') } $comments->all; - - $c->stash->{comments} = \%comment_counts; + $c->forward('stats_by_state'); my $alerts = $c->model('DB::Alert')->summary_report_alerts( $c->cobrand->restriction ); @@ -129,11 +111,7 @@ sub index : Path : Args(0) { : _('n/a'); $c->stash->{questionnaires} = \%questionnaire_counts; - if ($c->get_param('show_categories')) { - $c->stash->{categories} = $c->cobrand->problems->categories_summary(); - } - - $c->stash->{total_bodies} = $c->model('DB::Body')->count(); + $c->forward('fetch_all_bodies'); return 1; } @@ -196,7 +174,7 @@ sub timeline : Path( 'timeline' ) : Args(0) { return 1; } -sub questionnaire : Path('questionnaire') : Args(0) { +sub questionnaire : Path('stats/questionnaire') : Args(0) { my ( $self, $c ) = @_; my $questionnaires = $c->model('DB::Questionnaire')->search( @@ -232,6 +210,11 @@ sub questionnaire : Path('questionnaire') : Args(0) { sub bodies : Path('bodies') : Args(0) { my ( $self, $c ) = @_; + if (my $body_id = $c->get_param('body')) { + $c->res->redirect( $c->uri_for( 'body', $body_id ) ); + return; + } + $c->forward( 'get_token' ); my $edit_activity = $c->model('DB::ContactsHistory')->search( @@ -784,7 +767,7 @@ sub report_edit : Path('report_edit') : Args(1) { } if ( $remove_photo_param || $new_state eq 'hidden' ) { - unlink glob FixMyStreet->path_to( 'web', 'photo', $problem->id . '.*' ); + $problem->get_photoset->delete_cached; } if ( $problem->is_visible() and $old_state eq 'unconfirmed' ) { @@ -1005,7 +988,7 @@ sub update_edit : Path('update_edit') : Args(1) { } if ( $remove_photo_param || $new_state eq 'hidden' ) { - unlink glob FixMyStreet->path_to( 'web', 'photo', 'c', $update->id . '.*' ); + $update->get_photoset->delete_cached; } $update->name( $c->get_param('name') || '' ); @@ -1135,9 +1118,21 @@ sub user_edit : Path('user_edit') : Args(1) { return; } - $user->update; - if ($edited) { - $c->forward( 'log_edit', [ $id, 'user', 'edit' ] ); + my $existing_user = $c->model('DB::User')->search({ email => $user->email, id => { '!=', $user->id } })->first; + if ($existing_user) { + foreach (qw(Problem Comment Alert)) { + $c->model("DB::$_") + ->search({ user_id => $user->id }) + ->update({ user_id => $existing_user->id }); + } + $user->delete; + $c->forward( 'log_edit', [ $id, 'user', 'merge' ] ); + $c->res->redirect( $c->uri_for( 'user_edit', $existing_user->id ) ); + } else { + $user->update; + if ($edited) { + $c->forward( 'log_edit', [ $id, 'user', 'edit' ] ); + } } $c->stash->{status_message} = @@ -1175,6 +1170,36 @@ sub flagged : Path('flagged') : Args(0) { return 1; } +sub stats_by_state : Path('stats/state') : Args(0) { + my ( $self, $c ) = @_; + + my $problems = $c->cobrand->problems->summary_count; + + my %prob_counts = + map { $_->state => $_->get_column('state_count') } $problems->all; + + %prob_counts = + map { $_ => $prob_counts{$_} || 0 } + ( FixMyStreet::DB::Result::Problem->all_states() ); + $c->stash->{problems} = \%prob_counts; + $c->stash->{total_problems_live} += $prob_counts{$_} ? $prob_counts{$_} : 0 + for ( FixMyStreet::DB::Result::Problem->visible_states() ); + $c->stash->{total_problems_users} = $c->cobrand->problems->unique_users; + + my $comments = $c->cobrand->updates->summary_count; + + my %comment_counts = + map { $_->state => $_->get_column('state_count') } $comments->all; + + $c->stash->{comments} = \%comment_counts; +} + +sub stats_fix_rate : Path('stats/fix-rate') : Args(0) { + my ( $self, $c ) = @_; + + $c->stash->{categories} = $c->cobrand->problems->categories_summary(); +} + sub stats : Path('stats') : Args(0) { my ( $self, $c ) = @_; @@ -1273,7 +1298,6 @@ sub set_allowed_pages : Private { 'bodies' => [_('Bodies'), 1], 'reports' => [_('Reports'), 2], 'timeline' => [_('Timeline'), 3], - 'questionnaire' => [_('Survey'), 4], 'users' => [_('Users'), 5], 'flagged' => [_('Flagged'), 6], 'stats' => [_('Stats'), 7], @@ -1540,7 +1564,8 @@ sub check_page_allowed : Private { $c->forward('set_allowed_pages'); - (my $page = $c->req->action) =~ s#admin/?##; + (my $page = $c->req->path) =~ s#admin/?##; + $page =~ s#/.*##; $page ||= 'summary'; diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 6972bbc04..ddda02abd 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -5,6 +5,7 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } use mySociety::EmailUtil qw(is_valid_email); +use FixMyStreet::Gaze; =head1 NAME @@ -441,11 +442,7 @@ sub determine_location : Private { $c->go('index'); } - my $dist = - mySociety::Gaze::get_radius_containing_population( $c->stash->{latitude}, - $c->stash->{longitude}, 200000 ); - $dist = int( $dist * 10 + 0.5 ); - $dist = $dist / 10.0; + my $dist = FixMyStreet::Gaze::get_radius_containing_population($c->stash->{latitude}, $c->stash->{longitude}); $c->stash->{population_radius} = $dist; return 1; diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index d24d3ff71..2734491fa 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -43,7 +43,7 @@ sub during :LocalRegex('^(temp|fulltemp)\.([0-9a-f]{40}\.(?:jpeg|png|gif|tiff))$ $c->forward( 'output', [ $photo ] ); } -sub index :LocalRegex('^(c/)?(\d+)(?:\.(\d+))?(?:\.(full|tn|fp))?\.(?:jpeg|png|gif|tiff)$') { +sub index :LocalRegex('^(c/)?([1-9]\d*)(?:\.(\d+))?(?:\.(full|tn|fp))?\.(?:jpeg|png|gif|tiff)$') { my ( $self, $c ) = @_; my ( $is_update, $id, $photo_number, $size ) = @{ $c->req->captures }; diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 475a29fb5..b3e546c2c 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -130,6 +130,17 @@ sub load_problem_or_display_error : Private { } $c->stash->{problem} = $problem; + if ( $c->user_exists && $c->user->has_permission_to(moderate => $problem->bodies_str) ) { + $c->stash->{problem_original} = $problem->find_or_new_related( + moderation_original_data => { + title => $problem->title, + detail => $problem->detail, + photo => $problem->photo, + anonymous => $problem->anonymous, + } + ); + } + return 1; } diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 5df182506..76098c119 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -1053,6 +1053,11 @@ sub save_user_and_report : Private { $report->external_source( $c->config->{MESSAGE_MANAGER_URL} ) ; } + if ( $report->is_from_abuser ) { + $c->stash->{template} = 'tokens/abuse.html'; + $c->detach; + } + if ( $c->stash->{is_social_user} ) { my $token = $c->model("DB::Token")->create( { scope => 'problem/social', diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index af4ccff03..275a300bd 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -402,6 +402,11 @@ sub save_update : Private { $update->photo($fileid); } + if ( $update->is_from_abuser ) { + $c->stash->{template} = 'tokens/abuse.html'; + $c->detach; + } + if ( $c->stash->{is_social_user} ) { my $token = $c->model("DB::Token")->create( { scope => 'update/social', diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index 8d4f8313c..183b233a8 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -8,7 +8,7 @@ use XML::RSS; use FixMyStreet::App::Model::PhotoSet; -use mySociety::Gaze; +use FixMyStreet::Gaze; use mySociety::Locale; use mySociety::MaPit; use mySociety::Sundries qw(ordinal); @@ -143,10 +143,10 @@ sub local_problems_ll : Private { $c->stash->{qs} .= ";d=$d"; $d = 100 if $d > 100; } else { - $d = mySociety::Gaze::get_radius_containing_population( $lat, $lon, 200000 ); - $d = int( $d * 10 + 0.5 ) / 10; - mySociety::Locale::in_gb_locale { - $d = sprintf("%f", $d); + $d = FixMyStreet::Gaze::get_radius_containing_population($lat, $lon); + # Needs to be with a '.' for db passing + $d = mySociety::Locale::in_gb_locale { + sprintf("%f", $d); } } diff --git a/perllib/FixMyStreet/App/Controller/Status.pm b/perllib/FixMyStreet/App/Controller/Status.pm index 931c7bd47..57c8f362e 100755 --- a/perllib/FixMyStreet/App/Controller/Status.pm +++ b/perllib/FixMyStreet/App/Controller/Status.pm @@ -58,7 +58,7 @@ sub index : Path : Args(0) { alerts_unconfirmed => $c->stash->{alerts}{0}, questionnaires_sent => $c->stash->{questionnaires}{total}, questionnaires_answered => $c->stash->{questionnaires}{1}, - bodies => $c->stash->{total_bodies}, + bodies => scalar @{$c->stash->{bodies}}, contacts => $c->stash->{contacts}{total}, }; my $body = JSON->new->utf8(1)->pretty->encode($data); |