diff options
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 6 | ||||
-rw-r--r-- | t/app/controller/admin/bodies.t | 53 | ||||
-rw-r--r-- | templates/web/base/admin/contact-form.html | 18 |
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.") %] |