diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Bodies.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Contact.pm | 21 |
2 files changed, 28 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm index 07d058872..7b060f2ca 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm @@ -241,10 +241,14 @@ sub update_contact : Private { 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); + # Set the flag here so we can run the editable test on it + $contact->set_extra_metadata(open311_protect => $c->get_param('open311_protect')); + if (!$contact->category_uneditable) { + # Changed name + $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'); diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index affc6d480..2941683d1 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -175,4 +175,25 @@ sub disable_form_field { return $field; } +sub sent_by_open311 { + my $self = shift; + my $body = $self->body; + return 1 if + (!$body->can_be_devolved && $body->send_method eq 'Open311') + || ($body->can_be_devolved && $body->send_method eq 'Open311' && !$self->send_method) + || ($body->can_be_devolved && $self->send_method eq 'Open311'); + return 0; +} + +# We do not want to allow editing of a category's name +# if it's Open311, unless it's marked as protected +sub category_uneditable { + my $self = shift; + return 1 if + $self->in_storage + && !$self->get_extra_metadata('open311_protect') + && $self->sent_by_open311; + return 0; +} + 1; |