aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Bodies.pm5
-rw-r--r--perllib/Open311/PopulateServiceList.pm5
-rw-r--r--t/app/controller/admin/bodies.t11
-rw-r--r--t/open311/populate-service-list.t46
-rw-r--r--templates/web/base/admin/bodies/contact-form.html7
6 files changed, 73 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 71fef3855..6f99559ee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@
- Add fetch script that does combined job of fetch-comments and fetch-reports.
- Open311 improvements:
- match response templates on external status code over state
+ - Add flag to protect category/group names from Open311 overwrite.
- UK:
- Added junction lookup, so you can search for things like "M60, Junction 2"
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
index 4bfca21ae..6ae068cd9 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
@@ -272,6 +272,11 @@ sub update_contact : Private {
} else {
$contact->unset_extra_metadata( 'photo_required' );
}
+ if ( $c->get_param('open311_protect') ) {
+ $contact->set_extra_metadata( open311_protect => 1 );
+ } else {
+ $contact->unset_extra_metadata( 'open311_protect' );
+ }
if ( my @group = $c->get_param_list('group') ) {
@group = grep { $_ } @group;
if (scalar @group == 0) {
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index eb1d76da4..9be17946e 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -143,6 +143,7 @@ sub _handle_existing_contact {
my ( $self, $contact ) = @_;
my $service_name = $self->_normalize_service_name;
+ my $protected = $contact->get_extra_metadata("open311_protect");
print $self->_current_body->id . " already has a contact for service code " . $self->_current_service->{service_code} . "\n" if $self->verbose >= 2;
@@ -150,7 +151,7 @@ sub _handle_existing_contact {
eval {
$contact->update(
{
- category => $service_name,
+ $protected ? () : (category => $service_name),
email => $self->_current_service->{service_code},
state => 'confirmed',
%{ $self->_action_params("undeleted") },
@@ -178,7 +179,7 @@ sub _handle_existing_contact {
$contact->update;
}
- $self->_set_contact_group($contact);
+ $self->_set_contact_group($contact) unless $protected;
$self->_set_contact_non_public($contact);
push @{ $self->found_contacts }, $self->_current_service->{service_code};
diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t
index 340351473..c73a90da1 100644
--- a/t/app/controller/admin/bodies.t
+++ b/t/app/controller/admin/bodies.t
@@ -250,6 +250,17 @@ subtest 'disable form message editing' => sub {
}], 'right message added';
};
+subtest 'open311 protection editing' => sub {
+ $mech->get_ok('/admin/body/' . $body->id . '/test%20category');
+ $mech->submit_form_ok( { with_fields => {
+ open311_protect => 1,
+ note => 'Protected from Open311 changes',
+ } } );
+ $mech->content_contains('Values updated');
+ my $contact = $body->contacts->find({ category => 'test category' });
+ is $contact->get_extra_metadata('open311_protect'), 1, 'Open311 protect flag set';
+};
+
}; # END of override wrap
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index 59f8b7b65..bd837f203 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -349,6 +349,52 @@ subtest 'check new category marked non_public' => sub {
is $contact->non_public, 1, 'contact marked as non_public';
};
+subtest 'check protected categories do not have name/group overwritten' => sub {
+ my $contact = FixMyStreet::DB->resultset('Contact')->search( { body_id => $body->id } )->first;
+ $contact->set_extra_metadata('open311_protect', 1);
+ $contact->set_extra_metadata('group', [ 'sanitation' ]);
+ $contact->non_public(0);
+ $contact->update;
+
+ my $services_xml = '<?xml version="1.0" encoding="utf-8"?>
+ <services>
+ <service>
+ <service_code>100</service_code>
+ <service_name>Cans left out constantly</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>cleansing</group>
+ </service>
+ </services>
+ ';
+
+ my $service_list = get_xml_simple_object( $services_xml );
+
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'tester' ],
+ COBRAND_FEATURES => {
+ category_groups => { tester => 1 },
+ }
+ }, sub {
+ 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 unchanged';
+ is_deeply $contact->groups, ['sanitation'], 'group unchanged';
+ # test that something did change
+ 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({
diff --git a/templates/web/base/admin/bodies/contact-form.html b/templates/web/base/admin/bodies/contact-form.html
index b698fcea2..35fab4541 100644
--- a/templates/web/base/admin/bodies/contact-form.html
+++ b/templates/web/base/admin/bodies/contact-form.html
@@ -63,6 +63,13 @@
<textarea id="disabled-message" name="disable_message" class="form-control">[% contact.disable_form_field.description %]</textarea>
</p>
+ [% IF body.send_method == 'Open311' %]
+ <p class="form-check">
+ <input type="checkbox" name="open311_protect" value="1" id="open311_protect"[% ' checked' IF contact.get_extra_metadata('open311_protect') %]>
+ <label for="open311_protect">[% loc("Protect this category's name and group(s) from Open311 changes") %]</label>
+ </p>
+ [% END %]
+
[% IF body.can_be_devolved %]
<div class="admin-hint">
<p>