diff options
author | Matthew Somerville <matthew@mysociety.org> | 2020-06-03 15:31:15 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2020-06-04 11:22:41 +0100 |
commit | 1c8f7efec8e04919ad43c63ce9bcf148ee72a2cc (patch) | |
tree | f1ae812c0b63e699db310c10e704833e96c26d53 | |
parent | f8859e29f5bcf75c1b2acb934bd4353f83c5a2c1 (diff) |
[Open311] Do not remove any devolved contacts.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/Open311/PopulateServiceList.pm | 6 | ||||
-rw-r--r-- | t/open311/populate-service-list.t | 64 |
3 files changed, 46 insertions, 25 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a2466913..d9fe1e282 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix issue with dashboard report CSV export. #3026 - bin/update-schema PostgreSQL 12 compatibility. #3043 - Make sure category shown in all its groups when reporting. + - Do not remove any devolved contacts. - Admin improvements: - Display user name/email for contributed as reports. #2990 - Interface for enabling anonymous reports for certain categories. #2989 diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm index 9be17946e..20fca90b3 100644 --- a/perllib/Open311/PopulateServiceList.pm +++ b/perllib/Open311/PopulateServiceList.pm @@ -350,10 +350,10 @@ sub _delete_contacts_not_in_service_list { ); if ($self->_current_body->can_be_devolved) { - # If the body has can_be_devolved switched on, it's most likely a - # combination of Open311/email, so ignore any email addresses. + # If the body has can_be_devolved switched on, ignore any + # contact with its own send method $found_contacts = $found_contacts->search( - { email => { -not_like => '%@%' } } + { send_method => [ "", undef ] }, ); } diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t index bd837f203..20f092da4 100644 --- a/t/open311/populate-service-list.t +++ b/t/open311/populate-service-list.t @@ -175,33 +175,53 @@ subtest "set multiple groups with groups element" => sub { is_deeply $contact->get_extra->{group}, ['sanitation & cleaning','street'], "groups set correctly"; }; -subtest 'check non open311 contacts marked as deleted' => sub { - FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete(); +$body->update({ can_be_devolved => 1 }); +for my $test ( + { + test => 'check non open311 contacts marked as deleted', + contact_params => { + email => 'contact@example.com', + }, + deleted => 1, + }, + { + test => 'check devolved non open311 contacts not marked as deleted', + contact_params => { + email => 'contact', + send_method => 'Open311', + }, + deleted => 0, + }, +) { + subtest $test->{test} => sub { + FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete(); - my $contact = FixMyStreet::DB->resultset('Contact')->create( - { - body_id => $body->id, - email => 'contact@example.com', - category => 'An old category', - state => 'confirmed', - editor => $0, - whenedited => \'current_timestamp', - note => 'test contact', - } - ); + my $contact = FixMyStreet::DB->resultset('Contact')->create( + { + body_id => $body->id, + category => 'An old category', + state => 'confirmed', + editor => $0, + whenedited => \'current_timestamp', + note => 'test contact', + %{$test->{contact_params}}, + } + ); - my $service_list = get_xml_simple_object( get_standard_xml() ); + my $service_list = get_xml_simple_object( get_standard_xml() ); - my $processor = Open311::PopulateServiceList->new(); - $processor->_current_body( $body ); - $processor->process_services( $service_list ); + 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, 4, 'correct number of contacts'; + my $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->count(); + is $contact_count, 4, 'correct number of contacts'; - $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id, state => 'deleted' } )->count(); - is $contact_count, 1, 'correct number of deleted contacts'; -}; + $contact_count = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id, state => 'deleted' } )->count(); + is $contact_count, $test->{deleted}, 'correct number of deleted contacts'; + }; +} +$body->update({ can_be_devolved => 0 }); subtest 'check email changed if matching category' => sub { FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->delete(); |