diff options
author | Struan Donald <struan@exo.org.uk> | 2013-01-16 11:47:20 +0000 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2013-01-16 11:47:20 +0000 |
commit | 682db36dca4db6c0682deeb4fb704e8cf222e38c (patch) | |
tree | 5811b7e2288f48b0bc814f7f505e19cb705294d9 /perllib | |
parent | 257b658e49da3665a426f1c98d9760b0d53b8d3d (diff) | |
parent | 3c4c0ec2f55d82502169d2313745920850efdc99 (diff) |
Merge branch 'bromley-new-statuses'
Conflicts:
bin/send-comments
conf/crontab.ugly
db/schema.sql
perllib/FixMyStreet/App/Controller/Admin.pm
perllib/FixMyStreet/DB/Result/Open311conf.pm
perllib/FixMyStreet/DB/ResultSet/Problem.pm
perllib/Open311.pm
t/app/controller/report_updates.t
t/open311.t
templates/web/default/report/display.html
templates/web/default/report/updates.html
templates/web/fixmystreet/report/display.html
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Open311conf.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 96 | ||||
-rw-r--r-- | perllib/Open311.pm | 30 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequestUpdates.pm | 32 |
8 files changed, 176 insertions, 30 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 7a2790b31..e14c7dc66 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -65,11 +65,9 @@ sub index : Path : Args(0) { %prob_counts = map { $_ => $prob_counts{$_} || 0 } - ('confirmed', 'investigating', 'in progress', 'closed', 'fixed - council', - 'fixed - user', 'fixed', 'unconfirmed', 'hidden', - 'partial', 'planned'); + ( FixMyStreet::DB::Result::Problem->all_states() ); $c->stash->{problems} = \%prob_counts; - $c->stash->{total_problems_live} += $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; @@ -351,7 +349,7 @@ sub update_contacts : Private { } elsif ( $posted eq 'open311' ) { $c->forward('check_token'); - my %params = map { $_ => $c->req->param($_) || '' } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments suppress_alerts comment_user_id devolved/; + my %params = map { $_ => $c->req->param($_) || '' } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments suppress_alerts extended_statuses comment_user_id devolved/; if ( $params{open311_id} ) { my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } ); @@ -364,6 +362,7 @@ sub update_contacts : Private { $conf->suppress_alerts( $params{suppress_alerts} || 0); $conf->comment_user_id( $params{comment_user_id} || undef ); $conf->can_be_devolved( $params{devolved} || 0 ); + $conf->send_extended_statuses( $params{extended_statuses} || 0 ); $conf->update(); @@ -379,6 +378,7 @@ sub update_contacts : Private { $conf->suppress_alerts( $params{suppress_alerts} || 0); $conf->comment_user_id( $params{comment_user_id} || undef ); $conf->can_be_devolved( $params{devolved} || 0 ); + $conf->send_extended_statuses( $params{extended_statuses} || 0 ); $conf->insert(); diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index a5ba8ff07..17fd8b867 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -138,6 +138,8 @@ sub index : Path : Args(0) { $prob_where->{state} = [ FixMyStreet::DB::Result::Problem->fixed_states() ]; } elsif ( $c->stash->{q_state} ) { $prob_where->{state} = $c->stash->{q_state}; + $prob_where->{state} = { IN => [ 'planned', 'action scheduled' ] } + if $prob_where->{state} eq 'action scheduled'; } my $params = { %$prob_where, @@ -181,11 +183,13 @@ sub updates_search : Private { map { $_ => $counts{$_} || 0 } ('confirmed', 'investigating', 'in progress', 'closed', 'fixed - council', 'fixed - user', 'fixed', 'unconfirmed', 'hidden', - 'partial', 'planned'); + 'partial', 'action scheduled', 'planned'); + + $counts{'action scheduled'} += $counts{planned} || 0; for my $vars ( [ 'time_to_fix', 'fixed - council' ], - [ 'time_to_mark', 'in progress', 'planned', 'investigating', 'closed' ], + [ 'time_to_mark', 'in progress', 'action scheduled', 'investigating', 'closed' ], ) { my $col = shift @$vars; my $substmt = "select min(id) from comment where me.problem_id=comment.problem_id and problem_state in ('" diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index da4cc33ca..5e0d9f388 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -203,8 +203,23 @@ sub process_update : Private { $params{state} = 'fixed - council' if $params{state} eq 'fixed' && $c->user && $c->user->belongs_to_council( $update->problem->council ); $update->problem_state( $params{state} ); + } else { + # we do this so we have a record of the state of the problem at this point + # for use when sending updates to external parties + if ( $update->mark_fixed ) { + $update->problem_state( 'fixed - user' ); + } elsif ( $update->mark_open ) { + $update->problem_state( 'confirmed' ); + # if there is not state param and neither of the above conditions apply + # then we are not changing the state of the problem so can use the current + # problem state + } else { + my $problem = $c->stash->{problem} || $update->problem; + $update->problem_state( $problem->state ); + } } + my @extra; # Next function fills this, but we don't need it here. # This is just so that the error checkign for these extra fields runs. # TODO Use extra here as it is used on reports. @@ -249,7 +264,8 @@ sub check_for_errors : Private { $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' ) ); + $state = 'fixed - council' if $state eq 'fixed'; + $error = 1 unless ( grep { $state eq $_ } ( FixMyStreet::DB::Result::Problem->council_states() ) ); if ( $error ) { $c->stash->{errors} ||= []; diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 8c9fea282..b551be9ef 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -146,6 +146,11 @@ sub check_for_errors { $errors{update} = _('Please enter a message') unless $self->text =~ m/\S/; + if ( $self->text && $self->problem && $self->problem->council + && $self->problem->council eq '2482' && length($self->text) > 2000 ) { + $errors{update} = _('Updates are limited to 2000 characters in length. Please shorten your update'); + } + return \%errors; } @@ -186,6 +191,10 @@ sub meta_problem_state { my $state = $self->problem_state; $state =~ s/ -.*$//; + $state = _("not the council's responsibility") + if $state eq 'not responsible'; + $state = _('duplicate report') if $state eq 'duplicate'; + return $state; } diff --git a/perllib/FixMyStreet/DB/Result/Open311conf.pm b/perllib/FixMyStreet/DB/Result/Open311conf.pm index 8051e27de..f01a20dec 100644 --- a/perllib/FixMyStreet/DB/Result/Open311conf.pm +++ b/perllib/FixMyStreet/DB/Result/Open311conf.pm @@ -36,6 +36,8 @@ __PACKAGE__->add_columns( { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "can_be_devolved", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "send_extended_statuses", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("open311conf_area_id_key", ["area_id"]); @@ -55,6 +57,5 @@ __PACKAGE__->belongs_to( # Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-29 14:04:20 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Yoult8K/ldH6DMAKURtr3Q - # You can replace this text with custom code or comments, and it will be preserved on regeneration 1; diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index dd09ad3c2..b1f59e78a 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -196,10 +196,11 @@ HASHREF. sub open_states { my $states = { - 'confirmed' => 1, - 'investigating' => 1, - 'planned' => 1, - 'in progress' => 1, + 'confirmed' => 1, + 'investigating' => 1, + 'in progress' => 1, + 'planned' => 1, + 'action scheduled' => 1, }; return wantarray ? keys %{$states} : $states; @@ -237,7 +238,10 @@ HASHREF. sub closed_states { my $states = { - 'closed' => 1, + 'closed' => 1, + 'unable to fix' => 1, + 'not responsible' => 1, + 'duplicate' => 1, }; return wantarray ? keys %{$states} : $states; @@ -248,7 +252,7 @@ sub closed_states { @states = FixMyStreet::DB::Problem::visible_states(); -Get a list or states that should be visible on the site. If called in +Get a list of states that should be visible on the site. If called in array context then returns an array of names, otherwise returns a HASHREF. @@ -256,14 +260,73 @@ HASHREF. sub visible_states { my $states = { - 'confirmed' => 1, - 'planned' => 1, - 'investigating' => 1, - 'in progress' => 1, - 'fixed' => 1, - 'fixed - council' => 1, - 'fixed - user' => 1, - 'closed' => 1, + 'confirmed' => 1, + 'investigating' => 1, + 'in progress' => 1, + 'planned' => 1, + 'action scheduled' => 1, + 'fixed' => 1, + 'fixed - council' => 1, + 'fixed - user' => 1, + 'unable to fix' => 1, + 'not responsible' => 1, + 'duplicate' => 1, + 'closed' => 1, + }; + + return wantarray ? keys %{$states} : $states; +} + +=head2 + + @states = FixMyStreet::DB::Problem::all_states(); + +Get a list of all states that a problem can have. If called in +array context then returns an array of names, otherwise returns a +HASHREF. + +=cut + +sub all_states { + my $states = { + 'hidden' => 1, + 'partial' => 1, + 'unconfirmed' => 1, + 'confirmed' => 1, + 'investigating' => 1, + 'in progress' => 1, + 'action scheduled' => 1, + 'fixed' => 1, + 'fixed - council' => 1, + 'fixed - user' => 1, + 'unable to fix' => 1, + 'not responsible' => 1, + 'duplicate' => 1, + 'closed' => 1, + }; + + return wantarray ? keys %{$states} : $states; +} + +=head2 + + @states = FixMyStreet::DB::Problem::council_states(); + +Get a list of states that are availble to council users. If called in +array context then returns an array of names, otherwise returns a +HASHREF. + +=cut +sub council_states { + my $states = { + 'confirmed' => 1, + 'investigating' => 1, + 'action scheduled' => 1, + 'in progress' => 1, + 'fixed - council' => 1, + 'unable to fix' => 1, + 'not responsible' => 1, + 'duplicate' => 1, }; return wantarray ? keys %{$states} : $states; @@ -364,6 +427,11 @@ sub check_for_errors { $self->category(undef); } + if ( $self->council && $self->detail && + $self->council eq '2482' && length($self->detail) > 2000 ) { + $errors{detail} = _('Reports are limited to 2000 characters in length. Please shorten your report'); + } + return \%errors; } diff --git a/perllib/Open311.pm b/perllib/Open311.pm index 7a5493704..dee985fca 100644 --- a/perllib/Open311.pm +++ b/perllib/Open311.pm @@ -25,6 +25,7 @@ has send_notpinpointed => ( is => 'ro', isa => 'Bool', default => 0 ); has extended_description => ( is => 'ro', isa => 'Str', default => 1 ); has use_service_as_deviceid => ( is => 'ro', isa => 'Bool', default => 0 ); has use_extended_updates => ( is => 'ro', isa => 'Bool', default => 0 ); +has extended_statuses => ( is => 'ro', isa => 'Bool', default => 0 ); before [ qw/get_service_list get_service_meta_info get_service_requests get_service_request_updates @@ -287,10 +288,37 @@ sub _populate_service_request_update_params { my $name = $comment->name || $comment->user->name; my ( $firstname, $lastname ) = ( $name =~ /(\w+)\.?\s+(.+)/ ); + # fall back to problem state as it's probably correct + my $state = $comment->problem_state || $comment->problem->state; + + my $status = 'OPEN'; + if ( $self->extended_statuses ) { + if ( FixMyStreet::DB::Result::Problem->fixed_states()->{$state} ) { + $status = 'FIXED'; + } elsif ( $state eq 'in progress' ) { + $status = 'IN_PROGRESS'; + } elsif ($state eq 'action scheduled' + || $state eq 'planned' ) { + $status = 'ACTION_SCHEDULED'; + } elsif ( $state eq 'investigating' ) { + $status = 'INVESTIGATING'; + } elsif ( $state eq 'duplicate' ) { + $status = 'DUPLICATE'; + } elsif ( $state eq 'not responsible' ) { + $status = 'NOT_COUNCILS_RESPONSIBILITY'; + } elsif ( $state eq 'unable to fix' ) { + $status = 'NO_FURTHER_ACTION'; + } + } else { + if ( !FixMyStreet::DB::Result::Problem->open_states()->{$state} ) { + $status = 'CLOSED'; + } + } + my $params = { updated_datetime => DateTime::Format::W3CDTF->format_datetime($comment->confirmed_local->set_nanosecond(0)), service_request_id => $comment->problem->external_id, - status => $comment->problem->is_open ? 'OPEN' : 'CLOSED', + status => $status, email => $comment->user->email, description => $comment->text, last_name => $lastname, diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm index 0b4e037fd..e337c0f57 100644 --- a/perllib/Open311/GetServiceRequestUpdates.pm +++ b/perllib/Open311/GetServiceRequestUpdates.pm @@ -113,12 +113,14 @@ sub update_comments { # do not change the status of the problem as it's # tricky to determine the right thing to do. if ( $comment->created_local > $p->lastupdate_local ) { - if ( $p->is_open and lc($request->{status}) eq 'closed' ) { - $p->state( 'fixed - council' ); - $comment->problem_state( 'fixed - council' ); - } elsif ( ( $p->is_closed || $p->is_fixed ) and lc($request->{status}) eq 'open' ) { - $p->state( 'confirmed' ); - $comment->problem_state( 'confirmed' ); + my $state = $self->map_state( $request->{status} ); + + # don't update state unless it's an allowed state and it's + # actually changing the state of the problem + if ( FixMyStreet::DB::Result::Problem->council_states()->{$state} && $p->state ne $state && + !( $p->is_fixed && FixMyStreet::DB::Result::Problem->fixed_states()->{$state} ) ) { + $p->state($state); + $comment->problem_state($state); } } @@ -146,4 +148,22 @@ sub update_comments { return 1; } +sub map_state { + my $self = shift; + my $incoming_state = shift; + + $incoming_state = lc($incoming_state); + $incoming_state =~ s/_/ /g; + + my %state_map = ( + fixed => 'fixed - council', + 'not councils responsibility' => 'not responsible', + 'no further action' => 'unable to fix', + open => 'confirmed', + closed => 'fixed - council' + ); + + return $state_map{$incoming_state} || $incoming_state; +} + 1; |