aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Mytton <self@hecticjeff.net>2013-09-12 09:58:10 +0100
committerChris Mytton <self@hecticjeff.net>2013-09-12 09:58:10 +0100
commit2b85ab1153a5dba9b5bb671144115a7f548dc6b3 (patch)
tree763fa15c0345258aa54949c77d574c270efb672a
parent738b1068c8ea9df4a24056f1784ff5846bb8bb6b (diff)
parentdec287591b28d4e2eff79f763306168125d6981a (diff)
Merge branch 'zurich-407-generate-note-when-sdm-assigned'
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm28
-rw-r--r--t/cobrand/zurich.t44
2 files changed, 65 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index 450786c88..6e507037a 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -411,7 +411,6 @@ sub admin_report_edit {
user => $c->user->obj,
state => 'hidden', # seems best fit, should not be shown publicly
mark_fixed => 0,
- problem_state => $problem->state,
anonymous => 1,
extra => { is_internal_note => 1 },
} );
@@ -421,24 +420,28 @@ sub admin_report_edit {
# Problem updates upon submission
if ( ($type eq 'super' || $type eq 'dm') && $c->req->param('submit') ) {
# Predefine the hash so it's there for lookups
- # XXX Note you need to shallow copy each time you set it, due to a bug? in FilterColumn.
my $extra = $problem->extra || {};
$extra->{publish_photo} = $c->req->params->{publish_photo} || 0;
$extra->{third_personal} = $c->req->params->{third_personal} || 0;
# Make sure we have a copy of the original detail field
$extra->{original_detail} = $problem->detail if !$extra->{original_detail} && $c->req->params->{detail} && $problem->detail ne $c->req->params->{detail};
+ # Some changes will be accompanied by an internal note, which if needed
+ # should be stored in this variable.
+ my $internal_note_text = "";
# Workflow things
my $redirect = 0;
my $new_cat = $c->req->params->{category};
if ( $new_cat && $new_cat ne $problem->category ) {
my $cat = $c->model('DB::Contact')->search( { category => $c->req->params->{category} } )->first;
+ my $old_cat = $problem->category;
$problem->category( $new_cat );
$problem->external_body( undef );
$problem->bodies_str( $cat->body_id );
$problem->whensent( undef );
$extra->{changed_category} = 1;
+ $internal_note_text = "Weitergeleitet von $old_cat an $new_cat";
$redirect = 1 if $cat->body_id ne $body->id;
} elsif ( my $subdiv = $c->req->params->{body_subdivision} ) {
$extra->{moderated_overdue} = $self->overdue( $problem );
@@ -461,7 +464,7 @@ sub admin_report_edit {
}
}
- $problem->extra( { %$extra } );
+ $problem->extra( $extra );
$problem->title( $c->req->param('title') );
$problem->detail( $c->req->param('detail') );
$problem->latitude( $c->req->param('latitude') );
@@ -470,7 +473,7 @@ sub admin_report_edit {
# Final, public, Update from DM
if (my $update = $c->req->param('status_update')) {
$extra->{public_response} = $update;
- $problem->extra( { %$extra } );
+ $problem->extra( $extra );
if ($c->req->params->{publish_response}) {
$problem->state( 'fixed - council' );
_admin_send_email( $c, 'problem-closed.txt', $problem );
@@ -484,9 +487,22 @@ sub admin_report_edit {
'<p><em>' . _('Updated!') . '</em></p>';
# do this here otherwise lastupdate and confirmed times
- # do not display correctly
+ # do not display correctly (reloads problem from database, including
+ # fields modified by the database when saving)
$problem->discard_changes;
+ # Create an internal note if required
+ if ($internal_note_text) {
+ $problem->add_to_comments( {
+ text => $internal_note_text,
+ user => $c->user->obj,
+ state => 'hidden', # seems best fit, should not be shown publicly
+ mark_fixed => 0,
+ anonymous => 1,
+ extra => { is_internal_note => 1 },
+ } );
+ }
+
if ( $redirect ) {
$c->detach('index');
}
@@ -543,7 +559,7 @@ sub admin_report_edit {
if ($c->req->param('no_more_updates')) {
my $extra = $problem->extra || {};
$extra->{subdiv_overdue} = $self->overdue( $problem );
- $problem->extra( { %$extra } );
+ $problem->extra( $extra );
$problem->bodies_str( $body->parent->id );
$problem->whensent( undef );
$problem->state( 'planned' );
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index 869e5d460..035cdafe0 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -1,5 +1,5 @@
# TODO
-# Overdue alerts
+# Overdue alerts
use strict;
use warnings;
@@ -115,6 +115,48 @@ $mech->content_contains( 'report_edit/' . $report->id );
$mech->content_contains( DateTime->now->strftime("%d.%m.%Y") );
$mech->content_contains( 'Erfasst' );
+
+subtest "changing of categories" => sub {
+ # create a few categories (which are actually contacts)
+ foreach my $name ( qw/Cat1 Cat2/ ) {
+ FixMyStreet::App->model('DB::Contact')->find_or_create({
+ body => $division,
+ category => $name,
+ email => "$name\@example.org",
+ confirmed => 1,
+ deleted => 0,
+ editor => "editor",
+ whenedited => DateTime->now(),
+ note => "note for $name",
+ });
+ }
+
+ # put report into known category
+ my $original_category = $report->category;
+ $report->update({ category => 'Cat1' });
+ is( $report->category, "Cat1", "Category set to Cat1" );
+
+ # get the latest comment
+ my $comments_rs = $report->comments->search({},{ order_by => { -desc => "created" } });
+ ok ( !$comments_rs->first, "There are no comments yet" );
+
+ # change the category via the web interface
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->submit_form_ok( { with_fields => { category => 'Cat2' } } );
+
+ # check changes correctly saved
+ $report->discard_changes();
+ is( $report->category, "Cat2", "Category changed to Cat2 as expected" );
+
+ # Check that a new comment has been created.
+ my $new_comment = $comments_rs->first();
+ is( $new_comment->text, "Weitergeleitet von Cat1 an Cat2", "category change comment created" );
+
+ # restore report to original state.
+ $report->update({category => $original_category });
+};
+
+
$mech->get_ok( '/admin/report_edit/' . $report->id );
$mech->content_contains( 'Unbest&auml;tigt' ); # Unconfirmed email
$mech->submit_form_ok( { with_fields => { state => 'confirmed' } } );