diff options
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | perllib/Open311/PopulateServiceList.pm | 17 | ||||
-rw-r--r-- | t/open311/populate-service-list.t | 101 |
3 files changed, 121 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 48d866c13..79c50ecfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ - Development improvements: - Upgrade the underlying framework and a number of other packages. - Add feature cobrand helper function. + - Open311 improvements: + - Support use of 'private' service definition <keywords> to mark + reports made in that category private. * v2.6 (3rd May 2019) - New features: 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; diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t index ff4c4cf9d..c67fae9bd 100644 --- a/t/open311/populate-service-list.t +++ b/t/open311/populate-service-list.t @@ -225,6 +225,107 @@ subtest 'check conflicting contacts not changed' => sub { is $contact_count, 4, 'correct number of contacts'; }; +subtest 'check new category marked non_public' => sub { + FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete(); + + my $services_xml = '<?xml version="1.0" encoding="utf-8"?> + <services> + <service> + <service_code>100</service_code> + <service_name>Cans left out 24x7</service_name> + <description>Garbage or recycling cans that have been left out for more than 24 hours after collection. Violators will be cited.</description> + <metadata>false</metadata> + <type>realtime</type> + <keywords>private</keywords> + <group>sanitation</group> + </service> + </services> + '; + + my $service_list = get_xml_simple_object( $services_xml ); + + my $processor = Open311::PopulateServiceList->new(); + $processor->_current_body( $body ); + $processor->process_services( $service_list ); + + my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->count(); + is $contact_count, 1, 'correct number of contacts'; + + my $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->first; + is $contact->email, '100', 'email correct'; + is $contact->category, 'Cans left out 24x7', 'category correct'; + is $contact->non_public, 1, 'contact marked as non_public'; +}; + +subtest 'check existing category marked non_public' => sub { + my $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->first; + $contact->update({ + non_public => 0 + }); + is $contact->non_public, 0, 'contact not marked as non_public'; + + my $services_xml = '<?xml version="1.0" encoding="utf-8"?> + <services> + <service> + <service_code>100</service_code> + <service_name>Cans left out 24x7</service_name> + <description>Garbage or recycling cans that have been left out for more than 24 hours after collection. Violators will be cited.</description> + <metadata>false</metadata> + <type>realtime</type> + <keywords>private</keywords> + <group>sanitation</group> + </service> + </services> + '; + + my $service_list = get_xml_simple_object( $services_xml ); + + my $processor = Open311::PopulateServiceList->new(); + $processor->_current_body( $body ); + $processor->process_services( $service_list ); + + my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->count(); + is $contact_count, 1, 'correct number of contacts'; + + $contact->discard_changes; + is $contact->email, '100', 'email correct'; + is $contact->category, 'Cans left out 24x7', 'category correct'; + is $contact->non_public, 1, 'contact changed to non_public'; +}; + +subtest 'check existing non_public category does not get marked public' => sub { + my $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->first; + is $contact->non_public, 1, 'contact marked as non_public'; + + my $services_xml = '<?xml version="1.0" encoding="utf-8"?> + <services> + <service> + <service_code>100</service_code> + <service_name>Cans left out 24x7</service_name> + <description>Garbage or recycling cans that have been left out for more than 24 hours after collection. Violators will be cited.</description> + <metadata>false</metadata> + <type>realtime</type> + <keywords></keywords> + <group>sanitation</group> + </service> + </services> + '; + + my $service_list = get_xml_simple_object( $services_xml ); + + my $processor = Open311::PopulateServiceList->new(); + $processor->_current_body( $body ); + $processor->process_services( $service_list ); + + my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->count(); + is $contact_count, 1, 'correct number of contacts'; + + $contact->discard_changes; + is $contact->email, '100', 'email correct'; + is $contact->category, 'Cans left out 24x7', 'category correct'; + is $contact->non_public, 1, 'contact remains non_public'; +}; + for my $test ( { desc => 'check meta data added to existing contact', |