aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Reports.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/Bexley.pm20
-rw-r--r--t/cobrand/bexley.t25
-rw-r--r--templates/web/base/admin/reports/edit.html2
4 files changed, 44 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Reports.pm b/perllib/FixMyStreet/App/Controller/Admin/Reports.pm
index 91b086637..c57b207e2 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Reports.pm
@@ -255,7 +255,7 @@ sub edit : Path('/admin/report_edit') : Args(1) {
$c->detach('edit_display') if $done;
}
- if ( $c->get_param('resend') && !$c->cobrand->call_hook('disable_resend') ) {
+ if ( $c->get_param('resend') && !$c->cobrand->call_hook('disable_resend_button') ) {
$c->forward('/auth/check_csrf_token');
$problem->resend;
@@ -382,7 +382,7 @@ sub edit_category : Private {
my ($self, $c, $problem, $no_comment) = @_;
if ((my $category = $c->get_param('category')) ne $problem->category) {
- my $force_resend = $c->cobrand->call_hook('category_change_force_resend');
+ my $force_resend = $c->cobrand->call_hook('category_change_force_resend', $problem->category, $category);
my $disable_resend = $c->cobrand->call_hook('disable_resend');
my $category_old = $problem->category;
$problem->category($category);
diff --git a/perllib/FixMyStreet/Cobrand/Bexley.pm b/perllib/FixMyStreet/Cobrand/Bexley.pm
index 5900ba02d..bbef4154b 100644
--- a/perllib/FixMyStreet/Cobrand/Bexley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bexley.pm
@@ -27,7 +27,25 @@ sub disambiguate_location {
};
}
-sub disable_resend { 1 }
+sub disable_resend_button { 1 }
+
+# We can resend reports upon category change, unless it will be going to the
+# same Symology database, because that will reject saying it already has the
+# ID.
+sub category_change_force_resend {
+ my ($self, $old, $new) = @_;
+
+ # Get the Open311 identifiers
+ my $contacts = $self->{c}->stash->{contacts};
+ ($old) = map { $_->email } grep { $_->category eq $old } @$contacts;
+ ($new) = map { $_->email } grep { $_->category eq $new } @$contacts;
+
+ # Okay if we're switching to/from/within Confirm/Uniform
+ return 1 if $old =~ /^(Confirm|Uniform)/ || $new =~ /^(Confirm|Uniform)/;
+
+ # Otherwise, okay if we're switching between Symology DBs, but not within
+ return ($old =~ /^StreetLighting/ xor $new =~ /^StreetLighting/);
+}
sub on_map_default_status { 'open' }
diff --git a/t/cobrand/bexley.t b/t/cobrand/bexley.t
index 511c0770e..d7e996e0d 100644
--- a/t/cobrand/bexley.t
+++ b/t/cobrand/bexley.t
@@ -35,7 +35,7 @@ my $mech = FixMyStreet::TestMech->new;
my $body = $mech->create_body_ok(2494, 'London Borough of Bexley', {
send_method => 'Open311', api_key => 'key', 'endpoint' => 'e', 'jurisdiction' => 'j' });
$mech->create_contact_ok(body_id => $body->id, category => 'Abandoned and untaxed vehicles', email => "ABAN");
-$mech->create_contact_ok(body_id => $body->id, category => 'Lamp post', email => "LAMP");
+$mech->create_contact_ok(body_id => $body->id, category => 'Lamp post', email => "StreetLightingLAMP");
$mech->create_contact_ok(body_id => $body->id, category => 'Gulley covers', email => "GULL");
$mech->create_contact_ok(body_id => $body->id, category => 'Damaged road', email => "ROAD");
$mech->create_contact_ok(body_id => $body->id, category => 'Flooding in the road', email => "ConfirmFLOD");
@@ -90,9 +90,9 @@ FixMyStreet::override_config {
extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'No' } },
{ category => 'Damaged road', code => 'ROAD', email => ['p1'],
extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' } },
- { category => 'Lamp post', code => 'LAMP', email => ['thirdparty', 'another'],
+ { category => 'Lamp post', code => 'StreetLightingLAMP', email => ['thirdparty', 'another'],
extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'No' } },
- { category => 'Lamp post', code => 'LAMP', email => ['thirdparty', 'another'],
+ { category => 'Lamp post', code => 'StreetLightingLAMP', email => ['thirdparty', 'another'],
extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' } },
{ category => 'Flytipping', code => 'UniformFLY', email => ['eh'] },
{ category => 'Flooding in the road', code => 'ConfirmFLOD', email => ['flooding'] },
@@ -146,6 +146,25 @@ FixMyStreet::override_config {
$mech->content_lacks('Resend report');
};
+ subtest "resending of reports by changing category" => sub {
+ $mech->get_ok('/admin/report_edit/' . $report->id);
+ $mech->submit_form_ok({ with_fields => { category => 'Damaged road' } });
+ my $test_data = FixMyStreet::Script::Reports::send();
+ my $req = $test_data->{test_req_used};
+ my $c = CGI::Simple->new($req->content);
+ is $c->param('service_code'), 'ROAD', 'Report resent in new category';
+
+ $mech->submit_form_ok({ with_fields => { category => 'Gulley covers' } });
+ $test_data = FixMyStreet::Script::Reports::send();
+ is $test_data, undef, 'Report not resent';
+
+ $mech->submit_form_ok({ with_fields => { category => 'Lamp post' } });
+ $test_data = FixMyStreet::Script::Reports::send();
+ $req = $test_data->{test_req_used};
+ $c = CGI::Simple->new($req->content);
+ is $c->param('service_code'), 'StreetLightingLAMP', 'Report resent';
+ };
+
subtest 'extra CSV column present' => sub {
$mech->get_ok('/dashboard?export=1');
$mech->content_contains(',Category,Subcategory,');
diff --git a/templates/web/base/admin/reports/edit.html b/templates/web/base/admin/reports/edit.html
index 4f9b58887..d2b866d01 100644
--- a/templates/web/base/admin/reports/edit.html
+++ b/templates/web/base/admin/reports/edit.html
@@ -81,7 +81,7 @@ class="admin-offsite-link">[% problem.latitude %], [% problem.longitude %]</a>
[% IF problem.send_method_used %]
([% problem.send_method_used %])
[% END %]
- [% IF problem.state == 'confirmed' AND problem.whensent AND NOT c.cobrand.disable_resend %]
+ [% IF problem.state == 'confirmed' AND problem.whensent AND NOT c.cobrand.disable_resend_button %]
<input data-confirm="[% loc('Are you sure?') %]" class="btn" type="submit" name="resend" value="[% loc('Resend report') %]">
[% ELSIF NOT problem.whensent %]
<input type="submit" class="btn" name="mark_sent" value="[% loc('Mark as sent') %]">