aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm24
-rw-r--r--t/cobrand/zurich.t45
2 files changed, 49 insertions, 20 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index 03f76aa67..242edf991 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -560,11 +560,29 @@ sub admin_report_edit {
# Can assign to:
my @bodies = $c->model('DB::Body')->search( [
- { 'me.parent' => $body->parent->id }, # Other DMs on the same level
{ 'me.parent' => $body->id }, # Their subdivisions
{ 'me.parent' => undef, 'bodies.id' => undef }, # External bodies
- ], { join => 'bodies', distinct => 1 } );
- @bodies = sort { strcoll($a->name, $b->name) } @bodies;
+ ], { join => 'bodies', distinct => 1 } )->all;
+ @bodies = grep {
+ my $cat = $_->get_extra_metadata('category');
+ if ($cat) {
+ $cat = $c->model('DB::Contact')->not_deleted->search({ category => $cat })->first;
+ }
+ !$cat || $cat->body_id == $body->id;
+ } @bodies;
+ @bodies = sort {
+ my $a_cat = $a->get_extra_metadata('category');
+ my $b_cat = $b->get_extra_metadata('category');
+ if ($a_cat && $b_cat) {
+ strcoll($a->name, $b->name)
+ } elsif ($a_cat) {
+ -1;
+ } elsif ($b_cat) {
+ 1;
+ } else {
+ strcoll($a->name, $b->name)
+ }
+ } @bodies;
$c->stash->{bodies} = \@bodies;
# Can change category to any other
diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t
index 60ccfde14..a3de931bd 100644
--- a/t/cobrand/zurich.t
+++ b/t/cobrand/zurich.t
@@ -65,23 +65,16 @@ $mech->content_like( qr/zurich/i );
# Set up bodies
my $zurich = $mech->create_body_ok( 1, 'Zurich' );
-$zurich->parent( undef );
-$zurich->update;
-my $division = $mech->create_body_ok( 2, 'Division 1' );
-$division->parent( $zurich->id );
-$division->send_method( 'Zurich' );
-$division->endpoint( 'division@example.org' );
-$division->update;
-$division->body_areas->find_or_create({ area_id => 423017 });
-my $subdivision = $mech->create_body_ok( 3, 'Subdivision A' );
-$subdivision->parent( $division->id );
-$subdivision->send_method( 'Zurich' );
-$subdivision->endpoint( 'subdivision@example.org' );
-$subdivision->update;
-my $external_body = $mech->create_body_ok( 4, 'External Body' );
-$external_body->send_method( 'Zurich' );
-$external_body->endpoint( 'external_body@example.net' );
-$external_body->update;
+my $division = $mech->create_body_ok( 423017, 'Division 1', {
+ parent => $zurich->id, send_method => 'Zurich', endpoint => 'division@example.org' } );
+my $division2 = $mech->create_body_ok( 423017, 'Division 2', {
+ parent => $zurich->id, send_method => 'Zurich', endpoint => 'division2@example.org' } );
+my $subdivision = $mech->create_body_ok( 3, 'Subdivision A',
+ { parent => $division->id, send_method => 'Zurich', endpoint => 'subdivision@example.org' } );
+my $external_body = $mech->create_body_ok( 4, 'External Body',
+ { send_method => 'Zurich', endpoint => 'external_body@example.net' } );
+my $external_body2 = $mech->create_body_ok( 4, 'Another Body External',
+ { send_method => 'Zurich', endpoint => 'external_body2@example.net' } );
sub get_export_rows_count {
my $mech = shift;
@@ -761,6 +754,24 @@ subtest "link external body to category" => sub {
is $external_body->get_extra_metadata('category'), 'Cat1';
};
+subtest "shows correct external bodies" => sub {
+ $report->discard_changes;
+ $report->state('feedback pending');
+ $report->set_extra_metadata('closure_status' => 'external');
+ $report->update;
+ $user = $mech->log_in_ok( 'dm1@example.org' );
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_like(qr/<option[^>]*>External Body<\/option>\s*<option[^>]*>Another Body External<\/option>/); # Test order
+
+ $user = $mech->log_in_ok( 'dm2@example.org' );
+ $user->update({ from_body => $division2->id });
+ $report->update({ bodies_str => $division2->id });
+ $mech->get_ok( '/admin/report_edit/' . $report->id );
+ $mech->content_contains('Another Body External');
+ $mech->content_lacks('External Body');
+ $report->update({ bodies_str => $division->id });
+};
+
subtest "problems can't be assigned to deleted bodies" => sub {
$user = $mech->log_in_ok( 'dm1@example.org' );
$user->from_body( $zurich->id );