diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin/Bodies.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Bodies.pm | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm index 6ae068cd9..31a717a9c 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm @@ -151,8 +151,7 @@ sub category : Chained('body') : PathPart('') { my $history = $c->model('DB::ContactsHistory')->search( { - body_id => $c->stash->{body_id}, - category => $c->stash->{contact}->category + contact_id => $c->stash->{contact}->id, }, { order_by => ['contacts_history_id'] @@ -241,17 +240,27 @@ 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'); - $email =~ s/\s+//g; my $send_method = $c->get_param('send_method') || $contact->body->send_method || ""; + if ($send_method eq 'Open311') { + $email =~ s/^\s+|\s+$//g; + } else { + $email =~ s/\s+//g; + } my $email_unchanged = $contact->email && $email && $contact->email eq $email; - unless ( $send_method eq 'Open311' || $email_unchanged ) { + my $cobrand = $contact->body->get_cobrand_handler; + my $cobrand_valid = $cobrand && $cobrand->call_hook(validate_contact_email => $email); + unless ( $send_method eq 'Open311' || $email_unchanged || $cobrand_valid ) { $errors{email} = _('Please enter a valid email') unless is_valid_email_list($email) || $email eq 'REFUSED'; } @@ -267,15 +276,19 @@ sub update_contact : Private { $contact->send_method( $c->get_param('send_method') ); # Set flags in extra to the appropriate values - if ( $c->get_param('photo_required') ) { - $contact->set_extra_metadata_if_undefined( photo_required => 1 ); - } else { - $contact->unset_extra_metadata( 'photo_required' ); + foreach (qw(photo_required open311_protect updates_disallowed reopening_disallowed assigned_users_only anonymous_allowed)) { + if ( $c->get_param($_) ) { + $contact->set_extra_metadata( $_ => 1 ); + } else { + $contact->unset_extra_metadata($_); + } } - if ( $c->get_param('open311_protect') ) { - $contact->set_extra_metadata( open311_protect => 1 ); - } else { - $contact->unset_extra_metadata( 'open311_protect' ); + 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; |