aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2018-05-15 14:10:43 +0100
committerDave Arter <davea@mysociety.org>2018-06-26 14:44:23 +0100
commitae0381e4e74f82cf55181f07528558e7df37443e (patch)
treed449442c45f79a3b0e5a01db9fb47d615ae09f6d
parent7c009ce048fbe36db24dd1a24f3542503db2e898 (diff)
Enable editing of category group in admin
Fixes mysociety/fixmystreetforcouncils#275
-rw-r--r--CHANGELOG.md2
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm6
-rw-r--r--t/app/controller/admin/bodies.t53
-rw-r--r--templates/web/base/admin/contact-form.html18
4 files changed, 78 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a6bf42122..e5e142212 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,8 @@
- Simplify footer CSS. #2107
- Keep commas in geocode lookups.
- Show message on reports closed to updates.
+ - Admin improvements:
+ - Category group can be edited.
- Bugfixes:
- Don't remove automated fields when editing contacts #2163
- Remove small border to left of Fixed banner. #2156
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index dfea6f8d4..35f619c11 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -356,6 +356,12 @@ sub update_contacts : Private {
if ( $c->get_param('reputation_threshold') ) {
$contact->set_extra_metadata( reputation_threshold => int($c->get_param('reputation_threshold')) );
}
+ if ( my $group = $c->get_param('group') ) {
+ $contact->set_extra_metadata( group => $group );
+ } else {
+ $contact->unset_extra_metadata( 'group' );
+ }
+
$c->forward('update_extra_fields', [ $contact ]);
$c->forward('contact_cobrand_extra_fields', [ $contact ]);
diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t
index a485d286d..f67e45bf6 100644
--- a/t/app/controller/admin/bodies.t
+++ b/t/app/controller/admin/bodies.t
@@ -1,9 +1,17 @@
+package FixMyStreet::Cobrand::Tester;
+
+use parent 'FixMyStreet::Cobrand::Default';
+
+sub enable_category_groups { 1 }
+
+package main;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1);
$mech->log_in_ok( $superuser->email );
+my $body = $mech->create_body_ok(2650, 'Aberdeen City Council');
# This override is wrapped around ALL the /admin/body tests
FixMyStreet::override_config {
@@ -12,7 +20,6 @@ FixMyStreet::override_config {
BASE_URL => 'http://www.example.org',
}, sub {
-my $body = $mech->create_body_ok(2650, 'Aberdeen City Council');
$mech->get_ok('/admin/body/' . $body->id);
$mech->content_contains('Aberdeen City Council');
$mech->content_like(qr{AB\d\d});
@@ -56,6 +63,7 @@ subtest 'check contact creation' => sub {
subtest 'check contact editing' => sub {
$mech->get_ok('/admin/body/' . $body->id .'/test%20category');
+ $mech->content_lacks( 'group</strong> is used for the top-level category' );
$mech->submit_form_ok( { with_fields => {
email => 'test2@example.com',
@@ -201,4 +209,47 @@ subtest 'check text output' => sub {
}; # END of override wrap
+FixMyStreet::override_config {
+ ALLOWED_COBRANDS => ['tester'],
+ MAPIT_URL => 'http://mapit.uk/',
+ MAPIT_TYPES => [ 'UTA' ],
+ BASE_URL => 'http://www.example.org',
+}, sub {
+ subtest 'group editing works' => sub {
+ $mech->get_ok('/admin/body/' . $body->id);
+ $mech->content_contains( 'group</strong> is used for the top-level category' );
+
+ $mech->submit_form_ok( { with_fields => {
+ category => 'grouped category',
+ email => 'test@example.com',
+ note => 'test note',
+ group => 'group a',
+ non_public => undef,
+ state => 'unconfirmed',
+ } } );
+
+ my $contact = $body->contacts->find({ category => 'grouped category' });
+ is $contact->get_extra_metadata('group'), 'group a', "group stored correctly";
+ };
+
+ subtest 'group can be unset' => sub {
+ $mech->get_ok('/admin/body/' . $body->id);
+ $mech->content_contains( 'group</strong> is used for the top-level category' );
+
+ $mech->submit_form_ok( { with_fields => {
+ category => 'grouped category',
+ email => 'test@example.com',
+ note => 'test note',
+ group => undef,
+ non_public => undef,
+ state => 'unconfirmed',
+ } } );
+
+ my $contact = $body->contacts->find({ category => 'grouped category' });
+ is $contact->get_extra_metadata('group'), undef, "group unset correctly";
+ };
+
+};
+
+
done_testing();
diff --git a/templates/web/base/admin/contact-form.html b/templates/web/base/admin/contact-form.html
index b34ca3377..7e2830e9c 100644
--- a/templates/web/base/admin/contact-form.html
+++ b/templates/web/base/admin/contact-form.html
@@ -120,6 +120,24 @@ as well.") %]
[% INCLUDE 'admin/open311-form-fields.html', object = contact%]
[% END %]
+ [% IF c.cobrand.enable_category_groups %]
+ <div class="admin-hint">
+ <p>
+ [% loc(
+ "The <strong>group</strong> is used for the top-level category field when
+ subcategory grouping is enabled."
+ ) %]
+ </p>
+ </div>
+ <p>
+ <label>
+ [% loc('Group') %]
+ <input class="form-control" type="text" name="group" value="[% contact.extra.group | html %]" size="30">
+ </label>
+ </p>
+ [% END %]
+
+
<div class="admin-hint">
<p>
[% loc("Use this field to record details that are only displayed in the admin. Input is not shown publicly, and is not sent to the body.") %]