aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Admin.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2019-05-03 13:31:57 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2019-05-07 15:01:07 +0100
commit0236d3a37da94e06e9e6208f50f6c0b9388feb7c (patch)
tree53a206661f0b46303faaa3cf1e77c748f59b1621 /perllib/FixMyStreet/App/Controller/Admin.pm
parentb8fd2a09332798214188cbedecb85294645c06dc (diff)
Prevent creation of two templates with same title.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm9
1 files changed, 9 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 2f4669456..05ac48c8c 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -782,6 +782,15 @@ sub template_edit : Path('templates') : Args(2) {
}
$template->title( $c->get_param('title') );
+ my $query = { title => $template->title };
+ if ($template->in_storage) {
+ $query->{id} = { '!=', $template->id };
+ }
+ if ($c->stash->{body}->response_templates->search($query)->count) {
+ $c->stash->{errors} ||= {};
+ $c->stash->{errors}->{title} = _("There is already a template with that title.");
+ }
+
$template->text( $c->get_param('text') );
$template->state( $c->get_param('state') );
$template->external_status_code( $c->get_param('external_status_code') );