diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Bodies.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/BathNES.pm | 13 | ||||
-rw-r--r-- | t/cobrand/bathnes.t | 18 | ||||
-rw-r--r-- | templates/web/bathnes/admin/bodies/_category_field.html | 21 |
4 files changed, 55 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm index 8556e8a27..165fdc783 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm @@ -290,7 +290,7 @@ sub update_contact : Private { $c->forward('/admin/update_extra_fields', [ $contact ]); - $c->forward('contact_cobrand_extra_fields', [ $contact ]); + $c->forward('contact_cobrand_extra_fields', [ $contact, \%errors ]); # Special form disabling form if ($c->get_param('disable')) { @@ -434,12 +434,13 @@ sub check_body_params : Private { } sub contact_cobrand_extra_fields : Private { - my ( $self, $c, $contact ) = @_; + my ( $self, $c, $contact, $errors ) = @_; my $extra_fields = $c->cobrand->call_hook('contact_extra_fields'); foreach ( @$extra_fields ) { $contact->set_extra_metadata( $_ => $c->get_param("extra[$_]") ); } + $c->cobrand->call_hook(contact_extra_fields_validation => $contact, $errors); } sub fetch_translations : Private { diff --git a/perllib/FixMyStreet/Cobrand/BathNES.pm b/perllib/FixMyStreet/Cobrand/BathNES.pm index b6014a276..6de28bca8 100644 --- a/perllib/FixMyStreet/Cobrand/BathNES.pm +++ b/perllib/FixMyStreet/Cobrand/BathNES.pm @@ -27,6 +27,19 @@ sub get_geocoder { return 'OSM'; # default of Bing gives poor results, let's try overriding. } +sub contact_extra_fields { [ 'display_name' ] } + +sub contact_extra_fields_validation { + my ($self, $contact, $errors) = @_; + return unless $contact->get_extra_metadata('display_name'); + + my @contacts = $contact->body->contacts->not_deleted->search({ id => { '!=', $contact->id } }); + my %display_names = map { $_->get_extra_metadata('display_name') => 1 } @contacts; + if ($display_names{$contact->get_extra_metadata('display_name')}) { + $errors->{display_name} = 'That display name is already in use'; + } +} + sub disambiguate_location { my $self = shift; my $string = shift; diff --git a/t/cobrand/bathnes.t b/t/cobrand/bathnes.t index d434d1160..42a8ffe93 100644 --- a/t/cobrand/bathnes.t +++ b/t/cobrand/bathnes.t @@ -1,6 +1,10 @@ +use Test::MockModule; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; +my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::BathNES'); +$cobrand->mock('area_types', sub { [ 'UTA' ] }); + my $body = $mech->create_body_ok(2551, 'Bath and North East Somerset Council'); my @cats = ('Litter', 'Other', 'Potholes', 'Traffic lights'); for my $contact ( @cats ) { @@ -59,6 +63,20 @@ subtest 'cobrand displays council name' => sub { $mech->content_like( qr/Bath and North East Somerset\b/ ); }; +subtest 'check override contact display name' => sub { + $mech->log_in_ok( $superuser->email ); + $mech->get_ok("/admin/body/" . $body->id . '/Litter'); + $mech->content_contains('<h1>Litter</h1>'); + $mech->content_contains('extra[display_name]'); + $mech->submit_form_ok({ with_fields => { + 'extra[display_name]' => 'Wittering' + }}); + $mech->get_ok('/reports/Bath+and+North+East+Somerset'); + $mech->content_contains('Wittering</option>'); + $mech->content_contains('value="Litter"'); + $mech->content_lacks('Litter</option>'); +}; + subtest 'extra CSV columns are absent if permission not granted' => sub { $mech->log_in_ok( $counciluser->email ); diff --git a/templates/web/bathnes/admin/bodies/_category_field.html b/templates/web/bathnes/admin/bodies/_category_field.html new file mode 100644 index 000000000..6497e3511 --- /dev/null +++ b/templates/web/bathnes/admin/bodies/_category_field.html @@ -0,0 +1,21 @@ +[% IF contact.in_storage %] + <h1>[% contact.category | html %]</h1> + <input type="hidden" name="category" value="[% contact.category | html %]" > + + <div class="admin-hint"> + <p>A display name will be used in preference to the main category name on web pages and dropdown menus, but not in URLs.</p> + </div> + + <p> + <label> + Display name: + <input type="text" class="form-control" name="extra[display_name]" id="display_name" + value="[% contact.get_extra_metadata('display_name') | html %]" size="30"> + </label> + </p> + +[% ELSE %] + <p> + <strong>[% loc('Category') %] </strong><input type="text" class="form-control" name="category" size="30" value="[% contact.category | html %]" required> + </p> +[% END %] |