aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
authorHakim Cassimally <hakim@mysociety.org>2015-03-17 17:58:44 +0000
committerDave Arter <davea@mysociety.org>2015-10-06 09:09:25 +0100
commit3ef919ee67fc34c8b06dd85b035ba9d0ef85804c (patch)
treea0e546df59d6519daaa37072de48140fe899cda1 /perllib
parentd46284114fcd1b2038bc6da5b6477d6a293b1699 (diff)
[Zurich] additional closure statuses work
Requirements: ============= 1: DM to be able to mark a problem as Wish, Extern, Not contactable, Hidden, Jurisdiction unknown 2: SDM to be able to mark a problem as Not contactable. 3: DM to be able to add information to such a problem, and trigger emails to external agencies, and to user, closing the problem at the same time. 4: Closed reports must be categorized as Wish/Extern/NC/Hidden/JU for statistical reporting 5: Non-closed reports must appear as open, to allow DM to see them in the list, similar to what is currently done for Ruckmeldung Ausstehend (Feedback outstanding). 5b: however "Hidden" problems must be immediately hidden from public view. Proposal: ========= a) Requirement 1 will be carried out in exactly the same way by DM. e.g. Category dropdown select b) Requirement 2 will be carried out in exactly the same way by SDM. e.g. "Not contactable" button c) BUT, for a), c), the category will be diverted to "Ruckmeldung Ausstehend" (Feedback outstanding), and metadata will be saved with the appropriate closure type. d) NOTE: this means the report will still be visible to public as "In bearbeitung" (Except for Hidden reports, as per 5b) e) The extra fields will be presented on the "Ruckmeldung Ausstehend" page, just as defined in the PDF, depending on the metadata. e.g. - Wish: Zustaendige Stelle + Message - Extern: External body + Message2 - Not contactable: (no extra info) - Hidden: (no extra info) - Jurisdiction unknown: (no extra info) f) When the DM publishes the answer (e.g. "Antwort Veroeffentlichen" button), the state will normally change to Fixed. BUT in the new cases, the metadata saved in step c) will be checked, and the report will change state to Wish/Extern/Not contactable/Hidden/Jurisdiction unknown, as appropriate. The report will now be visible/hidden as previously discussed depending on the new state. g) If the report is edited again (in /admin/report_edit) it will be in the relevant state, and any extra fields will be visible as per e). Those fields may be updated. Alternatively, the state may be changed, possibly triggering a) again, and clearing any metadata. - Fix javascript interactions 690 - show new statuses in summary - fix photos on SDM page - fix Planned => Planned+metadata transition - stop "assignation .select" js affecting templates - fix redirection for Extern and generally See mysociety/FixMyStreet-Commercial#672, mysociety/FixMyStreet-Commercial#690
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm3
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm207
2 files changed, 156 insertions, 54 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 3aaa3e201..d7cae05d4 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -112,7 +112,8 @@ sub load_problem_or_display_error : Private {
$c->detach( '/page_error_404_not_found', [ _('Unknown problem ID') ] )
unless $c->cobrand->show_unconfirmed_reports ;
}
- elsif ( $problem->hidden_states->{ $problem->state } ) {
+ elsif ( $problem->hidden_states->{ $problem->state } or
+ (($problem->get_extra_metadata('closure_status')||'') eq 'hidden')) {
$c->detach(
'/page_error_410_gone',
[ _('That report has been removed from FixMyStreet.') ] #
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index 3f57ecf5a..1a9963a60 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -108,8 +108,11 @@ sub prettify_dt {
sub zurich_closed_states {
my $states = {
'fixed - council' => 1,
- 'closed' => 1,
+ 'closed' => 1, # extern
'hidden' => 1,
+ 'investigating' => 1, # wish
+ 'unable to fix' => 1, # jurisdiction unknown
+ 'partial' => 1, # not contactable
};
return wantarray ? keys %{ $states } : $states;
@@ -525,6 +528,7 @@ sub admin_report_edit {
}
}
+
# Problem updates upon submission
if ( ($type eq 'super' || $type eq 'dm') && $c->get_param('submit') ) {
$problem->set_extra_metadata('publish_photo' => $c->get_param('publish_photo') || 0 );
@@ -564,6 +568,17 @@ sub admin_report_edit {
my $redirect = 0;
my $new_cat = $c->get_param('category') || '';
my $state = $c->get_param('state') || '';
+ my $oldstate = $problem->state;
+
+ my %closure_states = (
+ 'closed' => 1,
+ 'investigating' => 1,
+ 'hidden' => 1,
+ 'partial' => 1,
+ 'unable to fix' => 1,
+ );
+
+ my $old_closure_state = $problem->get_extra_metadata('closure_status');
if (
($state eq 'confirmed')
@@ -580,6 +595,23 @@ sub admin_report_edit {
$internal_note_text = "Weitergeleitet von $old_cat an $new_cat";
$self->update_admin_log($c, $problem, "Changed category from $old_cat to $new_cat");
$redirect = 1 if $cat->body_id ne $body->id;
+ } elsif ( $closure_states{$state} and
+ ( $oldstate ne 'planned' )
+ || (($old_closure_state ||'') ne $state))
+ {
+ # for these states
+ # - closed (Extern)
+ # - investigating (Wish)
+ # - hidden
+ # - partial (Not contactable)
+ # - unable to fix (Jurisdiction unknown)
+ # we divert to planned (Rueckmeldung ausstehend) and set closure_status to the requested state
+ # From here, the DM can reply to the user, triggering the setting of problem to correct state
+ $problem->set_extra_metadata( closure_status => $state );
+ $self->set_problem_state($c, $problem, 'planned');
+ $state = 'planned';
+ $redirect = 1;
+
} elsif ( my $subdiv = $c->get_param('body_subdivision') ) {
$problem->set_extra_metadata_if_undefined( moderated_overdue => $self->overdue( $problem ) );
$self->set_problem_state($c, $problem, 'in progress');
@@ -587,55 +619,75 @@ sub admin_report_edit {
$problem->bodies_str( $subdiv );
$problem->whensent( undef );
$redirect = 1;
- } elsif ( my $external = $c->get_param('body_external') and $state =~/^(closed|investigating)$/) {
- # Extern | Wish
- my $external_body = $c->model('DB::Body')->find($external)
- or die "Body $external not found";
- $problem->set_extra_metadata_if_undefined( moderated_overdue => $self->overdue( $problem ) );
- $problem->set_extra_metadata_if_undefined( closed_overdue => $self->overdue( $problem ) );
- $problem->external_body( $external );
- $problem->whensent( undef );
- $self->set_problem_state($c, $problem, $state);
- if ( my $external_message = $c->req->params->{external_message} ) {
- $problem->add_to_comments( {
- text => (
- sprintf '(%s %s) %s',
- $state eq 'closed' ?
- _('Forwarded to external body') :
- _('Forwarded wish to external body'),
- $external_body->name,
- $external_message,
- ),
- user => $c->user->obj,
- state => 'hidden', # seems best fit, should not be shown publicly
- mark_fixed => 0,
- anonymous => 1,
- extra => { is_internal_note => 1, is_external_message => 1 },
- } );
- # set the external_message in extra, so that it will be picked up
- # later by send-reports
- $problem->set_extra_metadata( external_message => $external_message );
- }
- my $template = ($state eq 'investigating') ? 'problem-wish.txt' : 'problem-external.txt';
- _admin_send_email( $c, $template, $problem );
- $redirect = 1;
} else {
if ($state) {
- if ($problem->state eq 'unconfirmed' and $state ne 'unconfirmed') {
+ if ($oldstate eq 'unconfirmed' and $state ne 'unconfirmed') {
# only set this for the first state change
$problem->set_extra_metadata_if_undefined( moderated_overdue => $self->overdue( $problem ) );
}
- $self->set_problem_state($c, $problem, $state);
+ $self->set_problem_state($c, $problem, $state)
+ unless $closure_states{$state}; # in closure-states case, we'll defer to clause below
if ($self->problem_is_closed($problem)) {
$problem->set_extra_metadata_if_undefined( closed_overdue => $self->overdue( $problem ) );
+ $c->stash->{problem_is_closed} = 1;
}
- if ( $state eq 'hidden' && $c->get_param('send_rejected_email') ) {
- _admin_send_email( $c, 'problem-rejected.txt', $problem );
+ }
+ }
+
+ if ($problem->state eq 'planned') {
+ # Rueckmeldung ausstehend
+ # override $state from the metadata set above
+ $state = $problem->get_extra_metadata('closure_status') || '';
+ my $closed = 0;
+
+ if ($state eq 'hidden' && $c->req->params->{publish_response} ) {
+ _admin_send_email( $c, 'problem-rejected.txt', $problem );
+ $problem->set_extra_metadata_if_undefined( moderated_overdue => $self->overdue( $problem ) );
+ $self->set_problem_state($c, $problem, $state);
+ $closed++;
+ }
+ elsif ($state =~/^(closed|investigating)$/) { # Extern | Wish
+ # Nested if instead of `and` because in these cases, we *don't*
+ # want to close unless we have body_external (so we don't want
+ # the final elsif clause below to kick in on publish_response)
+ if (my $external = $c->req->params->{body_external}) {
+ my $external_body = $c->model('DB::Body')->find($external)
+ or die "Body $external not found";
+ $problem->external_body( $external );
+ }
+ if ($problem->external_body && $c->req->params->{publish_response}) {
+ $problem->set_extra_metadata_if_undefined( moderated_overdue => $self->overdue( $problem ) );
+ $problem->whensent( undef );
+ $self->set_problem_state($c, $problem, $state);
+ my $template = ($state eq 'investigating') ? 'problem-wish.txt' : 'problem-external.txt';
+ _admin_send_email( $c, $template, $problem );
+ $redirect = 1;
+ $closed++;
}
+ # else should really return a message here
+ }
+ elsif ($c->req->params->{publish_response}) {
+ # otherwise we only set the state if publish_response is set
+
+ # if $state wasn't set, then we are simply closing the message as fixed
+ $state ||= 'fixed - council';
+ _admin_send_email( $c, 'problem-closed.txt', $problem );
+ $redirect = 1;
+ $closed++;
}
+
+ if ($closed) {
+ # set to either the closure_status from metadata or 'fixed - council' as above
+ $self->set_problem_state($c, $problem, $state);
+ $problem->set_extra_metadata_if_undefined( closed_overdue => $self->overdue( $problem ) );
+ $problem->unset_extra_metadata('closure_status');
+ }
+ }
+ else {
+ $problem->unset_extra_metadata('closure_status');
}
$problem->title( $c->get_param('title') ) if $c->get_param('title');
@@ -643,16 +695,40 @@ sub admin_report_edit {
$problem->latitude( $c->get_param('latitude') );
$problem->longitude( $c->get_param('longitude') );
- # Final, public, Update from DM
- if (my $update = $c->get_param('status_update')) {
+ # update the public update from DM
+ if (my $update = $c->req->param('status_update')) {
$problem->set_extra_metadata(public_response => $update);
- if ($c->get_param('publish_response')) {
- $self->set_problem_state($c, $problem, 'fixed - council');
- $problem->set_extra_metadata( closed_overdue => $self->overdue( $problem ) );
- _admin_send_email( $c, 'problem-closed.txt', $problem );
- }
}
- $c->stash->{default_public_response} = "\nFreundliche Grüsse\n\nIhre Stadt Zürich\n";
+
+ # send external_message if provided and state is *now* Wish|Extern
+ # e.g. was already, or was set in the Rueckmeldung ausstehend clause above.
+ if ( my $external_message = $c->req->params->{external_message}
+ and $problem->state =~ /^(closed|investigating)$/)
+ {
+ my $external = $problem->external_body;
+ my $external_body = $c->model('DB::Body')->find($external)
+ or die "Body $external not found";
+
+ $problem->set_extra_metadata_if_undefined( moderated_overdue => $self->overdue( $problem ) );
+ $problem->add_to_comments( {
+ text => (
+ sprintf '(%s %s) %s',
+ $state eq 'closed' ?
+ _('Forwarded to external body') :
+ _('Forwarded wish to external body'),
+ $external_body->name,
+ $external_message,
+ ),
+ user => $c->user->obj,
+ state => 'hidden', # seems best fit, should not be shown publicly
+ mark_fixed => 0,
+ anonymous => 1,
+ extra => { is_internal_note => 1, is_external_message => 1 },
+ } );
+ # set the external_message in extra, so that it will be picked up
+ # later by send-reports
+ $problem->set_extra_metadata( external_message => $external_message );
+ }
$problem->lastupdate( \'current_timestamp' );
$problem->update;
@@ -682,7 +758,7 @@ sub admin_report_edit {
$self->update_admin_log($c, $problem);
if ( $redirect ) {
- $c->detach('index');
+ $c->go('index');
}
$c->stash->{updates} = [ $c->model('DB::Comment')
@@ -708,8 +784,14 @@ sub admin_report_edit {
my $not_contactable = $c->req->param('not_contactable');
$problem->bodies_str( $body->parent->id );
- my $new_state = $not_contactable ? 'partial' : 'confirmed';
- $self->set_problem_state($c, $problem, $new_state);
+ if ($not_contactable) {
+ # we can't directly set state, but mark the closure_status for DM to confirm.
+ $self->set_problem_state($c, $problem, 'planned');
+ $problem->set_extra_metadata( closure_status => 'partial');
+ }
+ else {
+ $self->set_problem_state($c, $problem, 'confirmed');
+ }
$problem->update;
$c->forward( 'log_edit', [ $problem->id, 'problem',
$not_contactable ?
@@ -792,11 +874,6 @@ sub stash_states {
unconfirmed => 1,
},
{
- # Rueckmeldung ausstehend
- state => 'planned',
- trans => _('Planned'),
- },
- {
# Unsichtbar (hidden)
state => 'hidden',
trans => _('Hidden'),
@@ -824,7 +901,26 @@ sub stash_states {
trans => _('Not contactable'),
},
);
+ my %state_trans = map { $_->{state} => $_->{trans} } @states;
+
my $state = $problem->state;
+
+ # Rueckmeldung ausstehend may also indicate the status it's working towards.
+ push @states, do {
+ if ($state eq 'planned' and my $closure_status = $problem->get_extra_metadata('closure_status')) {
+ {
+ state => $closure_status,
+ trans => sprintf '%s (%s)', _('Planned'), $state_trans{$closure_status},
+ };
+ }
+ else {
+ {
+ state => 'planned',
+ trans => _('Planned'),
+ };
+ }
+ };
+
if ($state eq 'in progress') {
push @states, {
state => 'in progress',
@@ -841,6 +937,11 @@ sub stash_states {
@states = grep { $_->{$state} } @states;
}
$c->stash->{states} = \@states;
+
+ # stash details about the public response
+ $c->stash->{default_public_response} = "\nFreundliche Grüsse\n\nIhre Stadt Zürich\n";
+ $c->stash->{show_publish_response} =
+ ($problem->state eq 'planned');
}
=head2 _admin_send_email