aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm2
-rw-r--r--perllib/Open311/PopulateServiceList.pm24
2 files changed, 23 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 3cd6bfd70..45ac1534d 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -1190,6 +1190,8 @@ sub update_extra_fields : Private {
$meta->{required} = $required ? 'true' : 'false';
my $notice = $c->get_param("metadata[$i].notice") && $c->get_param("metadata[$i].notice") eq 'on';
$meta->{variable} = $notice ? 'false' : 'true';
+ my $protected = $c->get_param("metadata[$i].protected") && $c->get_param("metadata[$i].protected") eq 'on';
+ $meta->{protected} = $protected ? 'true' : 'false';
$meta->{description} = $c->get_param("metadata[$i].description");
$meta->{datatype_description} = $c->get_param("metadata[$i].datatype_description");
$meta->{automated} = $c->get_param("metadata[$i].automated")
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index 5f7ca10a3..f6e8c8668 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -161,7 +161,12 @@ sub _handle_existing_contact {
if ( $contact and lc($metadata) eq 'true' ) {
$self->_add_meta_to_contact( $contact );
} elsif ( $contact and $contact->extra and lc($metadata) eq 'false' ) {
- $contact->set_extra_fields();
+ # check if there are any protected fields that we should not delete
+ my @meta = (
+ grep { $_->{protected} }
+ @{ $contact->get_extra_fields }
+ );
+ $contact->set_extra_fields(@meta);
$contact->update;
}
@@ -226,13 +231,26 @@ sub _add_meta_to_contact {
return;
}
- # turn the data into something a bit more friendly to use
+ # check if there are any protected fields that we should not overwrite
+ my $protected = {
+ map { $_->{code} => $_ }
+ grep { $_->{protected} }
+ @{ $contact->get_extra_fields }
+ };
my @meta =
+ map { $protected->{$_->{code}} ? delete $protected->{$_->{code}} : $_ }
+ @{ $meta_data->{attributes} };
+
+ # and then add back in any protected fields that we don't fetch
+ push @meta, values %$protected;
+
+ # turn the data into something a bit more friendly to use
+ @meta =
# remove trailing colon as we add this when we display so we don't want 2
map { $_->{description} =~ s/:\s*$//; $_ }
# there is a display order and we only want to sort once
sort { $a->{order} <=> $b->{order} }
- @{ $meta_data->{attributes} };
+ @meta;
# Some Open311 endpoints, such as Bromley and Warwickshire send <metadata>
# for attributes which we *don't* want to display to the user (e.g. as