diff options
-rw-r--r-- | .cypress/cypress/integration/buckinghamshire.js | 9 | ||||
-rwxr-xr-x | bin/fixmystreet.com/fixture | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bexley.pm | 37 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 8 | ||||
-rw-r--r-- | t/cobrand/bexley.t | 46 | ||||
-rw-r--r-- | web/cobrands/bexley/js.js | 31 | ||||
-rw-r--r-- | web/cobrands/fixmystreet/assets.js | 17 |
7 files changed, 134 insertions, 31 deletions
diff --git a/.cypress/cypress/integration/buckinghamshire.js b/.cypress/cypress/integration/buckinghamshire.js index 1f4641952..d5b14100a 100644 --- a/.cypress/cypress/integration/buckinghamshire.js +++ b/.cypress/cypress/integration/buckinghamshire.js @@ -42,4 +42,13 @@ describe('flytipping', function() { cy.get('body').should('contain', 'Thank you for your report'); }); + it('sets the site_code correctly', function() { + cy.get('.olMapViewport #fms_pan_zoom_zoomin').click(); + cy.wait('@roads-layer'); + cy.get('#map_box').click(290, 307); + cy.wait('@report-ajax'); + cy.get('select:eq(4)').select('Parks'); + cy.get('[name=site_code]').should('have.value', '7300268'); + }); + }); diff --git a/bin/fixmystreet.com/fixture b/bin/fixmystreet.com/fixture index 1f6063a47..1fa17dfad 100755 --- a/bin/fixmystreet.com/fixture +++ b/bin/fixmystreet.com/fixture @@ -95,7 +95,7 @@ if ($opt->test_fixtures) { my $bodies; foreach ( { area_id => 2234, categories => ['Fallen Tree', 'Very Urgent'], name => 'Northamptonshire County Council' }, - { area_id => 2217, categories => ['Flytipping', 'Roads'], name => 'Buckinghamshire County Council' }, + { area_id => 2217, categories => ['Flytipping', 'Roads', 'Parks'], name => 'Buckinghamshire County Council' }, { area_id => 2257, categories => ['Flytipping', 'Graffiti'], name => 'Chiltern District Council' }, { area_id => 2397, categories => [ 'Graffiti' ], name => 'Northampton Borough Council' }, { area_id => 2483, categories => [ 'Potholes', 'Other' ], name => 'Hounslow Borough Council' }, @@ -139,6 +139,21 @@ if ($opt->test_fixtures) { $child_cat->update; $child_cat = FixMyStreet::DB->resultset("Contact")->find({ + body => $bodies->{2217}, + category => 'Parks', + }); + $child_cat->set_extra_fields({ + code => 'site_code', + datatype => 'string', + description => 'site code', + order => 100, + required => 'false', + variable => 'true', + automated => 'hidden_field', + }); + $child_cat->update; + + $child_cat = FixMyStreet::DB->resultset("Contact")->find({ body => $bodies->{2483}, category => 'Other', }); diff --git a/perllib/FixMyStreet/Cobrand/Bexley.pm b/perllib/FixMyStreet/Cobrand/Bexley.pm index 1a303d633..eda276add 100644 --- a/perllib/FixMyStreet/Cobrand/Bexley.pm +++ b/perllib/FixMyStreet/Cobrand/Bexley.pm @@ -58,16 +58,35 @@ sub lookup_site_code_config { } sub open311_config { - my ($self, $row, $h, $params) = @_; + my ($self, $row, $h, $params, $contact) = @_; + + $params->{multi_photos} = 1; my $extra = $row->get_extra_fields; - # Reports made via the app probably won't have a NSGRef because we don't - # display the road layer. Instead we'll look up the closest asset from the - # WFS service at the point we're sending the report over Open311. - if (!$row->get_extra_field_value('NSGRef')) { - if (my $ref = $self->lookup_site_code($row)) { - push @$extra, { name => 'NSGRef', description => 'NSG Ref', value => $ref }; + if ($contact->email =~ /^Confirm/) { + push @$extra, + { name => 'report_url', description => 'Report URL', + value => $h->{url} }, + { name => 'title', description => 'Title', + value => $row->title }, + { name => 'description', description => 'Detail', + value => $row->detail }; + + if (!$row->get_extra_field_value('site_code')) { + if (my $ref = $self->lookup_site_code($row)) { + push @$extra, { name => 'site_code', value => $ref, description => 'Site code' }; + } + } + } elsif ($contact->email =~ /^Uniform/) { + } else { # Symology + # Reports made via the app probably won't have a NSGRef because we don't + # display the road layer. Instead we'll look up the closest asset from the + # WFS service at the point we're sending the report over Open311. + if (!$row->get_extra_field_value('NSGRef')) { + if (my $ref = $self->lookup_site_code($row)) { + push @$extra, { name => 'NSGRef', description => 'NSG Ref', value => $ref }; + } } } @@ -77,7 +96,7 @@ sub open311_config { sub admin_user_domain { 'bexley.gov.uk' } sub open311_post_send { - my ($self, $row, $h) = @_; + my ($self, $row, $h, $contact) = @_; # Check Open311 was successful return unless $row->external_id; @@ -122,7 +141,7 @@ sub open311_post_send { return unless @to; my $sender = FixMyStreet::SendReport::Email->new( to => \@to ); - $self->open311_config($row); # Populate NSGRef again if needed + $self->open311_config($row, $h, {}, $contact); # Populate NSGRef again if needed my $extra_data = join "; ", map { "$_->{description}: $_->{value}" } @{$row->get_extra_fields}; $h->{additional_information} = $extra_data; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index fcb6f7298..c4532e3b3 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -34,11 +34,11 @@ sub send { fixmystreet_body => $body, ); - my $cobrand = $body->get_cobrand_handler || $row->get_cobrand_logged; - $cobrand->call_hook(open311_config => $row, $h, \%open311_params); - my $contact = $self->fetch_category($body, $row) or next; + my $cobrand = $body->get_cobrand_handler || $row->get_cobrand_logged; + $cobrand->call_hook(open311_config => $row, $h, \%open311_params, $contact); + # Try and fill in some ones that we've been asked for, but not asked the user for my $extra = $row->get_extra_fields(); @@ -94,7 +94,7 @@ sub send { $self->error( $self->error . "\n" . $open311->error ); } - $cobrand->call_hook(open311_post_send => $row, $h); + $cobrand->call_hook(open311_post_send => $row, $h, $contact); } diff --git a/t/cobrand/bexley.t b/t/cobrand/bexley.t index 480f1ce2d..3cf71798e 100644 --- a/t/cobrand/bexley.t +++ b/t/cobrand/bexley.t @@ -34,7 +34,7 @@ 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 => 'Parks and open spaces', email => "PARK"); +$mech->create_contact_ok(body_id => $body->id, category => 'Parks and open spaces', email => "ConfirmPARK"); $mech->create_contact_ok(body_id => $body->id, category => 'Dead animal', email => "ANIM"); my $category = $mech->create_contact_ok(body_id => $body->id, category => 'Something dangerous', email => "DANG"); $category->set_extra_metadata(group => 'Danger things'); @@ -70,13 +70,13 @@ FixMyStreet::override_config { extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' } }, { category => 'Something dangerous', code => 'DANG', extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'No' } }, - { category => 'Parks and open spaces', email => 1, code => 'PARK', + { category => 'Parks and open spaces', email => 1, code => 'ConfirmPARK', extra => { 'name' => 'reportType', description => 'Type of report', 'value' => 'Wild animal' } }, - { category => 'Parks and open spaces', code => 'PARK', + { category => 'Parks and open spaces', code => 'ConfirmPARK', extra => { 'name' => 'reportType', description => 'Type of report', 'value' => 'Maintenance' } }, - { category => 'Parks and open spaces', code => 'PARK', + { category => 'Parks and open spaces', code => 'ConfirmPARK', extra => { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' } }, - { category => 'Parks and open spaces', email => 1, code => 'PARK', + { category => 'Parks and open spaces', email => 1, code => 'ConfirmPARK', extra => [ { 'name' => 'dangerous', description => 'Was it dangerous?', 'value' => 'Yes' }, { 'name' => 'reportType', description => 'Type of report', 'value' => 'Vandalism' }, @@ -100,7 +100,11 @@ FixMyStreet::override_config { my $req = $test_data->{test_req_used}; my $c = CGI::Simple->new($req->content); is $c->param('service_code'), $test->{code}; - is $c->param('attribute[NSGRef]'), 'Road ID'; + if ($test->{code} =~ /Confirm/) { + is $c->param('attribute[site_code]'), 'Road ID'; + } else { + is $c->param('attribute[NSGRef]'), 'Road ID'; + } if (my $t = $test->{email}) { my $email = $mech->get_email; @@ -109,7 +113,11 @@ FixMyStreet::override_config { } else { like $email->header('To'), qr/$t/; } - like $mech->get_text_body_from_email($email), qr/NSG Ref: Road ID/; + if ($test->{code} =~ /Confirm/) { + like $mech->get_text_body_from_email($email), qr/Site code: Road ID/; + } else { + like $mech->get_text_body_from_email($email), qr/NSG Ref: Road ID/; + } $mech->clear_emails_ok; } else { $mech->email_count_is(0); @@ -131,6 +139,30 @@ FixMyStreet::override_config { $mech->content_contains('"Danger things","Something dangerous"'); }; + + subtest 'testing special Open311 behaviour', sub { + my @reports = $mech->create_problems_for_body( 1, $body->id, 'Test', { + category => 'Parks and open spaces', cobrand => 'bexley', + latitude => 51.408484, longitude => 0.074653, areas => '2494', + photo => '74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg,74e3362283b6ef0c48686fb0e161da4043bbcc97.jpeg', + }); + my $report = $reports[0]; + + my $test_data = FixMyStreet::Script::Reports::send(); + $report->discard_changes; + ok $report->whensent, 'Report marked as sent'; + is $report->send_method_used, 'Open311', 'Report sent via Open311'; + is $report->external_id, 248, 'Report has right external ID'; + + my $req = $test_data->{test_req_used}; + my $c = CGI::Simple->new($req->content); + is $c->param('attribute[title]'), 'Test Test 1 for ' . $body->id, 'Request had correct title'; + is_deeply [ $c->param('media_url') ], [ + 'http://bexley.example.org/photo/' . $report->id . '.0.full.jpeg?74e33622', + 'http://bexley.example.org/photo/' . $report->id . '.1.full.jpeg?74e33622', + ], 'Request had multiple photos'; + }; + }; subtest 'nearest road returns correct road' => sub { diff --git a/web/cobrands/bexley/js.js b/web/cobrands/bexley/js.js index 24643e4db..89f52a7fb 100644 --- a/web/cobrands/bexley/js.js +++ b/web/cobrands/bexley/js.js @@ -74,10 +74,33 @@ fixmystreet.assets.add(road_defaults, { } }, nearest_radius: 100, - usrn: { - attribute: 'NSG_REF', - field: 'NSGRef' - } + usrn: [ + { + attribute: 'NSG_REF', + field: 'NSGRef' + }, + { + attribute: 'NSG_REF', + field: 'site_code' + } + ] +}); + +fixmystreet.assets.add(defaults, { + http_options: { + url: "https://tilma.staging.mysociety.org/mapserver/bexley", + params: { + TYPENAME: "Trees" + } + }, + asset_id_field: 'central_as', + attributes: { + central_asset_id: 'central_as', + site_code: 'site_code' + }, + asset_type: 'spot', + asset_category: ['Street', 'TPO enquiry'], + asset_item: 'tree' }); fixmystreet.assets.add(labeled_defaults, { diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index 25c1ac08e..c311b0f5f 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -236,14 +236,19 @@ OpenLayers.Layer.VectorNearest = OpenLayers.Class(OpenLayers.Layer.VectorAsset, updateUSRNField: function() { if (this.fixmystreet.usrn) { - var usrn_field = this.fixmystreet.usrn.field; - var selected_usrn; - if ( this.selected_feature ) { - selected_usrn = this.fixmystreet.getUSRN ? + if (!this.fixmystreet.usrn.length) { + this.fixmystreet.usrn = [this.fixmystreet.usrn]; + } + for (var i = 0; i < this.fixmystreet.usrn.length; i++) { + var usrn = this.fixmystreet.usrn[i]; + var selected_usrn; + if ( this.selected_feature ) { + selected_usrn = this.fixmystreet.getUSRN ? this.fixmystreet.getUSRN(this.selected_feature) : - this.selected_feature.attributes[this.fixmystreet.usrn.attribute]; + this.selected_feature.attributes[usrn.attribute]; + } + $("input[name=" + usrn.field + "]").val(selected_usrn); } - $("input[name=" + usrn_field + "]").val(selected_usrn); } }, |