diff options
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Zurich.pm | 17 | ||||
-rw-r--r-- | t/cobrand/zurich.t | 10 |
2 files changed, 24 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm index 2b3542a92..1bbe3b088 100644 --- a/perllib/FixMyStreet/Cobrand/Zurich.pm +++ b/perllib/FixMyStreet/Cobrand/Zurich.pm @@ -426,17 +426,22 @@ sub admin_report_edit { # 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 ); @@ -486,6 +491,18 @@ sub admin_report_edit { # 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'); } diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index cd826a8d3..a6cf934ef 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -1,5 +1,5 @@ # TODO -# Overdue alerts +# Overdue alerts use strict; use warnings; @@ -131,14 +131,14 @@ subtest "changing of categories" => sub { }); } - # put report into know category + # 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" } }); - my $pre_change_comment = $comments_rs->first; + ok ( !$comments_rs->first, "There are no comments yet" ); # change the category via the web interface $mech->get_ok( '/admin/report_edit/' . $report->id ); @@ -148,6 +148,10 @@ subtest "changing of categories" => sub { $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 }); }; |