aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm23
-rw-r--r--t/app/controller/admin/bodies.t39
-rw-r--r--templates/web/base/admin/open311-form-fields.html14
3 files changed, 71 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 6f7214906..33404cb82 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -218,9 +218,14 @@ sub bodies : Path('bodies') : Args(0) {
$c->forward('check_for_super_user');
$c->forward('/auth/check_csrf_token');
- my $params = $c->forward('body_params');
+ my $values = $c->forward('body_params');
unless ( keys %{$c->stash->{body_errors}} ) {
- my $body = $c->model('DB::Body')->create( $params );
+ my $body = $c->model('DB::Body')->create( $values->{params} );
+ if ($values->{extras}) {
+ $body->set_extra_metadata( $_ => $values->{extras}->{$_} )
+ for keys %{$values->{extras}};
+ $body->update;
+ }
my @area_ids = $c->get_param_list('area_ids');
foreach (@area_ids) {
$c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } );
@@ -396,9 +401,14 @@ sub update_contacts : Private {
$c->forward('check_for_super_user');
$c->forward('/auth/check_csrf_token');
- my $params = $c->forward( 'body_params' );
+ my $values = $c->forward( 'body_params' );
unless ( keys %{$c->stash->{body_errors}} ) {
- $c->stash->{body}->update( $params );
+ $c->stash->{body}->update( $values->{params} );
+ if ($values->{extras}) {
+ $c->stash->{body}->set_extra_metadata( $_ => $values->{extras}->{$_} )
+ for keys %{$values->{extras}};
+ $c->stash->{body}->update;
+ }
my @current = $c->stash->{body}->body_areas->all;
my %current = map { $_->area_id => 1 } @current;
my @area_ids = $c->get_param_list('area_ids');
@@ -465,7 +475,10 @@ sub body_params : Private {
);
my %params = map { $_ => $c->get_param($_) || $defaults{$_} } keys %defaults;
$c->forward('check_body_params', [ \%params ]);
- return \%params;
+ my @extras = qw/fetch_all_problems/;
+ %defaults = map { $_ => '' } @extras;
+ my %extras = map { $_ => $c->get_param($_) || $defaults{$_} } @extras;
+ return { params => \%params, extras => \%extras };
}
sub check_body_params : Private {
diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t
index 9bdf8fb9a..a485d286d 100644
--- a/t/app/controller/admin/bodies.t
+++ b/t/app/controller/admin/bodies.t
@@ -150,6 +150,45 @@ subtest 'check open311 configuring' => sub {
is $conf->endpoint, 'http://example.org/open311', 'endpoint updated';
is $conf->api_key, 'new api key', 'api key updated';
is $conf->jurisdiction, 'open311', 'jurisdiction configures';
+ ok !$conf->get_extra_metadata('fetch_all_problems'), 'fetch all problems unset';
+
+ $mech->form_number(3);
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ api_key => 'new api key',
+ endpoint => 'http://example.org/open311',
+ jurisdiction => 'open311',
+ send_comments => 0,
+ send_method => 'Open311',
+ fetch_all_problems => 1,
+ }
+ }
+ );
+
+ $mech->content_contains('Values updated');
+
+ $conf = FixMyStreet::App->model('DB::Body')->find( $body->id );
+ ok $conf->get_extra_metadata('fetch_all_problems'), 'fetch all problems set';
+
+ $mech->form_number(3);
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ api_key => 'new api key',
+ endpoint => 'http://example.org/open311',
+ jurisdiction => 'open311',
+ send_comments => 0,
+ send_method => 'Open311',
+ fetch_all_problems => 0,
+ }
+ }
+ );
+
+ $mech->content_contains('Values updated');
+
+ $conf = FixMyStreet::App->model('DB::Body')->find( $body->id );
+ ok !$conf->get_extra_metadata('fetch_all_problems'), 'fetch all problems unset';
};
subtest 'check text output' => sub {
diff --git a/templates/web/base/admin/open311-form-fields.html b/templates/web/base/admin/open311-form-fields.html
index 50436fc79..b716cf175 100644
--- a/templates/web/base/admin/open311-form-fields.html
+++ b/templates/web/base/admin/open311-form-fields.html
@@ -150,6 +150,20 @@
<input type="checkbox" id="convert_latlong" name="convert_latlong"[% ' checked' IF object.convert_latlong %]>
<label for="convert_latlong" class="inline">[% loc('Convert location from Easting/Northing') %]</label>
</p>
+
+ <div class="admin-hint">
+ <p>
+ [% loc(
+ "Enable <strong>Always fetch all problems</strong> if you've enabled Open311 problem-fetching above
+ and the endpoint always returns a list of all problems. This will suppress error messages about
+ bad dates in the problems fetched."
+ ) %]
+ </p>
+ </div>
+ <p>
+ <input type="checkbox" id="fetch_all_problems" name="fetch_all_problems"[% ' checked' IF object.get_extra_metadata('fetch_all_problems') %]>
+ <label for="fetch_all_problems" class="inline">[% loc('Always fetch all problems') %]</label>
+ </p>
</div>
[% END %]
</div>