diff options
Diffstat (limited to 'perllib/FixMyStreet/App')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 87 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/JSON.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 2 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Questionnaire.pm | 23 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 34 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 8 |
7 files changed, 142 insertions, 22 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 405ee37ec..e5c0133cf 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 ); @@ -614,6 +616,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 ) = @_; @@ -737,6 +769,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 ) = @_; @@ -840,9 +917,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], @@ -890,7 +969,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.') ] ); } diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 0f871508e..d3a4500c6 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -189,7 +189,7 @@ sub display_location : Private { { latitude => $p->latitude, longitude => $p->longitude, - colour => $p->state eq 'fixed' ? 'green' : 'red', + colour => $p->is_fixed ? 'green' : 'red', id => $p->id, title => $p->title, } diff --git a/perllib/FixMyStreet/App/Controller/JSON.pm b/perllib/FixMyStreet/App/Controller/JSON.pm index a89fb3e6c..f3607341a 100644 --- a/perllib/FixMyStreet/App/Controller/JSON.pm +++ b/perllib/FixMyStreet/App/Controller/JSON.pm @@ -71,12 +71,12 @@ sub problems : Local { } # query the database - my ( $state, $date_col ); + my ( @state, $date_col ); if ( $type eq 'new_problems' ) { - $state = 'confirmed'; + @state = FixMyStreet::DB::Result::Problem->open_states(); $date_col = 'confirmed'; } elsif ( $type eq 'fixed_problems' ) { - $state = 'fixed'; + @state = FixMyStreet::DB::Result::Problem->fixed_states(); $date_col = 'lastupdate'; } @@ -86,7 +86,7 @@ sub problems : Local { '>=' => $start_dt, '<=' => $end_dt + $one_day, }, - state => $state, + state => [ @state ], }; $query->{category} = $category if $category; my @problems = $c->cobrand->problems->search( $query, { diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 17862aa0a..b4fa3a457 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -48,7 +48,7 @@ sub index :Path :Args(0) { $c->detach( 'no_photo' ) if $id =~ /\D/; @photo = $c->cobrand->problems->search( { id => $id, - state => [ 'confirmed', 'fixed', 'partial' ], + state => [ FixMyStreet::DB::Result::Problem->visible_states(), 'partial' ], photo => { '!=', undef }, } ); } diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index a87aff330..a8bdca7a4 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -41,7 +41,7 @@ sub check_questionnaire : Private { $c->detach; } - unless ( $questionnaire->problem->state eq 'confirmed' || $questionnaire->problem->state eq 'fixed' ) { + unless ( $questionnaire->problem->is_visible ) { $c->detach('missing_problem'); } @@ -121,13 +121,19 @@ sub submit_creator_fixed : Private { my $questionnaire = $c->model( 'DB::Questionnaire' )->find_or_new( { problem_id => $c->stash->{problem}, - old_state => 'confirmed', - new_state => 'fixed', + # we want to look for any previous questionnaire here rather than one for + # this specific open state -> fixed transistion + old_state => [ FixMyStreet::DB::Result::Problem->open_states() ], + new_state => 'fixed - user', } ); unless ( $questionnaire->in_storage ) { + my $old_state = $c->flash->{old_state}; + $old_state = 'confirmed' unless FixMyStreet::DB::Result::Problem->open_states->{$old_state}; + $questionnaire->ever_reported( $c->stash->{reported} eq 'Yes' ? 1 : 0 ); + $questionnaire->old_state( $old_state ); $questionnaire->whensent( \'ms_current_timestamp()' ); $questionnaire->whenanswered( \'ms_current_timestamp()' ); $questionnaire->insert; @@ -149,8 +155,10 @@ sub submit_standard : Private { my $problem = $c->stash->{problem}; my $old_state = $problem->state; my $new_state = ''; - $new_state = 'fixed' if $c->stash->{been_fixed} eq 'Yes' && $old_state eq 'confirmed'; - $new_state = 'confirmed' if $c->stash->{been_fixed} eq 'No' && $old_state eq 'fixed'; + $new_state = 'fixed - user' if $c->stash->{been_fixed} eq 'Yes' && + FixMyStreet::DB::Result::Problem->open_states()->{$old_state}; + $new_state = 'confirmed' if $c->stash->{been_fixed} eq 'No' && + FixMyStreet::DB::Result::Problem->fixed_states()->{$old_state}; # Record state change, if there was one if ( $new_state ) { @@ -159,7 +167,8 @@ sub submit_standard : Private { } # If it's not fixed and they say it's still not been fixed, record time update - if ( $c->stash->{been_fixed} eq 'No' && $old_state eq 'confirmed' ) { + if ( $c->stash->{been_fixed} eq 'No' && + FixMyStreet::DB::Result::Problem->open_states->{$old_state} ) { $problem->lastupdate( \'ms_current_timestamp()' ); } @@ -186,7 +195,7 @@ sub submit_standard : Private { user => $problem->user, text => $update, state => 'confirmed', - mark_fixed => $new_state eq 'fixed' ? 1 : 0, + mark_fixed => $new_state eq 'fixed - user' ? 1 : 0, mark_open => $new_state eq 'confirmed' ? 1 : 0, lang => $c->stash->{lang_code}, cobrand => $c->cobrand->moniker, diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 501dd2b41..add9d1371 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -51,8 +51,11 @@ sub update_problem : Private { my $update = $c->stash->{update}; my $problem = $c->stash->{problem} || $update->problem; + # we may need this if we display the questionnaire + my $old_state = $problem->state; + if ( $update->mark_fixed ) { - $problem->state('fixed'); + $problem->state('fixed - user'); if ( $update->user->id == $problem->user->id ) { $problem->send_questionnaire(0); @@ -65,6 +68,10 @@ sub update_problem : Private { } } + if ( $update->problem_state ) { + $problem->state( $update->problem_state ); + } + if ( $update->mark_open && $update->user->id == $problem->user->id ) { $problem->state('confirmed'); } @@ -75,6 +82,7 @@ sub update_problem : Private { $c->stash->{problem_id} = $problem->id; if ($display_questionnaire) { + $c->flash->{old_state} = $old_state; $c->detach('/questionnaire/creator_fixed'); } @@ -145,7 +153,7 @@ sub process_update : Private { my ( $self, $c ) = @_; my %params = - map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed', 'reopen' ); + map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed', 'state', 'reopen' ); $params{update} = Utils::cleanup_text( $params{update}, { allow_multiline => 1 } ); @@ -170,6 +178,12 @@ sub process_update : Private { } ); + if ( $params{state} ) { + $params{state} = 'fixed - council' + if $params{state} eq 'fixed' && $c->user && $c->user->belongs_to_council( $update->problem->council ); + $update->problem_state( $params{state} ); + } + $c->stash->{update} = $update; $c->stash->{add_alert} = $c->req->param('add_alert'); @@ -187,6 +201,22 @@ return false. sub check_for_errors : Private { my ( $self, $c ) = @_; + # they have to be an authority user to update the state + if ( $c->req->param('state') ) { + my $error = 0; + $error = 1 unless $c->user && $c->user->belongs_to_council( $c->stash->{update}->problem->council ); + + my $state = $c->req->param('state'); + $error = 1 unless ( grep { $state eq $_ } ( qw/confirmed closed fixed investigating planned/, 'in progress', 'fixed', 'fixed - user', 'fixed - council' ) ); + + if ( $error ) { + $c->stash->{errors} ||= []; + push @{ $c->stash->{errors} }, _('There was a problem with your update. Please try again.'); + return; + } + + } + # let the model check for errors $c->stash->{field_errors} ||= {}; my %field_errors = ( diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index feafc4b77..bf270a3b2 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -315,7 +315,7 @@ sub load_and_group_problems : Private { my $page = $c->req->params->{p} || 1; my $where = { - state => [ 'confirmed', 'fixed' ] + state => [ FixMyStreet::DB::Result::Problem->visible_states() ] }; if ($c->stash->{ward}) { $where->{areas} = { 'like', '%,' . $c->stash->{ward}->{id} . ',%' }; @@ -411,9 +411,11 @@ sub add_row { ? 'unknown' : ($problem->{age} > $fourweeks ? 'older' : 'new'); # Fixed problems are either old or new - push @{$fixed->{$council}{$duration_str}}, $problem if $problem->{state} eq 'fixed'; + push @{$fixed->{$council}{$duration_str}}, $problem if + exists FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}}; # Open problems are either unknown, older, or new - push @{$open->{$council}{$type}}, $problem if $problem->{state} eq 'confirmed'; + push @{$open->{$council}{$type}}, $problem if + exists FixMyStreet::DB::Result::Problem->open_states->{$problem->{state}}; push @$pins, { latitude => $problem->{latitude}, |