aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Open311/Updates.pm17
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm13
-rw-r--r--perllib/Open311/UpdatesBase.pm37
3 files changed, 23 insertions, 44 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Open311/Updates.pm b/perllib/FixMyStreet/App/Controller/Open311/Updates.pm
index 105400a8a..d5754bab7 100644
--- a/perllib/FixMyStreet/App/Controller/Open311/Updates.pm
+++ b/perllib/FixMyStreet/App/Controller/Open311/Updates.pm
@@ -3,7 +3,6 @@ package FixMyStreet::App::Controller::Open311::Updates;
use utf8;
use Moose;
use namespace::autoclean;
-use Open311;
use Open311::GetServiceRequestUpdates;
BEGIN { extends 'Catalyst::Controller'; }
@@ -31,7 +30,6 @@ sub receive : Regex('^open311/v2/servicerequestupdates.(xml|json)$') : Args(0) {
$body = $c->model('DB::Body')->find({ id => $c->get_param('jurisdiction_id') });
}
$c->detach('bad_request', ['jurisdiction_id']) unless $body;
- my $user = $body->comment_user;
my $key = $c->get_param('api_key') || '';
my $token = $c->cobrand->feature('open311_token') || '';
@@ -45,21 +43,8 @@ sub receive : Regex('^open311/v2/servicerequestupdates.(xml|json)$') : Args(0) {
$request->{$_} = $c->get_param($_) || $c->detach('bad_request', [ $_ ]);
}
- my %open311_conf = (
- endpoint => $body->endpoint,
- api_key => $body->api_key,
- jurisdiction => $body->jurisdiction,
- extended_statuses => $body->send_extended_statuses,
- );
-
- my $cobrand = $body->get_cobrand_handler;
- $cobrand->call_hook(open311_config_updates => \%open311_conf)
- if $cobrand;
-
- my $open311 = Open311->new(%open311_conf);
my $updates = Open311::GetServiceRequestUpdates->new(
- system_user => $user,
- current_open311 => $open311,
+ system_user => $body->comment_user,
current_body => $body,
);
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index ad324fe60..f5933d754 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -1679,21 +1679,8 @@ sub create_related_things : Private {
foreach my $body (values %{$problem->bodies}) {
my $user = $body->comment_user or next;
- my %open311_conf = (
- endpoint => $body->endpoint || '',
- api_key => $body->api_key || '',
- jurisdiction => $body->jurisdiction || '',
- extended_statuses => $body->send_extended_statuses,
- );
-
- my $cobrand = $body->get_cobrand_handler;
- $cobrand->call_hook(open311_config_updates => \%open311_conf)
- if $cobrand;
-
- my $open311 = Open311->new(%open311_conf);
my $updates = Open311::GetServiceRequestUpdates->new(
system_user => $user,
- current_open311 => $open311,
current_body => $body,
blank_updates_permitted => 1,
);
diff --git a/perllib/Open311/UpdatesBase.pm b/perllib/Open311/UpdatesBase.pm
index c6ad3277a..0be324773 100644
--- a/perllib/Open311/UpdatesBase.pm
+++ b/perllib/Open311/UpdatesBase.pm
@@ -15,7 +15,8 @@ has suppress_alerts => ( is => 'rw', default => 0 );
has blank_updates_permitted => ( is => 'rw', default => 0 );
has current_body => ( is => 'rw' );
-has current_open311 => ( is => 'rw' );
+has current_open311 => ( is => 'rwp', lazy => 1, builder => 1 );
+has open311_config => ( is => 'ro' ); # If we need to pass in a devolved contact
Readonly::Scalar my $AREA_ID_OXFORDSHIRE => 2237;
@@ -59,20 +60,7 @@ sub fetch {
$pm->start and next;
$self->current_body( $body );
-
- my %open311_conf = (
- endpoint => $body->endpoint,
- api_key => $body->api_key,
- jurisdiction => $body->jurisdiction,
- extended_statuses => $body->send_extended_statuses,
- );
-
- my $cobrand = $body->get_cobrand_handler;
- $cobrand->call_hook(open311_config_updates => \%open311_conf)
- if $cobrand;
-
- $self->current_open311( $open311 || Open311->new(%open311_conf) );
-
+ $self->_set_current_open311( $open311 || $self->_build_current_open311 );
$self->suppress_alerts( $body->suppress_alerts );
$self->blank_updates_permitted( $body->blank_updates_permitted );
$self->system_user( $body->comment_user );
@@ -84,6 +72,25 @@ sub fetch {
$pm->wait_all_children;
}
+sub _build_current_open311 {
+ my $self = shift;
+
+ my $body = $self->current_body;
+ my $conf = $self->open311_config || $body;
+ my %open311_conf = (
+ endpoint => $conf->endpoint || '',
+ api_key => $conf->api_key || '',
+ jurisdiction => $conf->jurisdiction || '',
+ extended_statuses => $body->send_extended_statuses,
+ );
+
+ my $cobrand = $body->get_cobrand_handler;
+ $cobrand->call_hook(open311_config_updates => \%open311_conf)
+ if $cobrand;
+
+ return Open311->new(%open311_conf);
+}
+
sub check_date {
my ($self, $request, @args) = @_;