aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Open311/PopulateServiceList.pm
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2019-04-12 15:52:52 +0100
committerDave Arter <davea@mysociety.org>2019-06-04 14:53:59 +0100
commit84d49bae300280f6169b9543657f8cfa8861643b (patch)
tree09aae11609e40c65b0cfcc41164d319e21e96f06 /perllib/Open311/PopulateServiceList.pm
parent500d4fe948bae1ee5a2d4dab8820c1d0ea9424c2 (diff)
Mark Open311 contacts non_public according to service keywords
This allows the Open311 endpoint to include ‘private’ in the ‘keywords’ field of a service definition in order for it to be marked as non_public on FMS. NB existing categories may be updated to become non_public, but non_public categories will never have their non_public flag unset by PopulateServiceList. This is so any existing Open311 categories on FMS don’t suddenly become public.
Diffstat (limited to 'perllib/Open311/PopulateServiceList.pm')
-rw-r--r--perllib/Open311/PopulateServiceList.pm17
1 files changed, 17 insertions, 0 deletions
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index ad7288c62..2da67e9cd 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -165,6 +165,7 @@ sub _handle_existing_contact {
}
$self->_set_contact_group($contact);
+ $self->_set_contact_non_public($contact);
push @{ $self->found_contacts }, $self->_current_service->{service_code};
}
@@ -201,6 +202,7 @@ sub _create_contact {
}
$self->_set_contact_group($contact);
+ $self->_set_contact_non_public($contact);
if ( $contact ) {
push @{ $self->found_contacts }, $self->_current_service->{service_code};
@@ -283,6 +285,21 @@ sub _set_contact_group {
}
}
+sub _set_contact_non_public {
+ my ($self, $contact) = @_;
+
+ # We never want to make a private category unprivate.
+ return if $contact->non_public;
+
+ my %keywords = map { $_ => 1 } split /,/, ( $self->_current_service->{keywords} || '' );
+ $contact->update({
+ non_public => 1,
+ editor => $0,
+ whenedited => \'current_timestamp',
+ note => 'marked private automatically by script',
+ }) if $keywords{private};
+}
+
sub _delete_contacts_not_in_service_list {
my $self = shift;