Skip to content

Commit

Permalink
[Zurich] admin workflow changes available states
Browse files Browse the repository at this point in the history
See mysociety/societyworks#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/societyworks#718)
  • Loading branch information
osfameron authored and davea committed Oct 6, 2015
1 parent 34f3f5a commit e7c35a0
Show file tree
Hide file tree
Showing 11 changed files with 558 additions and 279 deletions.
153 changes: 142 additions & 11 deletions perllib/FixMyStreet/Cobrand/Zurich.pm
Expand Up @@ -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 );
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -642,6 +680,7 @@ sub admin_report_edit {
->search( { problem_id => $problem->id }, { order_by => 'created' } )
->all ];

$self->stash_states($problem);
return 1;
}

Expand All @@ -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');

Expand All @@ -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>';

Expand All @@ -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 ) = @_;

Expand Down
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/DB/ResultSet/Problem.pm
Expand Up @@ -247,7 +247,7 @@ sub send_reports {
my $site = $site_override || CronFns::site($base_url);

my $states = [ 'confirmed', 'fixed' ];
$states = [ 'unconfirmed', 'confirmed', 'in progress', 'planned', 'closed' ] if $site eq 'zurich';
$states = [ 'unconfirmed', 'confirmed', 'in progress', 'planned', 'closed', 'investigating' ] if $site eq 'zurich';
my $unsent = $rs->search( {
state => $states,
whensent => undef,
Expand Down
3 changes: 3 additions & 0 deletions perllib/FixMyStreet/SendReport/Zurich.pm
Expand Up @@ -12,6 +12,7 @@ sub build_recipient_list {
if ( $row->external_body ) {
$body = FixMyStreet::App->model("DB::Body")->find( { id => $row->external_body } );
$h->{bodies_name} = $body->name;
$h->{external_message} = $row->get_extra_metadata('external_message') || '';
}
my $body_email = $body->endpoint;

Expand Down Expand Up @@ -39,6 +40,8 @@ sub get_template {
$template = 'submit-in-progress.txt';
} elsif ( $row->state eq 'planned' ) {
$template = 'submit-feedback-pending.txt';
} elsif ( $row->state eq 'investigating' ) {
$template = 'submit-external-wish.txt';
} elsif ( $row->state eq 'closed' ) {
$template = 'submit-external.txt';
if ( $row->extra->{third_personal} ) {
Expand Down

0 comments on commit e7c35a0

Please sign in to comment.