aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Bodies.pm18
-rw-r--r--t/app/controller/admin/bodies.t17
-rw-r--r--templates/web/base/admin/bodies/contact-form.html8
4 files changed, 36 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 428c1a4cd..0deef93a5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@
- Contact form emails now include user admin links.
- Allow categories/Open311 questions to disable the reporting form. #2599
- Improve category edit form. #2469
+ - Allow editing of category name. #1398
- New features:
- Categories can be listed under more than one group #2475
- OpenID Connect login support. #2523
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
index f47ec7a2f..8556e8a27 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
@@ -138,7 +138,8 @@ sub category : Chained('body') : PathPart('') {
$c->forward( '/auth/get_csrf_token' );
my $contact = $c->stash->{body}->contacts->search( { category => $category } )->first;
- $c->stash->{contact} = $contact;
+ $c->detach( '/page_error_404_not_found', [] ) unless $contact;
+ $c->stash->{contact} = $c->stash->{current_contact} = $contact;
$c->stash->{translation_col} = 'category';
$c->stash->{object} = $c->stash->{contact};
@@ -218,6 +219,13 @@ sub update_contact : Private {
my %errors;
+ my $current_category = $c->get_param('current_category') || '';
+ my $current_contact = $c->model('DB::Contact')->find({
+ body_id => $c->stash->{body_id},
+ category => $current_category,
+ });
+ $c->stash->{current_contact} = $current_contact;
+
my $category = $self->trim( $c->get_param('category') );
$errors{category} = _("Please choose a category") unless $category;
$errors{note} = _('Please enter a message') unless $c->get_param('note') || FixMyStreet->config('STAGING_SITE');
@@ -228,6 +236,14 @@ sub update_contact : Private {
category => $category,
}
);
+ if ($current_contact && $contact->id && $contact->id != $current_contact->id) {
+ $errors{category} = _('You cannot rename a category to an existing category');
+ } elsif ($current_contact && !$contact->id) {
+ # Changed name
+ $contact = $current_contact;
+ $c->model('DB::Problem')->to_body($c->stash->{body_id})->search({ category => $current_category })->update({ category => $category });
+ $contact->category($category);
+ }
my $email = $c->get_param('email');
$email =~ s/\s+//g;
diff --git a/t/app/controller/admin/bodies.t b/t/app/controller/admin/bodies.t
index 75f0f606f..cd86e3da6 100644
--- a/t/app/controller/admin/bodies.t
+++ b/t/app/controller/admin/bodies.t
@@ -51,7 +51,7 @@ subtest 'check contact creation' => sub {
non_public => 'on',
} } );
$mech->get_ok('/admin/body/' . $body->id . '/test/category');
- $mech->content_contains('<h1>test/category</h1>');
+ $mech->content_contains('test/category');
};
subtest 'check contact editing' => sub {
@@ -91,6 +91,21 @@ subtest 'check contact editing' => sub {
$mech->content_contains( '<td><strong>test2@example.com' );
};
+subtest 'check contact renaming' => sub {
+ my ($report) = $mech->create_problems_for_body(1, $body->id, 'Title', { category => 'test category' });
+ $mech->get_ok('/admin/body/' . $body->id .'/test%20category');
+ $mech->submit_form_ok( { with_fields => { category => 'private category' } } );
+ $mech->content_contains('You cannot rename');
+ $mech->submit_form_ok( { with_fields => { category => 'testing category' } } );
+ $mech->content_contains( 'testing category' );
+ $mech->get('/admin/body/' . $body->id . '/test%20category');
+ is $mech->res->code, 404;
+ $mech->get_ok('/admin/body/' . $body->id . '/testing%20category');
+ $report->discard_changes;
+ is $report->category, 'testing category';
+ $mech->submit_form_ok( { with_fields => { category => 'test category' } } );
+};
+
subtest 'check contact updating' => sub {
$mech->get_ok('/admin/body/' . $body->id . '/test%20category');
$mech->content_like(qr{test2\@example.com</strong>[^<]*</td>[^<]*<td>unconfirmed}s);
diff --git a/templates/web/base/admin/bodies/contact-form.html b/templates/web/base/admin/bodies/contact-form.html
index 4a2323865..b28b74d92 100644
--- a/templates/web/base/admin/bodies/contact-form.html
+++ b/templates/web/base/admin/bodies/contact-form.html
@@ -1,11 +1,5 @@
<form method="post" action="[% c.uri_for_action('admin/bodies/edit', [ body_id ] ) %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8" id="category_edit">
- [% IF contact.in_storage %]
- <p>
- <h1>[% contact.category_display | html %]</h1>
- <input type="hidden" name="category" value="[% contact.category | html %]" >
- </p>
- [% ELSE %]
<div class="admin-hint">
<p>
[% loc('Choose a <strong>category</strong> name that makes sense to the public (e.g., "Pothole", "Street lighting") but is helpful
@@ -18,6 +12,8 @@
<p>
<strong>[% loc('Category') %] </strong><input type="text" class="form-control" name="category" size="30" value="[% contact.category | html %]" required>
</p>
+ [% IF contact.in_storage %]
+ <input type="hidden" name="current_category" value="[% current_contact.category | html %]" >
[% END %]
[% INCLUDE 'admin/bodies/_translations.html' %]