aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/UK.pm3
-rw-r--r--perllib/Open311/PopulateServiceList.pm2
-rw-r--r--t/open311/populate-service-list.t90
-rw-r--r--templates/web/base/report/new/category_extras_fields.html2
7 files changed, 100 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9fabf394e..1de079800 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@
- New features
- Fetch problems over Open311 #1986
- Option to send multiple photos over Open311 #1986
+ - Allow Open311 service definitions to include automated
+ attributes #1986
- Front end improvements:
- Improve questionnaire process. #1939 #1998
- Increase size of "sub map links" (hide pins, permalink, etc) #2003
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index f7334c115..e4e82f091 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -1003,7 +1003,7 @@ sub set_report_extras : Private {
foreach my $contact (@$contacts) {
my $metas = $contact->get_metadata_for_input;
foreach my $field ( @$metas ) {
- if ( lc( $field->{required} ) eq 'true' && !$c->cobrand->category_extra_hidden($field->{code})) {
+ if ( lc( $field->{required} ) eq 'true' && !$c->cobrand->category_extra_hidden($field)) {
unless ( $c->get_param($param_prefix . $field->{code}) ) {
$c->stash->{field_errors}->{ $field->{code} } = _('This information is required');
}
@@ -1020,7 +1020,7 @@ sub set_report_extras : Private {
my $metas = $extra_fields->get_extra_fields;
$param_prefix = "extra[" . $extra_fields->id . "]";
foreach my $field ( @$metas ) {
- if ( lc( $field->{required} ) eq 'true' && !$c->cobrand->category_extra_hidden($field->{code})) {
+ if ( lc( $field->{required} ) eq 'true' && !$c->cobrand->category_extra_hidden($field)) {
unless ( $c->get_param($param_prefix . $field->{code}) ) {
$c->stash->{field_errors}->{ $field->{code} } = _('This information is required');
}
diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 03a6c1a83..8c4d8be53 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -1178,7 +1178,7 @@ Return true if an Open311 service attribute should be a hidden field.
sub category_extra_hidden {
my ($self, $meta) = @_;
- return 0;
+ return 0;
}
=item reputation_increment_states/reputation_decrement_states
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm
index e1f5e565f..0ecb6a7c6 100644
--- a/perllib/FixMyStreet/Cobrand/UK.pm
+++ b/perllib/FixMyStreet/Cobrand/UK.pm
@@ -396,7 +396,8 @@ sub lookup_by_ref_regex {
sub category_extra_hidden {
my ($self, $meta) = @_;
- return 1 if $meta eq 'usrn' || $meta eq 'asset_id';
+ return 1 if $meta->{code} eq 'usrn' || $meta->{code} eq 'asset_id';
+ return 1 if $meta->{automated} eq 'hidden_field';
return 0;
}
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index 30d888eb4..af89e3169 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -267,6 +267,8 @@ sub _add_meta_to_contact {
@meta = grep { ! $ignore{ $_->{ code } } } @meta;
}
+ @meta = grep { !defined $_->{automated} || $_->{ automated } eq 'hidden_field' } @meta;
+
$contact->set_extra_fields(@meta);
$contact->update;
}
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 7d4f491c6..149fb4b2a 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -646,6 +646,96 @@ subtest 'check bromely skip code' => sub {
is_deeply $contact->get_extra_fields, $extra, 'all meta data saved for non bromley';
};
+subtest 'check automated meta skip code' => sub {
+ my $processor = Open311::PopulateServiceList->new();
+
+ my $meta_xml = '<?xml version="1.0" encoding="utf-8"?>
+<service_definition>
+ <service_code>100</service_code>
+ <attributes>
+ <attribute>
+ <variable>true</variable>
+ <code>type</code>
+ <datatype>string</datatype>
+ <required>true</required>
+ <datatype_description>Type of bin</datatype_description>
+ <order>1</order>
+ <description>Type of bin</description>
+ </attribute>
+ <attribute>
+ <automated>server_set</automated>
+ <variable>true</variable>
+ <code>title</code>
+ <datatype>string</datatype>
+ <required>true</required>
+ <datatype_description>Type of bin</datatype_description>
+ <order>1</order>
+ <description>Type of bin</description>
+ </attribute>
+ <attribute>
+ <automated>hidden_field</automated>
+ <variable>true</variable>
+ <code>asset_id</code>
+ <datatype>string</datatype>
+ <required>true</required>
+ <datatype_description>Id of bin</datatype_description>
+ <order>1</order>
+ <description>Id of bin</description>
+ </attribute>
+ </attributes>
+</service_definition>
+ ';
+
+ my $contact = FixMyStreet::DB->resultset('Contact')->find_or_create(
+ {
+ body_id => 1,
+ email => '001',
+ category => 'Bins left out 24x7',
+ state => 'confirmed',
+ editor => $0,
+ whenedited => \'current_timestamp',
+ note => 'test contact',
+ }
+ );
+
+ my $o = Open311->new(
+ jurisdiction => 'mysociety',
+ endpoint => 'http://example.com',
+ test_mode => 1,
+ test_get_returns => { 'services/100.xml' => $meta_xml }
+ );
+
+ $processor->_current_open311( $o );
+ $processor->_current_body( $body );
+ $processor->_current_service( { service_code => 100 } );
+
+ $processor->_add_meta_to_contact( $contact );
+
+ my $extra = [ {
+ variable => 'true',
+ code => 'type',
+ datatype => 'string',
+ required => 'true',
+ datatype_description => 'Type of bin',
+ order => 1,
+ description => 'Type of bin'
+ },
+ {
+ automated => 'hidden_field',
+ variable => 'true',
+ code => 'asset_id',
+ datatype => 'string',
+ required => 'true',
+ datatype_description => 'Id of bin',
+ order => 1,
+ description => 'Id of bin'
+ } ];
+
+ $contact->discard_changes;
+
+ is_deeply $contact->get_extra_fields, $extra, 'only hidden automated meta data saved';
+};
+
sub get_standard_xml {
return qq{<?xml version="1.0" encoding="utf-8"?>
<services>
diff --git a/templates/web/base/report/new/category_extras_fields.html b/templates/web/base/report/new/category_extras_fields.html
index 6ed6391c7..cf5cc37b4 100644
--- a/templates/web/base/report/new/category_extras_fields.html
+++ b/templates/web/base/report/new/category_extras_fields.html
@@ -1,7 +1,7 @@
[%- FOR meta IN metas %]
[%- meta_name = meta.code -%]
- [% IF c.cobrand.category_extra_hidden(meta_name) AND NOT show_hidden %]
+ [% IF c.cobrand.category_extra_hidden(meta) AND NOT show_hidden %]
<input type="hidden" value="[% report_meta.$meta_name.value | html %]" name="[% cat_prefix %][% meta_name %]" id="[% cat_prefix %]form_[% meta_name %]">