aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2018-05-16 14:35:57 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-08-06 09:39:42 +0100
commitcc3e8bd6e93fd293934d8697e0daea58494ad28f (patch)
tree6ef5483d04e678407f3889d9f09fbd27bbe5b217
parent18e74eeb512c2824ca43c54fead5ba63d04f361b (diff)
allow front end to not send to specific body
add a do_not_send parameter to reports which allows the front end to specify a comma separated list of bodies that reports should not be sent to even if there is a valid contact match. This enables asset layers to override backend body processing, e.g. if a body only accepts reports that are on a road this allows the front end to specify that.
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm15
-rw-r--r--t/app/controller/report_new.t7
-rw-r--r--templates/web/base/report/new/form_report.html1
-rw-r--r--web/cobrands/bromley/assets.js4
-rw-r--r--web/cobrands/buckinghamshire/assets.js4
-rw-r--r--web/cobrands/fixmystreet/assets.js63
-rw-r--r--web/cobrands/fixmystreet/fixmystreet.js13
8 files changed, 96 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f727686f3..b26064f0a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,7 @@
- Development improvements:
- Cobrand hook for presenting custom search results. #2183
- Cobrand hook to allow extra login conditions #2092
+ - Add ability for client to set bodies not to be sent to.
* v2.3.4 (7th June 2018)
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index bed69431a..c332830b9 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -955,7 +955,9 @@ sub process_report : Private {
my $body = $c->model('DB::Body')->search({ name => $single_body_only })->first;
$body ? $body->id : '-1';
} else {
- my $bodies = $c->forward('contacts_to_bodies', [ $report->category ]);
+ my $contact_options = {};
+ $contact_options->{do_not_send} = [ $c->get_param_list('do_not_send', 1) ];
+ my $bodies = $c->forward('contacts_to_bodies', [ $report->category, $contact_options ]);
join(',', map { $_->id } @$bodies) || '-1';
}
};
@@ -1014,10 +1016,19 @@ sub process_report : Private {
}
sub contacts_to_bodies : Private {
- my ($self, $c, $category) = @_;
+ my ($self, $c, $category, $options) = @_;
my @contacts = grep { $_->category eq $category } @{$c->stash->{contacts}};
+ # check that the front end has not indicated that we should not send to a
+ # body. This is usually because the asset code thinks it's not near enough
+ # to a road.
+ if ($options->{do_not_send}) {
+ my %do_not_send_check = map { $_ => 1 } @{$options->{do_not_send}};
+ my @contacts_filtered = grep { !$do_not_send_check{$_->body->name} } @contacts;
+ @contacts = @contacts_filtered if scalar @contacts_filtered;
+ }
+
if ($c->stash->{unresponsive}{$category} || $c->stash->{unresponsive}{ALL} || !@contacts) {
[];
} else {
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 8c4deec56..048f2644e 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -967,6 +967,13 @@ foreach my $test (
extra_fields => { single_body_only => 'Invalid council' },
email_count => 1,
},
+ {
+ desc => "test do_not_send means body is ignored",
+ category => 'Street lighting',
+ councils => [ 2326 ],
+ extra_fields => { do_not_send => 'Gloucestershire County Council' },
+ email_count => 1,
+ },
) {
subtest $test->{desc} => sub {
diff --git a/templates/web/base/report/new/form_report.html b/templates/web/base/report/new/form_report.html
index 9526b677c..ce8f69855 100644
--- a/templates/web/base/report/new/form_report.html
+++ b/templates/web/base/report/new/form_report.html
@@ -64,4 +64,5 @@
[% END %]
<input type="hidden" id="single_body_only" name="single_body_only" value="">
+ <input type="hidden" id="do_not_send" name="do_not_send" value="">
<input type="hidden" name="submit_problem" value="1">
diff --git a/web/cobrands/bromley/assets.js b/web/cobrands/bromley/assets.js
index 6d05e0084..959148e5d 100644
--- a/web/cobrands/bromley/assets.js
+++ b/web/cobrands/bromley/assets.js
@@ -82,11 +82,11 @@ fixmystreet.assets.add($.extend(true, {}, defaults, {
actions: {
found: function(layer, feature) {
if (!fixmystreet.assets.selectedFeature()) {
- $('#single_body_only').val('TfL');
+ fixmystreet.body_overrides.only_send('TfL');
}
},
not_found: function(layer) {
- $('#single_body_only').val('');
+ fixmystreet.body_overrides.remove_only_send();
}
}
}));
diff --git a/web/cobrands/buckinghamshire/assets.js b/web/cobrands/buckinghamshire/assets.js
index 9b392daba..82301c4f2 100644
--- a/web/cobrands/buckinghamshire/assets.js
+++ b/web/cobrands/buckinghamshire/assets.js
@@ -172,6 +172,7 @@ fixmystreet.assets.add($.extend(true, {}, defaults, {
all_categories: true,
actions: {
found: function(layer, feature) {
+ fixmystreet.body_overrides.allow_send(layer.fixmystreet.body);
if (fixmystreet.assets.selectedFeature()) {
hide_responsibility_errors();
enable_report_form();
@@ -180,6 +181,7 @@ fixmystreet.assets.add($.extend(true, {}, defaults, {
enable_report_form();
} else if (is_only_body(layer.fixmystreet.body)) {
// User has clicked a road that Bucks don't maintain.
+ fixmystreet.body_overrides.do_not_send(layer.fixmystreet.body);
show_responsibility_error("#js-not-council-road");
disable_report_form();
}
@@ -189,7 +191,9 @@ fixmystreet.assets.add($.extend(true, {}, defaults, {
// If a feature wasn't found at the location they've clicked, it's
// probably a field or something. Show an error to that effect,
// unless an asset is selected.
+ fixmystreet.body_overrides.do_not_send(layer.fixmystreet.body);
if (fixmystreet.assets.selectedFeature()) {
+ fixmystreet.body_overrides.allow_send(layer.fixmystreet.body);
hide_responsibility_errors();
enable_report_form();
} else if (is_only_body(layer.fixmystreet.body)){
diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js
index 11ea1c80e..cd1e202e5 100644
--- a/web/cobrands/fixmystreet/assets.js
+++ b/web/cobrands/fixmystreet/assets.js
@@ -136,7 +136,7 @@ OpenLayers.Layer.VectorNearest = OpenLayers.Class(OpenLayers.Layer.VectorAsset,
if (this.fixmystreet.actions) {
this.fixmystreet.actions.found(this, this.selected_feature);
} else if (!fixmystreet.assets.selectedFeature()) {
- $('#single_body_only').val(this.fixmystreet.body);
+ fixmystreet.body_overrides.only_send(this.fixmystreet.body);
}
},
@@ -144,7 +144,7 @@ OpenLayers.Layer.VectorNearest = OpenLayers.Class(OpenLayers.Layer.VectorAsset,
if (this.fixmystreet.actions) {
this.fixmystreet.actions.not_found(this);
} else {
- $('#single_body_only').val('');
+ fixmystreet.body_overrides.remove_only_send();
}
},
@@ -742,3 +742,62 @@ OpenLayers.Request.XMLHttpRequest.prototype.setRequestHeader = function(sName, s
return this._object.setRequestHeader(sName, sValue);
};
})();
+
+/* Handling of body override functionality */
+
+fixmystreet.body_overrides = (function(){
+
+var do_not_send = [];
+var only_send = '';
+
+function update() {
+ $('#do_not_send').val(fixmystreet.utils.array_to_csv_line(do_not_send));
+ $('#single_body_only').val(only_send);
+ $(fixmystreet).trigger('body_overrides:change');
+}
+
+return {
+ clear: function() {
+ do_not_send = [];
+ update();
+ },
+ only_send: function(body) {
+ only_send = body;
+ update();
+ },
+ remove_only_send: function() {
+ only_send = '';
+ update();
+ },
+ do_not_send: function(body) {
+ do_not_send.push(body);
+ update();
+ },
+ allow_send: function(body) {
+ do_not_send = $.grep(do_not_send, function(a) { return a !== body; });
+ update();
+ }
+};
+
+})();
+
+$(fixmystreet).on('body_overrides:change', function() {
+ var councils_text = $('#js-councils_text').html();
+
+ var single_body_only = $('#single_body_only').val();
+ if (single_body_only) {
+ councils_text = councils_text.replace(/<strong>.*<\/strong>/, '<strong>' + single_body_only + '</strong>');
+ }
+
+ var do_not_send = $('#do_not_send').val();
+ if (do_not_send) {
+ do_not_send = fixmystreet.utils.csv_to_array(do_not_send);
+ for (var i=0; i<do_not_send.length; i++) {
+ // XXX Translations
+ councils_text = councils_text.replace(new RegExp('or <strong>' + do_not_send[i] + '</strong>'), '');
+ councils_text = councils_text.replace(new RegExp('<strong>' + do_not_send[i] + '</strong> or '), '');
+ }
+ }
+
+ $('#js-councils_text').html(councils_text);
+});
diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js
index 5f9dd9699..1b863625f 100644
--- a/web/cobrands/fixmystreet/fixmystreet.js
+++ b/web/cobrands/fixmystreet/fixmystreet.js
@@ -410,6 +410,9 @@ $.extend(fixmystreet.set_up, {
$category_meta.empty();
}
fixmystreet.bodies = data.bodies || [];
+ if (fixmystreet.body_overrides) {
+ fixmystreet.body_overrides.clear();
+ }
$(fixmystreet).trigger('report_new:category_change:extras_received');
});
@@ -889,14 +892,9 @@ $.extend(fixmystreet.set_up, {
});
fixmystreet.update_councils_text = function(data) {
- var single_body_only = $('#single_body_only').val();
- if (single_body_only) {
- data.councils_text = data.councils_text.replace(/<strong>.*<\/strong>/, '<strong>' + single_body_only + '</strong>');
- }
-
$('#js-councils_text').html(data.councils_text);
$('#js-councils_text_private').html(data.councils_text_private);
-
+ $(fixmystreet).trigger('body_overrides:change');
};
// The new location will be saved to a history state unless
@@ -942,6 +940,9 @@ fixmystreet.update_pin = function(lonlat, savePushState) {
}
fixmystreet.bodies = data.bodies || [];
+ if (fixmystreet.body_overrides) {
+ fixmystreet.body_overrides.clear();
+ }
// If the category filter appears on the map and the user has selected
// something from it, then pre-fill the category field in the report,