aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm5
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyStreet.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/IsleOfWight.pm17
-rw-r--r--perllib/FixMyStreet/DB/Result/Contact.pm7
-rw-r--r--perllib/FixMyStreet/TestMech.pm27
-rw-r--r--perllib/Open311/PopulateServiceList.pm34
7 files changed, 69 insertions, 25 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index ebb3d4839..f14d116cc 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -234,7 +234,7 @@ sub check_and_stash_category : Private {
my @list_of_names = map { $_->name } values %bodies;
my $csv = Text::CSV->new();
$csv->combine(@list_of_names);
- $c->stash->{bodies} = \@bodies;
+ $c->stash->{around_bodies} = \@bodies;
$c->{stash}->{list_of_names_as_string} = $csv->string;
my $where = { body_id => [ keys %bodies ], };
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 06974cd09..5407ec937 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -102,19 +102,18 @@ sub report_new : Path : Args(0) {
$c->stash->{template} = "report/new/fill_in_details.html";
$c->forward('setup_categories_and_bodies');
$c->forward('setup_report_extra_fields');
- $c->forward('generate_map');
$c->forward('check_for_category');
$c->forward('setup_report_extras');
# deal with the user and report and check both are happy
- return unless $c->forward('check_form_submitted');
+ $c->detach('generate_map') unless $c->forward('check_form_submitted');
$c->forward('/auth/check_csrf_token');
$c->forward('process_report');
$c->forward('process_user');
$c->forward('/photo/process_photo');
- return unless $c->forward('check_for_errors');
+ $c->detach('generate_map') unless $c->forward('check_for_errors');
$c->forward('save_user_and_report');
$c->forward('redirect_or_confirm_creation');
}
diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
index 38e9e09a0..72ba51dd8 100644
--- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
+++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
@@ -42,7 +42,7 @@ sub munge_around_category_where {
my ($self, $where) = @_;
my $user = $self->{c}->user;
- my @iow = grep { $_->name eq 'Isle of Wight Council' } @{ $self->{c}->stash->{bodies} };
+ my @iow = grep { $_->name eq 'Isle of Wight Council' } @{ $self->{c}->stash->{around_bodies} };
return unless @iow;
# display all the categories on Isle of Wight at the moment as there's no way to
diff --git a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
index 753ac3b72..6a719604d 100644
--- a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
+++ b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
@@ -58,6 +58,15 @@ sub problems_restriction {
sub get_geocoder { 'OSM' }
+sub lookup_site_code_config { {
+ buffer => 50, # metres
+ url => "https://tilma.mysociety.org/mapserver/iow",
+ srsname => "urn:ogc:def:crs:EPSG::27700",
+ typename => "streets",
+ property => "SITE_CODE",
+ accept_feature => sub { 1 }
+} }
+
sub open311_pre_send {
my ($self, $row, $open311) = @_;
@@ -81,6 +90,14 @@ sub open311_config {
{ name => 'description',
value => $row->detail };
+ if (!$row->get_extra_field_value('site_code')) {
+ if (my $site_code = $self->lookup_site_code($row)) {
+ push @$extra,
+ { name => 'site_code',
+ value => $site_code };
+ }
+ }
+
$row->set_extra_fields(@$extra);
}
diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm
index bc91c84ee..a99915fb4 100644
--- a/perllib/FixMyStreet/DB/Result/Contact.pm
+++ b/perllib/FixMyStreet/DB/Result/Contact.pm
@@ -98,6 +98,13 @@ sub category_display {
$self->translate_column('category');
}
+sub groups {
+ my $self = shift;
+ my $groups = $self->get_extra_metadata('group') || [];
+ $groups = [ $groups ] unless ref $groups eq 'ARRAY';
+ return $groups;
+}
+
sub get_all_metadata {
my $self = shift;
my @metadata = @{$self->get_extra_fields};
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 927e4556c..cc2020b63 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -56,6 +56,26 @@ sub logged_in_ok {
"logged in" );
}
+=head2 uniquify_email
+
+Given an email address, will add the caller to it so that it can be unique per
+file. You can pass a caller file in yourself if e.g. you're another function in
+this file.
+
+=cut
+
+sub uniquify_email {
+ my ($self, $email, $file) = @_;
+
+ $file = (caller)[1] unless $file;
+ (my $pkg = $file) =~ s{/}{}g;
+
+ if ($email =~ /@/ && $email !~ /^pkg-/) {
+ $email = "pkg-$pkg-$email";
+ }
+ return $email;
+}
+
=head2 create_user_ok
$user = $mech->create_user_ok( $email );
@@ -68,8 +88,9 @@ sub create_user_ok {
my $self = shift;
my ( $username, %extra ) = @_;
+ $username = $self->uniquify_email($username, (caller)[1]);
my $params = { %extra };
- $username =~ /@/ ? $params->{email} = $username : $params->{phone} = $username;
+ $username =~ /@/ ? ($params->{email} = $username) : ($params->{phone} = $username);
my $user = FixMyStreet::DB->resultset('User')->find_or_create($params);
ok $user, "found/created user for $username";
@@ -88,6 +109,7 @@ sub log_in_ok {
my $mech = shift;
my $username = shift;
+ $username = $mech->uniquify_email($username, (caller)[1]);
my $user = $mech->create_user_ok($username);
# remember the old password and then change it to a known one
@@ -663,8 +685,9 @@ sub create_problems_for_body {
my $dt = $params->{dt} || DateTime->now();
+ my $email = $mech->uniquify_email('test@example.com', (caller)[1]);
my $user = $params->{user} ||
- FixMyStreet::DB->resultset('User')->find_or_create( { email => 'test@example.com', name => 'Test User' } );
+ FixMyStreet::DB->resultset('User')->find_or_create( { email => $email, name => 'Test User' } );
delete $params->{user};
delete $params->{dt};
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index f1bfc0f21..e58f51be6 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -280,16 +280,11 @@ sub _normalize_service_name {
sub _set_contact_group {
my ($self, $contact) = @_;
- my $groups_enabled = $self->_current_body_cobrand && $self->_current_body_cobrand->enable_category_groups;
- my $old_group = $contact->get_extra_metadata('group') || '';
- my $new_group = $groups_enabled ? $self->_current_service->{group} || '' : '';
- my $new_group_multi = $groups_enabled ? $self->_current_service->{groups} || [] : [];
- if (@$new_group_multi) {
- $new_group = $new_group_multi;
- }
+ my $old_group = $contact->groups;
+ my $new_group = $self->_get_new_groups;
if ($self->_groups_different($old_group, $new_group)) {
- if ($new_group) {
+ if (@$new_group) {
$contact->set_extra_metadata(group => @$new_group == 1 ? $new_group->[0] : $new_group);
$contact->update({
editor => $0,
@@ -322,19 +317,22 @@ sub _set_contact_non_public {
}) if $keywords{private};
}
+sub _get_new_groups {
+ my $self = shift;
+ return [] unless $self->_current_body_cobrand && $self->_current_body_cobrand->enable_category_groups;
+
+ my $groups = $self->_current_service->{groups} || [];
+ return $groups if @$groups;
+
+ my $group = $self->_current_service->{group} || [];
+ $group = [] if @$group == 1 && !$group->[0]; # <group></group> becomes [undef]...
+ return $group;
+}
+
sub _groups_different {
my ($self, $old, $new) = @_;
- my $diff = 1;
- if ($old && $new) {
- $old = [ $old ] unless ref $old eq 'ARRAY';
- $new = [ $new ] unless ref $new eq 'ARRAY';
- $diff = join( ',', sort(@$old) ) ne join( ',', sort(@$new) );
- } elsif (!$old && !$new) {
- $diff = 0;
- }
-
- return $diff;
+ return join( ',', sort(@$old) ) ne join( ',', sort(@$new) );
}
sub _delete_contacts_not_in_service_list {