aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--perllib/Open311/PopulateServiceList.pm35
-rw-r--r--t/open311/populate-service-list.t10
3 files changed, 32 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6b1b5322..b2a4d15df 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,8 @@
- Clearer relocation options while you’re reporting a problem #2238
- Admin improvements:
- Allow moderation to potentially change category. #2320
+ - Open311 improvements:
+ - Fix bug in contact group handling. #2323
* v2.4.2 (6th November 2018)
- New features:
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index d3f30d60c..8101c609d 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -8,12 +8,13 @@ has found_contacts => ( is => 'rw', default => sub { [] } );
has verbose => ( is => 'ro', default => 0 );
has schema => ( is => 'ro', lazy => 1, default => sub { FixMyStreet::DB->schema->connect } );
-has _current_body => ( is => 'rw' );
+has _current_body => ( is => 'rw', trigger => sub {
+ my ($self, $body) = @_;
+ $self->_current_body_cobrand($body->get_cobrand_handler);
+} );
+has _current_body_cobrand => ( is => 'rw' );
has _current_open311 => ( is => 'rw' );
has _current_service => ( is => 'rw' );
-has _current_body_cobrand => ( is => 'ro', lazy => 1, default => sub {
- return shift->_current_body->get_cobrand_handler;
-} );
sub process_bodies {
my $self = shift;
@@ -309,14 +310,26 @@ sub _normalize_service_name {
sub _set_contact_group {
my ($self, $contact) = @_;
- if ($self->_current_body_cobrand && $self->_current_body_cobrand->call_hook('enable_category_groups')) {
- if (my $group = $self->_current_service->{group}) {
- $contact->set_extra_metadata(group => $group);
- $contact->update;
+ my $groups_enabled = $self->_current_body_cobrand && $self->_current_body_cobrand->call_hook('enable_category_groups');
+ my $old_group = $contact->get_extra_metadata('group') || '';
+ my $new_group = $groups_enabled ? $self->_current_service->{group} || '' : '';
+
+ if ($old_group ne $new_group) {
+ if ($new_group) {
+ $contact->set_extra_metadata(group => $new_group);
+ $contact->update({
+ editor => $0,
+ whenedited => \'current_timestamp',
+ note => 'group updated automatically by script',
+ });
+ } else {
+ $contact->unset_extra_metadata('group');
+ $contact->update({
+ editor => $0,
+ whenedited => \'current_timestamp',
+ note => 'group removed automatically by script',
+ });
}
- } else {
- $contact->unset_extra_metadata('group');
- $contact->update;
}
}
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 313d5c809..1415c7b2a 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -46,14 +46,16 @@ $bromley->body_areas->find_or_create({
} );
for my $test (
- { cobrand => 'tester', groups => 0 },
- { cobrand => 'testergroups', groups => 1 },
+ { desc => 'groups not set for new contacts', cobrand => 'tester', groups => 0, delete => 1 },
+ { desc => 'groups set for new contacts', cobrand => 'testergroups', groups => 1, delete => 1},
+ { desc => 'groups removed for existing contacts', cobrand => 'tester', groups => 0, delete => 0 },
+ { desc => 'groups added for existing contacts', cobrand => 'testergroups', groups => 1, delete => 0},
) {
FixMyStreet::override_config {
ALLOWED_COBRANDS => [ $test->{cobrand} ],
}, sub {
- subtest 'check basic functionality' => sub {
- FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->delete();
+ subtest 'check basic functionality, ' . $test->{desc} => sub {
+ FixMyStreet::DB->resultset('Contact')->search( { body_id => 1 } )->delete() if $test->{delete};
my $service_list = get_xml_simple_object( get_standard_xml() );