aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Cobrand
diff options
context:
space:
mode:
authorHakim Cassimally <hakim@mysociety.org>2015-02-27 15:34:24 +0000
committerDave Arter <davea@mysociety.org>2015-10-06 09:09:24 +0100
commite7c35a0de101331436b1d5d6f2346a8c85233737 (patch)
tree895462731355a23da52c5d504c59871c9342a426 /perllib/FixMyStreet/Cobrand
parent34f3f5a36b6773ad51060256d4e95efd7c45b3c8 (diff)
[Zurich] admin workflow changes available states
See mysociety/FixMyStreet-Commercial#690 - external_message for Extern/Wunsch states - as per PDF mockups, the "public response" field is now editable from more states, namely: - Ruckmeldung ausstehend - Extern - Zustandigkeit unbekannt - Wunsch - Nicht kontaktierbar - Unsichtbar - test fixes NB: slight hack to reorder Zurich report_display tests As these remove 'investigating' from hidden_states, these break tests for default cobrand (the FMS::App code expects to be called once on request start, not multiple times within one test) - Not contactable button and tests for this and the similar `send_back` functionality (previously untested). NB: Unsure why we need to specify form_number=2 just for these submits, but test won't find the buttons otherwise. - Make sure SDMs' "time_spent" figure is recorded. (See mysociety/FixMyStreet-Commercial#718)
Diffstat (limited to 'perllib/FixMyStreet/Cobrand')
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm153
1 files changed, 142 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index c08d48161..908550adb 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -545,10 +545,23 @@ sub admin_report_edit {
my $internal_note_text = "";
# Workflow things
+ #
+ # Note that 2 types of email may be sent
+ # 1) _admin_send_email() sends an email to the *user*, if their email is confirmed
+ # 2) setting $problem->whensent(undef) may make it eligible for generating an email
+ # to the body (internal or external). See DBRS::Problem->send_reports for Zurich-
+ # specific categories which are eligible for this.
+
my $redirect = 0;
- my $new_cat = $c->get_param('category');
- if ( $new_cat && $new_cat ne $problem->category ) {
- my $cat = $c->model('DB::Contact')->search( { category => $c->get_param('category') } )->first;
+ my $new_cat = $c->get_param('category') || '';
+ my $state = $c->get_param('state') || '';
+
+ if (
+ ($state eq 'confirmed')
+ && $new_cat
+ && $new_cat ne $problem->category
+ ) {
+ my $cat = $c->model('DB::Contact')->search({ category => $c->get_param('category') } )->first;
my $old_cat = $problem->category;
$problem->category( $new_cat );
$problem->external_body( undef );
@@ -565,16 +578,40 @@ sub admin_report_edit {
$problem->bodies_str( $subdiv );
$problem->whensent( undef );
$redirect = 1;
- } elsif ( my $external = $c->get_param('body_external') ) {
+ } 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 ) );
- $self->set_problem_state($c, $problem, 'closed');
$problem->set_extra_metadata_if_undefined( closed_overdue => $self->overdue( $problem ) );
$problem->external_body( $external );
$problem->whensent( undef );
- _admin_send_email( $c, 'problem-external.txt', $problem );
+ $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 (my $state = $c->get_param('state')) {
+ if ($state) {
if ($problem->state eq 'unconfirmed' and $state ne 'unconfirmed') {
# only set this for the first state change
@@ -606,6 +643,7 @@ sub admin_report_edit {
_admin_send_email( $c, 'problem-closed.txt', $problem );
}
}
+ $c->stash->{default_public_response} = "\nFreundliche Grüsse\n\nIhre Stadt Zürich\n";
$problem->lastupdate( \'current_timestamp' );
$problem->update;
@@ -642,6 +680,7 @@ sub admin_report_edit {
->search( { problem_id => $problem->id }, { order_by => 'created' } )
->all ];
+ $self->stash_states($problem);
return 1;
}
@@ -650,15 +689,26 @@ sub admin_report_edit {
# Has cut-down edit template for adding update and sending back up only
$c->stash->{template} = 'admin/report_edit-sdm.html';
- if ($c->get_param('send_back')) {
+ if ($c->get_param('send_back') or $c->get_param('not_contactable')) {
+ # SDM can send back a report either to be assigned to a different
+ # subdivision, or because the customer was not contactable.
+ # We handle these in the same way but with different statuses.
+
$c->forward('check_token');
+ my $not_contactable = $c->req->param('not_contactable');
+
$problem->bodies_str( $body->parent->id );
- $self->set_problem_state($c, $problem, 'confirmed');
+ my $new_state = $not_contactable ? 'partial' : 'confirmed';
+ $self->set_problem_state($c, $problem, $new_state);
$problem->update;
- # log here
+ $c->forward( 'log_edit', [ $problem->id, 'problem',
+ $not_contactable ?
+ _('Customer not contactable')
+ : _('Sent report back') ] );
+ # Make sure the problem's time_spent is updated
+ $self->update_admin_log($c, $problem);
$c->res->redirect( '/admin/summary' );
-
} elsif ($c->get_param('submit')) {
$c->forward('check_token');
@@ -683,6 +733,8 @@ sub admin_report_edit {
anonymous => 1,
} );
}
+ # Make sure the problem's time_spent is updated
+ $self->update_admin_log($c, $problem);
$c->stash->{status_message} = '<p><em>' . _('Updated!') . '</em></p>';
@@ -701,14 +753,93 @@ sub admin_report_edit {
->search( { problem_id => $problem->id }, { order_by => 'created' } )
->all ];
+ $self->stash_states($problem);
return 1;
}
+ $self->stash_states($problem);
return 0;
}
+sub stash_states {
+ my ($self, $problem) = @_;
+ my $c = $self->{c};
+
+ # current problem state affects which states are visible in dropdowns
+ my @states = (
+ {
+ # Erfasst
+ state => 'unconfirmed',
+ trans => _('Submitted'),
+ unconfirmed => 1,
+ hidden => 1,
+ },
+ {
+ # Aufgenommen
+ state => 'confirmed',
+ trans => _('Open'),
+ unconfirmed => 1,
+ },
+ {
+ # Rueckmeldung ausstehend
+ state => 'planned',
+ trans => _('Planned'),
+ },
+ {
+ # Unsichtbar (hidden)
+ state => 'hidden',
+ trans => _('Hidden'),
+ unconfirmed => 1,
+ hidden => 1,
+ },
+ {
+ # Extern
+ state => 'closed',
+ trans => _('Extern'),
+ },
+ {
+ # Zustaendigkeit unbekannt
+ state => 'unable to fix',
+ trans => _('Jurisdiction unknown'),
+ },
+ {
+ # Wunsch (hidden)
+ state => 'investigating',
+ trans => _('Wish'),
+ },
+ {
+ # Nicht kontaktierbar (hidden)
+ state => 'partial',
+ trans => _('Not contactable'),
+ },
+ );
+ my $state = $problem->state;
+ if ($state eq 'in progress') {
+ push @states, {
+ state => 'in progress',
+ trans => _('In progress'),
+ };
+ }
+ elsif ($state eq 'fixed - council') {
+ push @states, {
+ state => 'fixed - council',
+ trans => _('Closed'),
+ };
+ }
+ elsif ($state =~/^(hidden|unconfirmed)$/) {
+ @states = grep { $_->{$state} } @states;
+ }
+ $c->stash->{states} = \@states;
+}
+
+=head2 _admin_send_email
+
+Send an email to the B<user> who logged the problem, if their email address is confirmed.
+
+=cut
+
sub _admin_send_email {
my ( $c, $template, $problem ) = @_;