From 0236d3a37da94e06e9e6208f50f6c0b9388feb7c Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 May 2019 13:31:57 +0100 Subject: Prevent creation of two templates with same title. --- perllib/FixMyStreet/App/Controller/Admin.pm | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Admin.pm') 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') ); -- cgit v1.2.3