aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2020-10-23 14:28:38 +0100
committerStruan Donald <struan@exo.org.uk>2020-10-28 09:56:07 +0000
commitcfda101b3006f12280a41adc4b28ca555b867556 (patch)
treef7f09eeec2cb31c8db33b9d0d819ebd9b84fea54 /perllib
parentc5f80e9cd8a896ff469acfa9a90f69a5a7b5243e (diff)
prevent editing of category names with hardcoded flag
If a category has hardcoded set to 1 in it's extra metadata then prevent the name being edited in the admin. This is to avoid issues where the name of the category is used in e.g. layers or other configuration and changing it breaks things. Also includes admin interface for setting this that is restricted to super users only. Fixes mysociety/fixmystreet-commercial#1992
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Bodies.pm7
-rw-r--r--perllib/FixMyStreet/DB/Result/Contact.pm4
2 files changed, 11 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
index f1a6f938b..31a717a9c 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
@@ -283,6 +283,13 @@ sub update_contact : Private {
$contact->unset_extra_metadata($_);
}
}
+ if ( $c->user->is_superuser ) {
+ if ( $c->get_param('hardcoded') ) {
+ $contact->set_extra_metadata( hardcoded => 1 );
+ } else {
+ $contact->unset_extra_metadata('hardcoded');
+ }
+ }
if ( my @group = $c->get_param_list('group') ) {
@group = grep { $_ } @group;
if (scalar @group == 0) {
diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm
index 5cf3302dd..69f8886eb 100644
--- a/perllib/FixMyStreet/DB/Result/Contact.pm
+++ b/perllib/FixMyStreet/DB/Result/Contact.pm
@@ -191,12 +191,16 @@ sub sent_by_open311 {
# We do not want to allow editing of a category's name
# if it's Open311, unless it's marked as protected
+# Also prevent editing of hardcoded categories
sub category_uneditable {
my $self = shift;
return 1 if
$self->in_storage
&& !$self->get_extra_metadata('open311_protect')
&& $self->sent_by_open311;
+ return 1 if
+ $self->in_storage
+ && $self->get_extra_metadata('hardcoded');
return 0;
}