aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
committerMarius Halden <marius.h@lden.org>2021-10-07 13:32:40 +0200
commit09dacfc6b8bf62addeee16c20b1d90c2a256da96 (patch)
tree7caa2bf9e92227ab74448f9b746dd28bbcb81b2a /perllib/FixMyStreet/App/Controller/Admin/Bodies.pm
parent585e57484f9c6332668bf1ac0a6a3b39dbe32223 (diff)
parentcea89fb87a96943708a1db0f646492fbfaaf000f (diff)
Merge tag 'v3.1' into fiksgatami-devfiksgatami-dev
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Admin/Bodies.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Bodies.pm43
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;