From c9773705e4c611363474144f69182ad421187242 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 16 Jun 2011 12:17:35 +0100 Subject: handle new states in report display and updating --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 2f1d88d08..88b53494b 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -56,7 +56,7 @@ sub update_problem : Private { my $problem = $c->stash->{problem} || $update->problem; if ( $update->mark_fixed ) { - $problem->state('fixed'); + $problem->state('fixed - user'); if ( $update->user->id == $problem->user->id ) { $problem->send_questionnaire(0); -- cgit v1.2.3 From c35ef08e4f6f51874d1ce46dce3b4895dca6fe54 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 16 Jun 2011 16:46:04 +0100 Subject: stop using hard coded names for fixed/visible states ( work in progress ) --- perllib/FixMyStreet/App/Controller/Around.pm | 2 +- perllib/FixMyStreet/App/Controller/Reports.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 0c26220e0..b380eedfc 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/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index e1983c855..3f7bd268f 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -256,7 +256,7 @@ sub load_and_group_problems : Private { my ( $self, $c ) = @_; my $where = { - state => [ 'confirmed', 'fixed' ] + state => [ FixMyStreet::DB::Result::Problem->visible_states() ] }; my @extra_cols = (); if ($c->stash->{ward}) { -- cgit v1.2.3 From 630ed304d67f83ecd8848bf665b03fd7c27fff46 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 21 Jun 2011 16:11:42 +0100 Subject: remove more hardcoded references to fixed --- perllib/FixMyStreet/App/Controller/Photo.pm | 2 +- perllib/FixMyStreet/App/Controller/Questionnaire.pm | 9 +++++---- perllib/FixMyStreet/App/Controller/Reports.pm | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') 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 19d057958..27c413259 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -48,7 +48,7 @@ sub load_questionnaire : Private { $c->detach; } - unless ( $questionnaire->problem->state eq 'confirmed' || $questionnaire->problem->state eq 'fixed' ) { + unless ( $questionnaire->problem->is_visible ) { $c->detach('missing_problem'); } @@ -129,7 +129,7 @@ sub submit_creator_fixed : Private { { problem_id => $c->stash->{problem}, old_state => 'confirmed', - new_state => 'fixed', + new_state => 'fixed - user', } ); @@ -156,8 +156,9 @@ 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' && $old_state eq 'confirmed'; + $new_state = 'confirmed' if $c->stash->{been_fixed} eq 'No' && + exists FixMyStreet::DB::Result::Problem->fixed_states()->{$old_state}; # Record state change, if there was one if ( $new_state ) { diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 58b689bf9..2f895015b 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -354,7 +354,8 @@ 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'; } -- cgit v1.2.3 From ddde474e6a1dfb1591e8cfe06dc05c8be3312853 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 21 Jun 2011 17:54:16 +0100 Subject: check for open states instead of confirmed --- perllib/FixMyStreet/App/Controller/JSON.pm | 8 ++++---- perllib/FixMyStreet/App/Controller/Reports.pm | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/JSON.pm b/perllib/FixMyStreet/App/Controller/JSON.pm index 3a3010911..d9baeaaf8 100644 --- a/perllib/FixMyStreet/App/Controller/JSON.pm +++ b/perllib/FixMyStreet/App/Controller/JSON.pm @@ -70,12 +70,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 = 'created'; } elsif ( $type eq 'fixed_problems' ) { - $state = 'fixed'; + @state = FixMyStreet::DB::Result::Problem->fixed_states(); $date_col = 'lastupdate'; } @@ -85,7 +85,7 @@ sub problems : Local { '>=' => $start_dt, '<=' => $end_dt + $one_day, }, - state => $state, + state => [ @state ], }, { order_by => { -asc => 'confirmed' }, columns => [ diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 2f895015b..fc8c4cd0e 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -357,7 +357,8 @@ sub add_row { 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}}; } =head1 AUTHOR -- cgit v1.2.3 From 3d1798ff5ebf15d59c704545412c91d3a68b1035 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 21 Jun 2011 18:50:46 +0100 Subject: remove hard coded confirmeds from questionnaire --- perllib/FixMyStreet/App/Controller/Questionnaire.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index 27c413259..ad3827de9 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -128,7 +128,7 @@ sub submit_creator_fixed : Private { my $questionnaire = $c->model( 'DB::Questionnaire' )->find_or_new( { problem_id => $c->stash->{problem}, - old_state => 'confirmed', + old_state => [ FixMyStreet::DB::Result::Problem->open_states() ], new_state => 'fixed - user', } ); @@ -156,9 +156,10 @@ sub submit_standard : Private { my $problem = $c->stash->{problem}; my $old_state = $problem->state; my $new_state = ''; - $new_state = 'fixed - user' if $c->stash->{been_fixed} eq 'Yes' && $old_state eq 'confirmed'; + $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' && - exists FixMyStreet::DB::Result::Problem->fixed_states()->{$old_state}; + FixMyStreet::DB::Result::Problem->fixed_states()->{$old_state}; # Record state change, if there was one if ( $new_state ) { @@ -167,7 +168,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()' ); } -- cgit v1.2.3 From 4d646d87ad5a603d046c6c3e23e9688bf058ebcc Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 22 Jun 2011 09:16:12 +0100 Subject: add new states into admin --- perllib/FixMyStreet/App/Controller/Admin.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index abc454600..ae4154e98 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() ); my $comments = $c->model('DB::Comment')->summary_count( $site_restriction ); @@ -740,7 +742,7 @@ sub update_edit : Path('update_edit') : Args(1) { # If we're hiding an update, see if it marked as fixed and unfix if so if ( $new_state eq 'hidden' && $update->mark_fixed ) { - if ( $update->problem->state eq 'fixed' ) { + if ( $update->problem->is_fixed ) { $update->problem->state('confirmed'); $update->problem->update; } -- cgit v1.2.3 From 59e5a595bd0a903f25eb6210209cec5afe1f699c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 23 Jun 2011 14:06:03 +0100 Subject: prevent non authority users from changing the state on updates --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 88b53494b..02d111d9f 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -180,6 +180,15 @@ 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') ) { + unless ( $c->user && $c->user->from_authority ) { + $c->stash->{errors} ||= []; + push @{ $c->stash->{errors} }, _('There was a problem with your update. Please try again.'); + return; + } + } + # let the model check for errors my %field_errors = ( %{ $c->stash->{update_user}->check_for_errors }, -- cgit v1.2.3 From 159fa8ad9e2427d8b20586baec4c260a0c71b57c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 23 Jun 2011 15:46:55 +0100 Subject: update problem status from update --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 354690949..a131fbd35 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -65,6 +65,10 @@ sub update_problem : Private { } } + if ( $update->problem_state ) { + $problem->state( $update->problem_state ); + } + $problem->lastupdate( \'ms_current_timestamp()' ); $problem->update; @@ -126,7 +130,7 @@ sub process_update : Private { my ( $self, $c ) = @_; my %params = - map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed' ); + map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed', 'state' ); $params{update} = Utils::cleanup_text( $params{update}, { allow_multiline => 1 } ); @@ -152,6 +156,12 @@ sub process_update : Private { } ); + if ( $params{state} ) { + $params{state} = 'fixed - council' + if $params{state} eq 'fixed' && $c->user && $c->user->from_authority; + $update->problem_state( $params{state} ); + } + $c->stash->{update} = $update; $c->stash->{add_alert} = $c->req->param('add_alert'); -- cgit v1.2.3 From fb56c38856fe33c971903ab0efde1cf5d4829426 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 23 Jun 2011 16:34:19 +0100 Subject: check that state is permitted --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 41bc3a4bd..5421385fb 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -181,11 +181,18 @@ sub check_for_errors : Private { # they have to be an authority user to update the state if ( $c->req->param('state') ) { - unless ( $c->user && $c->user->from_authority ) { + my $error = 0; + $error = 1 unless $c->user && $c->user->from_authority; + + my $state = $c->req->param('state'); + $error = 1 unless ( grep { $state eq $_ } ( qw/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 -- cgit v1.2.3 From a20fc533b0f10646814742f1348c5f9141217efa Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 27 Jun 2011 11:03:57 +0100 Subject: change to use from_council in users table and store the council id in there so we can check that the problem is for the council the user is from --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 2d810d871..652694595 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -153,7 +153,8 @@ sub process_update : Private { if ( $params{state} ) { $params{state} = 'fixed - council' - if $params{state} eq 'fixed' && $c->user && $c->user->from_authority; + if $params{state} eq 'fixed' && $c->user && $c->user->from_council + && $c->user->from_council == $update->problem->council; $update->problem_state( $params{state} ); } @@ -177,7 +178,7 @@ sub check_for_errors : Private { # 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->from_authority; + $error = 1 unless $c->user && $c->user->from_council && $c->user->from_council == $c->stash->{update}->problem->council; my $state = $c->req->param('state'); $error = 1 unless ( grep { $state eq $_ } ( qw/closed fixed investigating planned/, 'in progress', 'fixed', 'fixed - user', 'fixed - council' ) ); -- cgit v1.2.3 From ef93992a2abbb3c800a2d6bbc112b284c4e227a6 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 27 Jun 2011 16:36:22 +0100 Subject: user searching and editing --- perllib/FixMyStreet/App/Controller/Admin.pm | 79 +++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index ae4154e98..f0790cbff 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -586,6 +586,83 @@ 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 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} = + '

' . _('Updated!') . '

'; + } + + return 1; +} + + =head2 set_allowed_pages Sets up the allowed_pages stash entry for checking if the current page is @@ -605,10 +682,12 @@ sub set_allowed_pages : Private { 'search_reports' => [_('Search Reports'), 2], 'timeline' => [_('Timeline'), 3], 'questionnaire' => [_('Survey Results'), 4], + 'search_users' => [_('Search Users'), 5], 'council_contacts' => [undef, undef], 'council_edit' => [undef, undef], 'report_edit' => [undef, undef], 'update_edit' => [undef, undef], + 'user_edit' => [undef, undef], } } -- cgit v1.2.3 From d40180650fbc0060c3d8cfbf9db60ca61b0e7e3a Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 27 Jun 2011 16:37:53 +0100 Subject: 404 if no token --- perllib/FixMyStreet/App/Controller/Admin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index f0790cbff..f38181be6 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -730,7 +730,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.') ] ); } -- cgit v1.2.3 From 0c3c4a0be17118ff4d8e01168df5938a947f28f6 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 27 Jun 2011 17:28:07 +0100 Subject: council users should be able to set state to confirmed --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 652694595..1ea0e88b4 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -181,7 +181,7 @@ sub check_for_errors : Private { $error = 1 unless $c->user && $c->user->from_council && $c->user->from_council == $c->stash->{update}->problem->council; my $state = $c->req->param('state'); - $error = 1 unless ( grep { $state eq $_ } ( qw/closed fixed investigating planned/, 'in progress', 'fixed', 'fixed - user', 'fixed - council' ) ); + $error = 1 unless ( grep { $state eq $_ } ( qw/confirmed closed fixed investigating planned/, 'in progress', 'fixed', 'fixed - user', 'fixed - council' ) ); if ( $error ) { $c->stash->{errors} ||= []; -- cgit v1.2.3 From f301d83e6bd7546b2f2a80067313dd17502581f8 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 28 Jun 2011 13:23:09 +0100 Subject: store correct old state in questionnaire when creator marks problem as fixed --- perllib/FixMyStreet/App/Controller/Questionnaire.pm | 6 ++++++ perllib/FixMyStreet/App/Controller/Report/Update.pm | 4 ++++ 2 files changed, 10 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index ad3827de9..ccf7dfba0 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -128,13 +128,19 @@ sub submit_creator_fixed : Private { my $questionnaire = $c->model( 'DB::Questionnaire' )->find_or_new( { problem_id => $c->stash->{problem}, + # 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; diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 1ea0e88b4..76bd89174 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -51,6 +51,9 @@ 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 - user'); @@ -75,6 +78,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'); } -- cgit v1.2.3 From 96da0c04218644450f141f20c1dee4247a0ed8fe Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 28 Jun 2011 14:51:17 +0100 Subject: correctly set mark_open/fixed in questionnaire generates updates --- perllib/FixMyStreet/App/Controller/Questionnaire.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index ccf7dfba0..a146b85ce 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -202,7 +202,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, -- cgit v1.2.3 From 50984fe0e0b75436ed2ce673631c018e83ed9945 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 19 Jul 2011 17:11:45 +0100 Subject: Couple of typos in bits of code. --- perllib/FixMyStreet/App/Controller/Questionnaire.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index 90674b294..8de935dd7 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -168,7 +168,7 @@ 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' && - FixMyStreet::DB::Result::Problem->open_states($old_state) ) { + FixMyStreet::DB::Result::Problem->open_states->{$old_state} ) { $problem->lastupdate( \'ms_current_timestamp()' ); } -- cgit v1.2.3 From e1801441beb37f37857c925a3c8c889653da4fe9 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 27 Jul 2011 13:54:46 +0100 Subject: allow council user to update state on problem sent to multiple councils --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 03130f60b..add9d1371 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -180,8 +180,7 @@ sub process_update : Private { if ( $params{state} ) { $params{state} = 'fixed - council' - if $params{state} eq 'fixed' && $c->user && $c->user->from_council - && $c->user->from_council == $update->problem->council; + if $params{state} eq 'fixed' && $c->user && $c->user->belongs_to_council( $update->problem->council ); $update->problem_state( $params{state} ); } @@ -205,7 +204,7 @@ sub check_for_errors : Private { # 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->from_council && $c->user->from_council == $c->stash->{update}->problem->council; + $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' ) ); -- cgit v1.2.3 From 01750786cc7f8d13f939eb75284f1d805673effe Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 18 Aug 2011 13:57:16 +0100 Subject: remove hard coded references to fixed --- perllib/FixMyStreet/App/Controller/My.pm | 4 ++-- perllib/FixMyStreet/App/Controller/Questionnaire.pm | 2 +- perllib/FixMyStreet/App/Controller/Reports.pm | 2 +- perllib/FixMyStreet/App/Controller/Tokens.pm | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm index 1021f7056..677f23ceb 100644 --- a/perllib/FixMyStreet/App/Controller/My.pm +++ b/perllib/FixMyStreet/App/Controller/My.pm @@ -31,7 +31,7 @@ sub my : Path : Args(0) { my $pins = []; my $problems = {}; my $rs = $c->user->problems->search( { - state => [ 'confirmed', 'fixed' ], + state => [ FixMyStreet::DB::Result::Problem->visible_states() ], }, { order_by => { -desc => 'confirmed' }, rows => 50 @@ -41,7 +41,7 @@ sub my : Path : Args(0) { push @$pins, { latitude => $problem->latitude, longitude => $problem->longitude, - colour => $problem->state eq 'fixed' ? 'green' : 'red', + colour => $problem->is_fixed ? 'green' : 'red', id => $problem->id, title => $problem->title, }; diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index a8bdca7a4..7a089eb76 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -297,7 +297,7 @@ sub display : Private { pins => [ { latitude => $problem->latitude, longitude => $problem->longitude, - colour => $problem->state eq 'fixed' ? 'green' : 'red', + colour => $problem->is_fixed() ? 'green' : 'red', } ], ); } diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index bf270a3b2..f7fb5dec5 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -420,7 +420,7 @@ sub add_row { push @$pins, { latitude => $problem->{latitude}, longitude => $problem->{longitude}, - colour => $problem->{state} eq 'fixed' ? 'green' : 'red', + colour => FixMyStreet::DB::Result::Problem->fixed_states()->{$problem->{state}} ? 'green' : 'red', id => $problem->{id}, title => $problem->{title}, }; diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm index 26a1a1459..1ebf35652 100644 --- a/perllib/FixMyStreet/App/Controller/Tokens.pm +++ b/perllib/FixMyStreet/App/Controller/Tokens.pm @@ -75,7 +75,7 @@ sub confirm_problem : Path('/P') { $c->authenticate( { email => $problem->user->email }, 'no_password' ); $c->set_session_cookie_expire(0); - if ( $old_state eq 'confirmed' || $old_state eq 'fixed' ) { + if ( FixMyStreet::DB::Result::Problem->visible_states()->{$old_state} == 1 ) { my $report_uri = $c->uri_for( '/report', $problem->id ); $c->res->redirect($report_uri); } -- cgit v1.2.3 From 120f353b1793d5033a5f7c1a922f7da255307805 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 18 Aug 2011 15:27:43 +0100 Subject: remove hard coded state strings --- perllib/FixMyStreet/App/Controller/Open311.pm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm index 459ce12c9..46d7801f6 100644 --- a/perllib/FixMyStreet/App/Controller/Open311.pm +++ b/perllib/FixMyStreet/App/Controller/Open311.pm @@ -216,8 +216,11 @@ sub output_requests : Private { # Look up categories for this council or councils my $problems = $c->cobrand->problems->search( $criteria, $attr ); - my %statusmap = ( 'fixed' => 'closed', - 'confirmed' => 'open'); + my %statusmap = ( + map( { $_ => 'open' } FixMyStreet::DB::Result::Problem->open_states() ), + map( { $_ => 'closed' } FixMyStreet::DB::Result::Problem->fixed_states() ), + 'closed' => 'closed' + ); my @problemlist; my @councils; @@ -309,13 +312,13 @@ sub get_requests : Private { # Only provide access to the published reports my $criteria = { - state => [ 'fixed', 'confirmed' ] + state => [ FixMyStreet::DB::Result::Problem->visible_states() ] }; my %rules = ( service_request_id => [ '=', 'id' ], service_code => [ '=', 'category' ], - status => [ '=', 'state' ], + status => [ 'IN', 'state' ], start_date => [ '>=', 'confirmed' ], end_date => [ '<', 'confirmed' ], agency_responsible => [ '~', 'council' ], @@ -329,8 +332,8 @@ sub get_requests : Private { my $key = $rules{$param}[1]; if ( 'status' eq $param ) { $value = { - 'open' => 'confirmed', - 'closed' => 'fixed' + 'open' => [ FixMyStreet::DB::Result::Problem->open_states() ], + 'closed' => [ FixMyStreet::DB::Result::Problem->fixed_states(), 'closed' ], }->{$value}; } elsif ( 'agency_responsible' eq $param ) { my @valuelist; @@ -403,7 +406,7 @@ sub get_request : Private { } my $criteria = { - state => [ 'fixed', 'confirmed' ], + state => [ FixMyStreet::DB::Result::Problem->visible_states() ], id => $id, }; $c->forward( 'output_requests', [ $criteria ] ); -- cgit v1.2.3 From 9d893420aa44d8b42eb59325cd3a328b16bf8250 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 18 Aug 2011 16:44:29 +0100 Subject: avoid warnings about uninitalized values --- perllib/FixMyStreet/App/Controller/Tokens.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm index 1ebf35652..10f994d9f 100644 --- a/perllib/FixMyStreet/App/Controller/Tokens.pm +++ b/perllib/FixMyStreet/App/Controller/Tokens.pm @@ -75,7 +75,7 @@ sub confirm_problem : Path('/P') { $c->authenticate( { email => $problem->user->email }, 'no_password' ); $c->set_session_cookie_expire(0); - if ( FixMyStreet::DB::Result::Problem->visible_states()->{$old_state} == 1 ) { + if ( FixMyStreet::DB::Result::Problem->visible_states()->{$old_state} ) { my $report_uri = $c->uri_for( '/report', $problem->id ); $c->res->redirect($report_uri); } -- cgit v1.2.3 From 8c1ffdca6e94c0affc67def47d10db339cf28e5c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 18 Aug 2011 18:14:06 +0100 Subject: do not use raw problem state to categorise problems --- perllib/FixMyStreet/App/Controller/My.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm index 677f23ceb..87b78eef4 100644 --- a/perllib/FixMyStreet/App/Controller/My.pm +++ b/perllib/FixMyStreet/App/Controller/My.pm @@ -45,7 +45,8 @@ sub my : Path : Args(0) { id => $problem->id, title => $problem->title, }; - push @{ $problems->{$problem->state} }, $problem; + my $state = $problem->is_fixed ? 'fixed' : 'confirmed'; + push @{ $problems->{$state} }, $problem; } $c->stash->{problems_pager} = $rs->pager; $c->stash->{problems} = $problems; -- cgit v1.2.3 From 66657b4d1a4aa002609c2435a9a7686cd3257cdc Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 18 Aug 2011 18:22:33 +0100 Subject: show closed problems on my page --- perllib/FixMyStreet/App/Controller/My.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm index 87b78eef4..60e9dd09f 100644 --- a/perllib/FixMyStreet/App/Controller/My.pm +++ b/perllib/FixMyStreet/App/Controller/My.pm @@ -45,7 +45,7 @@ sub my : Path : Args(0) { id => $problem->id, title => $problem->title, }; - my $state = $problem->is_fixed ? 'fixed' : 'confirmed'; + my $state = $problem->is_fixed ? 'fixed' : $problem->is_closed ? 'closed' : 'confirmed'; push @{ $problems->{$state} }, $problem; } $c->stash->{problems_pager} = $rs->pager; -- cgit v1.2.3 From 34ae11b13ec02a874badea13bbeb2ee8e7c384de Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 18 Aug 2011 23:50:43 +0100 Subject: few more static states --- perllib/FixMyStreet/App/Controller/Questionnaire.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller') diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index 7a089eb76..f0cb02115 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -245,7 +245,7 @@ sub process_questionnaire : Private { if ($c->stash->{been_fixed} eq 'No' || $c->stash->{been_fixed} eq 'Unknown') && !$c->stash->{another}; push @errors, _('Please provide some explanation as to why you\'re reopening this report') - if $c->stash->{been_fixed} eq 'No' && $c->stash->{problem}->state eq 'fixed' && !$c->stash->{update}; + if $c->stash->{been_fixed} eq 'No' && $c->stash->{problem}->is_fixed() && !$c->stash->{update}; $c->forward('/report/new/process_photo'); push @errors, $c->stash->{photo_error} -- cgit v1.2.3