aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rwxr-xr-xbin/send-daemon1
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm2
-rwxr-xr-xperllib/Open311/PostServiceRequestUpdates.pm25
-rw-r--r--t/open311/post-service-request-updates.t9
5 files changed, 26 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0ae55f306..968d00efb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,8 @@
- Links inside `#front-main` can be customised using `$primary_link_*` Sass variables. #3007
- Add option to show front end testing code coverage. #3036
- Add function to fetch user's country from Gaze.
+ - Open311 improvements:
+ - Use devolved data on update sending.
- UK:
- Add option for recaptcha. #3050
diff --git a/bin/send-daemon b/bin/send-daemon
index dee9e949f..ae54c2564 100755
--- a/bin/send-daemon
+++ b/bin/send-daemon
@@ -125,7 +125,6 @@ sub look_for_update {
my ($body) = grep { $bodies->{$_} } @{$comment->problem->bodies_str_ids};
$body = $bodies->{$body};
- $updates->construct_open311($body);
$updates->process_update($body, $comment);
}
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index c8e11f93d..73340338b 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -961,7 +961,7 @@ sub get_body_sender {
# look up via category
my $contact = $body->contacts->search( { category => $category } )->first;
- if ( $body->can_be_devolved && $contact->send_method ) {
+ if ( $body->can_be_devolved && $contact && $contact->send_method ) {
return { method => $contact->send_method, config => $contact, contact => $contact };
}
diff --git a/perllib/Open311/PostServiceRequestUpdates.pm b/perllib/Open311/PostServiceRequestUpdates.pm
index 68823343c..d7345ea4d 100755
--- a/perllib/Open311/PostServiceRequestUpdates.pm
+++ b/perllib/Open311/PostServiceRequestUpdates.pm
@@ -14,14 +14,12 @@ use Open311;
use constant SEND_METHOD_OPEN311 => 'Open311';
has verbose => ( is => 'ro', default => 0 );
-has current_open311 => ( is => 'rw' );
sub send {
my $self = shift;
my $bodies = $self->fetch_bodies;
foreach my $body (values %$bodies) {
- $self->construct_open311($body);
$self->process_body($body);
}
}
@@ -41,18 +39,25 @@ sub fetch_bodies {
}
sub construct_open311 {
- my ($self, $body) = @_;
- my $o = Open311->new($self->open311_params($body));
- $self->current_open311($o);
+ my ($self, $body, $comment) = @_;
+ my $o = Open311->new($self->open311_params($body, $comment));
+ return $o;
}
sub open311_params {
- my ($self, $body) = @_;
+ my ($self, $body, $comment) = @_;
+
+ my $conf = $body;
+ if ($comment) {
+ my $cobrand_logged = $comment->get_cobrand_logged;
+ my $sender = $cobrand_logged->get_body_sender($body, $comment->problem->category);
+ $conf = $sender->{config};
+ }
my %open311_conf = (
- endpoint => $body->endpoint,
- jurisdiction => $body->jurisdiction,
- api_key => $body->api_key,
+ endpoint => $conf->endpoint,
+ jurisdiction => $conf->jurisdiction,
+ api_key => $conf->api_key,
extended_statuses => $body->send_extended_statuses,
fixmystreet_body => $body,
);
@@ -119,7 +124,7 @@ sub process_update {
return;
}
- my $o = $self->current_open311;
+ my $o = $self->construct_open311($body, $comment);
$cobrand->call_hook(open311_pre_send => $comment, $o);
diff --git a/t/open311/post-service-request-updates.t b/t/open311/post-service-request-updates.t
index 71bba4af7..75711bd2d 100644
--- a/t/open311/post-service-request-updates.t
+++ b/t/open311/post-service-request-updates.t
@@ -16,7 +16,7 @@ my $params = {
endpoint => 'endpoint',
jurisdiction => 'home',
};
-my $bromley = $mech->create_body_ok(2482, 'Bromley', { %$params, send_extended_statuses => 1 });
+my $bromley = $mech->create_body_ok(2482, 'Bromley', { %$params, send_extended_statuses => 1, can_be_devolved => 1 });
my $oxon = $mech->create_body_ok(2237, 'Oxfordshire', { %$params, id => "5" . $bromley->id });
my $bucks = $mech->create_body_ok(2217, 'Buckinghamshire', $params);
my $lewisham = $mech->create_body_ok(2492, 'Lewisham', $params);
@@ -135,5 +135,12 @@ subtest 'Oxfordshire gets an ID' => sub {
};
};
+subtest 'Devolved contact' => sub {
+ $mech->create_contact_ok(body_id => $bromley->id, category => 'Other', email => "OTHER", send_method => 'Open311', endpoint => '/devolved-endpoint/');
+ $c1->update({ send_fail_count => 0 });
+ $o->send;
+ $c1->discard_changes;
+ like $c1->send_fail_reason, qr/devolved-endpoint/, 'Failure message contains correct endpoint';
+};
done_testing();