aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Open311/Updates.pm
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
committerMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
commit09dacfc6b8bf62addeee16c20b1d90c2a256da96 (patch)
tree7caa2bf9e92227ab74448f9b746dd28bbcb81b2a /perllib/FixMyStreet/App/Controller/Open311/Updates.pm
parent585e57484f9c6332668bf1ac0a6a3b39dbe32223 (diff)
parentcea89fb87a96943708a1db0f646492fbfaaf000f (diff)
Merge tag 'v3.1' into fiksgatami-devfiksgatami-dev
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Open311/Updates.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Open311/Updates.pm31
1 files changed, 14 insertions, 17 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Open311/Updates.pm b/perllib/FixMyStreet/App/Controller/Open311/Updates.pm
index 105400a8a..8881a1b87 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,37 +43,36 @@ 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,
- );
+ $c->forward('process_update', [ $body, $request ]);
+}
- my $cobrand = $body->get_cobrand_handler;
- $cobrand->call_hook(open311_config_updates => \%open311_conf)
- if $cobrand;
+sub process_update : Private {
+ my ($self, $c, $body, $request) = @_;
- 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,
);
my $p = $updates->find_problem($request);
$c->detach('bad_request', [ 'not found' ]) unless $p;
- my $comment = $p->comments->search( { external_id => $request->{update_id} } )->first;
- $c->detach('bad_request', [ 'already exists' ]) if $comment;
+ $c->forward('check_existing', [ $p, $request, $updates ]);
- $comment = $updates->process_update($request, $p);
+ my $comment = $updates->process_update($request, $p);
my $data = { service_request_updates => { update_id => $comment->id } };
$c->forward('/open311/format_output', [ $data ]);
}
+sub check_existing : Private {
+ my ($self, $c, $p, $request, $updates) = @_;
+
+ my $comment = $p->comments->search( { external_id => $request->{update_id} } )->first;
+ $c->detach('bad_request', [ 'already exists' ]) if $comment;
+}
+
sub bad_request : Private {
my ($self, $c, $comment) = @_;
$c->response->status(400);