diff options
30 files changed, 355 insertions, 96 deletions
diff --git a/bin/fixmystreet.com/one-off-status-update b/bin/fixmystreet.com/one-off-status-update new file mode 100755 index 000000000..78a27b67f --- /dev/null +++ b/bin/fixmystreet.com/one-off-status-update @@ -0,0 +1,177 @@ +#!/usr/bin/env perl + +=head1 NAME + +one-off-status-update + +=head1 SUMMARY + +one-off-status-update [--commit] path/to/file.csv + +=head1 DESCRIPTION + +This is a one off script to update the status of NCC reports affected +by a bug in the NCC update process. It relies on a csv file containing +a mapping of report id to Alloy status and uses this to update the +FixMyStreet status. + +It takes a single command line argument which is the path to the csv +file containing the reports to update, along with details of the current +alloy state which it uses to determine what state to update them too. + +Only reports that match the state in the `fms_state` column of the csv +file will be updated. Similarly, if it cannot determine what state to +update the report to it will skip that report. + +Any update made will set the appropriate response template. + +It will not update the database unless the `--commit` flag is used. + +=head1 EXPECTED CSV HEADERS + +RESOURCE_ID,INSPECTION_NUMBER,Street_Doctor_No,fms_state,Reason_for_Closure,Enquiry_TASK_STATUS,Enquiry_Type,Summary,Reported_DateTime,Response_to_Customer,DEFECT_REPORTED_DATE,DEFECT_STATUS_NO,DEFECT_STATUS,DEFECT_NUMBER,REMEDIED_DATE,TEAM_DESCRIPTION,User_Name,Category,Stage,Stage_Description,blank,blank2 + + +Of these the following are used: + +=over + +=item * Street_Doctor_No - FixMyStreet id + +=item * fms_state - expected state on FixMyStreet + +=item * Enquiry_TASK_STATUS - Alloy status + +=item * Reason_for_Closure - Alloy reason for closure + +=item * Response_to_Customer - Alloy text to add to update on FixMyStreet + +=item * DEFECT_STATUS - used to check if there is extra status on the defect + +=back + +=cut + +use strict; +use warnings; +use v5.14; + +BEGIN { + use File::Basename qw(dirname); + use File::Spec; + my $d = dirname(File::Spec->rel2abs($0)); + require "$d/../../setenv.pl"; +} + +use FixMyStreet::DB; +use Text::CSV; + +use Getopt::Long; + +my ($commit, $verbose); +GetOptions( + 'commit' => \$commit, + 'verbose' => \$verbose, +); + +if (!$commit) { + say "*** DRY RUN ***"; +} + +my %alloy_to_fms_map = ( + 'No Action Necessary' => 'unable to fix', + 'Outside NCC Control' => 'not responsible', + 'Highways to Monitor. No Action' => 'unable to fix', + 'Work Instructed' => 'in progess', +); + +my $file = shift; + +my $csv = Text::CSV->new; +open my $fh, "<:encoding(utf-8)", $file or die "Failed to open $file: $!\n"; +my @cols = @{$csv->getline($fh)}; +$csv->column_names (@cols); + +my ($checked, $updated) = (0,0); +my $northants = FixMyStreet::DB->resultset("Body")->find({ name => 'Northamptonshire County Council' }); +if ($northants) { + my $comment_user = $northants->comment_user; + while (my $report = $csv->getline_hr( $fh ) ) { + $checked++; + my $id = $report->{Street_Doctor_No}; + next unless $id; + my $p = FixMyStreet::DB->resultset("Problem")->find({ id => $id }); + unless ($p) { + warn "Could not find matching report with id $id\n"; + next; + } + + unless ($p->state eq $report->{fms_state}) { + warn sprintf("Report $id has state %s, %s expected\n", $p->state, $report->{fms_state}); + next; + } + + my $new_state = get_state( $report ); + + unless ( $new_state ) { + warn "skipping $id as can't determine new state\n" if $verbose; + next; + } + + my $text = $report->{Response_to_Customer}; + if (!$text) { + if (my $t = $p->response_templates->search({ + auto_response => 1, + 'me.state' => $new_state + })->first) { + $text = $t->text; + } + } + + if ($commit) { + warn "updating $id to $new_state\n" if $verbose; + $updated++; + $p->update({ + state => $new_state, + lastupdate => \'current_timestamp', + }); + + my $comment = FixMyStreet::DB->resultset('Comment')->new({ + problem => $p, + user => $comment_user, + name => $comment_user->name, + text => $text, + problem_state => $new_state, + external_id => -1, + mark_fixed => 0, + mark_open => 0, + anonymous => 0, + confirmed => \'current_timestamp', + created => \'current_timestamp', + state => 'confirmed', + }); + $comment->set_extra_metadata(one_off_script_update => 1); + $comment->insert; + } + } +} else { + say STDERR "Could not find Northamptonshire"; +} + +say "$checked reports looked at, $updated updated"; + +sub get_state { + my $report = shift; + + if ( !$report->{Reason_for_Closure} && !$report->{DEFECT_STATUS} && $report->{Enquiry_TASK_STATUS} eq 'Completed') { + return "closed"; + } + + my $fms_state = $alloy_to_fms_map{$report->{Reason_for_Closure}}; + + if ( $report->{DEFECT_STATUS} ) { + say STDERR $report->{Street_Doctor_No} . " has a defect status of " . $report->{DEFECT_STATUS}; + } + + return $fms_state; +} 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 { diff --git a/t/Mock/OpenIDConnect.pm b/t/Mock/OpenIDConnect.pm index 079c354fc..1a1428758 100644 --- a/t/Mock/OpenIDConnect.pm +++ b/t/Mock/OpenIDConnect.pm @@ -55,7 +55,7 @@ sub dispatch_request { extension_CrmContactId => "1c304134-ef12-c128-9212-123908123901", nonce => 'MyAwesomeRandomValue', }; - $payload->{emails} = ['oidc@example.org'] if $self->returns_email; + $payload->{emails} = ['pkg-tappcontrollerauth_social.t-oidc@example.org'] if $self->returns_email; my $signature = "dummy"; my $id_token = join(".", ( encode_base64($self->json->encode($header), ''), diff --git a/t/app/controller/admin/update_edit.t b/t/app/controller/admin/update_edit.t index cf371651b..57c8973d4 100644 --- a/t/app/controller/admin/update_edit.t +++ b/t/app/controller/admin/update_edit.t @@ -83,7 +83,7 @@ for my $test ( state => 'confirmed', name => '', anonymous => 1, - username => 'test@example.com', + username => $update->user->email, }, changes => { text => 'this is a changed update', @@ -98,7 +98,7 @@ for my $test ( state => 'confirmed', name => '', anonymous => 1, - username => 'test@example.com', + username => $update->user->email, }, changes => { name => 'A User', @@ -113,7 +113,7 @@ for my $test ( state => 'confirmed', name => 'A User', anonymous => 1, - username => 'test@example.com', + username => $update->user->email, }, changes => { anonymous => 0, @@ -128,10 +128,10 @@ for my $test ( state => 'confirmed', name => 'A User', anonymous => 0, - username => 'test@example.com', + username => $update->user->email, }, changes => { - username => 'test2@example.com', + username => $user2->email, }, log_count => 4, log_entries => [qw/edit edit edit edit/], @@ -144,7 +144,7 @@ for my $test ( state => 'confirmed', name => 'A User', anonymous => 0, - username => 'test2@example.com', + username => $user2->email, }, changes => { state => 'unconfirmed', @@ -159,7 +159,7 @@ for my $test ( state => 'unconfirmed', name => 'A User', anonymous => 0, - username => 'test2@example.com', + username => $user2->email, }, changes => { text => 'this is a twice changed update', diff --git a/t/app/controller/admin/users.t b/t/app/controller/admin/users.t index b6da170ba..7361ab619 100644 --- a/t/app/controller/admin/users.t +++ b/t/app/controller/admin/users.t @@ -264,7 +264,7 @@ FixMyStreet::override_config { desc => 'edit user name', fields => { name => '', - email => 'test@example.com', + email => $user->email, email_verified => 1, body => $haringey->id, phone => '', @@ -285,7 +285,7 @@ FixMyStreet::override_config { desc => 'edit user email', fields => { name => 'Changed User', - email => 'test@example.com', + email => $user->email, email_verified => 1, body => $haringey->id, phone => '', @@ -464,7 +464,7 @@ FixMyStreet::override_config { $mech->create_problems_for_body(2, 2514, 'Title', { user => $existing_user }); my $count = FixMyStreet::DB->resultset('Problem')->search({ user_id => $user->id })->count; $mech->get_ok( '/admin/users/' . $user->id ); - $mech->submit_form_ok( { with_fields => { email => 'existing@example.com' } }, 'submit email change' ); + $mech->submit_form_ok( { with_fields => { email => $existing_user->email } }, 'submit email change' ); is $mech->uri->path, '/admin/users/' . $existing_user->id, 'redirected'; my $p = FixMyStreet::DB->resultset('Problem')->search({ user_id => $existing_user->id })->count; is $p, $count + 2, 'reports merged'; @@ -518,7 +518,7 @@ subtest "Send login email from admin for unverified email" => sub { is $email->header('Subject'), "Your FixMyStreet account details", "subject is correct"; - is $email->header('To'), 'test@example.com', "to is correct"; + is $email->header('To'), $user->email, "to is correct"; my $link = $mech->get_link_from_email($email); diff --git a/t/app/controller/alert_new.t b/t/app/controller/alert_new.t index f77114d86..7318d5c65 100644 --- a/t/app/controller/alert_new.t +++ b/t/app/controller/alert_new.t @@ -4,56 +4,56 @@ use FixMyStreet::Script::Alerts; my $mech = FixMyStreet::TestMech->new; -$mech->log_in_ok('test@example.com'); +my $user = $mech->log_in_ok('test@example.com'); $mech->get_ok('/alert/subscribe?id=1'); my ($csrf) = $mech->content =~ /name="token" value="([^"]*)"/; foreach my $test ( { - email => 'test@example.com', + email => $user->email, type => 'area_problems', content => 'Click the link in our confirmation email to activate your alert', email_text => "confirms that you'd like to receive an email", uri => -'/alert/subscribe?type=local&rznvy=test@example.com&feed=area:1000:A_Location', +'/alert/subscribe?type=local&rznvy=' . $user->email . '&feed=area:1000:A_Location', param1 => 1000 }, { - email => 'test@example.com', + email => $user->email, type => 'council_problems', content => 'Click the link in our confirmation email to activate your alert', email_text => "confirms that you'd like to receive an email", uri => -'/alert/subscribe?type=local&rznvy=test@example.com&feed=council:1000:A_Location', +'/alert/subscribe?type=local&rznvy=' . $user->email . '&feed=council:1000:A_Location', param1 => 1000, param2 => 1000, }, { - email => 'test@example.com', + email => $user->email, type => 'ward_problems', content => 'Click the link in our confirmation email to activate your alert', email_text => "confirms that you'd like to receive an email", uri => -'/alert/subscribe?type=local&rznvy=test@example.com&feed=ward:1000:1001:A_Location:Diff_Location', +'/alert/subscribe?type=local&rznvy=' . $user->email . '&feed=ward:1000:1001:A_Location:Diff_Location', param1 => 1000, param2 => 1001, }, { - email => 'test@example.com', + email => $user->email, type => 'local_problems', content => 'Click the link in our confirmation email to activate your alert', email_text => "confirms that you'd like to receive an email", uri => -'/alert/subscribe?type=local&rznvy=test@example.com&feed=local:10.2:20.1', +'/alert/subscribe?type=local&rznvy=' . $user->email . '&feed=local:10.2:20.1', param1 => 20.1, param2 => 10.2, }, { - email => 'test@example.com', + email => $user->email, type => 'new_updates', content => 'Click the link in our confirmation email to activate your alert', email_text => "confirms that you'd like to receive an email", - uri => '/alert/subscribe?type=updates&rznvy=test@example.com&id=1', + uri => '/alert/subscribe?type=updates&rznvy=' . $user->email . '&id=1', param1 => 1, } ) @@ -163,7 +163,7 @@ foreach my $test ( # clear existing data so we can be sure we're creating it ok $alert->delete() if $alert && !$test->{exist}; - $mech->get_ok( '/alert/subscribe?type=local&rznvy=test-new@example.com&feed=area:1000:A_Location&token=' . $csrf ); + $mech->get_ok( '/alert/subscribe?type=local&rznvy=' . $user->email . '&feed=area:1000:A_Location&token=' . $csrf ); $alert = FixMyStreet::App->model('DB::Alert')->find( { @@ -232,11 +232,11 @@ foreach my $test ( for my $test ( { - email => 'test@example.com', + email => $user->email, type => 'new_updates', content => 'Click the link in our confirmation email to activate your alert', email_text => 'confirm the alert', - uri => '/alert/subscribe?type=updates&rznvy=test@example.com&id=1', + uri => '/alert/subscribe?type=updates&rznvy=' . $user->email . '&id=1', param1 => 1, } ) diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 829d78ca3..7f88b13c1 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -137,6 +137,18 @@ subtest 'check non public reports are not displayed on around page' => sub { 'problem marked non public is not visible' ); }; +subtest 'check missing body message not shown when it does not need to be' => sub { + $mech->get_ok('/'); + FixMyStreet::override_config { + ALLOWED_COBRANDS => 'fixmystreet', + MAPIT_URL => 'http://mapit.uk/', + }, sub { + $mech->submit_form_ok( { with_fields => { pc => 'EH1 1BB' } }, + "good location" ); + }; + $mech->content_lacks('yet have details for the other councils that cover this location'); +}; + for my $permission ( qw/ report_inspect report_mark_private/ ) { subtest 'check non public reports are displayed on around page with $permission permission' => sub { my $body = FixMyStreet::DB->resultset('Body')->find( $body_edin_id ); diff --git a/t/app/controller/auth_profile.t b/t/app/controller/auth_profile.t index 4be1be12c..815098caa 100644 --- a/t/app/controller/auth_profile.t +++ b/t/app/controller/auth_profile.t @@ -428,10 +428,9 @@ subtest "Test generate token page" => sub { }; subtest "Test two-factor authentication admin" => sub { - my $user = FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); + my $user = $mech->log_in_ok($test_email); ok $user->update({ is_superuser => 1 }), 'user set to superuser'; - $mech->log_in_ok($test_email); $mech->get_ok('/auth/generate_token'); ok !$user->get_extra_metadata('2fa_secret'); diff --git a/t/app/controller/auth_social.t b/t/app/controller/auth_social.t index f499da659..f5f64248c 100644 --- a/t/app/controller/auth_social.t +++ b/t/app/controller/auth_social.t @@ -17,6 +17,7 @@ END { FixMyStreet::App->log->enable('info'); } my $body = $mech->create_body_ok(2504, 'Westminster City Council'); my ($report) = $mech->create_problems_for_body(1, $body->id, 'My Test Report'); +my $test_email = $report->user->email; my $contact = $mech->create_contact_ok( body_id => $body->id, category => 'Damaged bin', email => 'BIN', @@ -44,7 +45,7 @@ for my $test ( MAPIT_URL => 'http://mapit.uk/', }, update => 1, - email => 'facebook@example.org', + email => $mech->uniquify_email('facebook@example.org'), uid => 123456789, mock => 't::Mock::Facebook', mock_hosts => ['www.facebook.com', 'graph.facebook.com'], @@ -71,7 +72,7 @@ for my $test ( } } }, - email => 'oidc@example.org', + email => $mech->uniquify_email('oidc@example.org'), uid => "westminster:example_client_id:my_cool_user_id", mock => 't::Mock::OpenIDConnect', mock_hosts => ['oidc.example.org'], @@ -113,7 +114,7 @@ for my $state ( 'refused', 'no email', 'existing UID', 'okay' ) { if ($page eq 'my' && $state eq 'existing UID') { $report->update({ user_id => FixMyStreet::App->model( 'DB::User' )->find( { email => $test->{email} } )->id }); } else { - $report->update({ user_id => FixMyStreet::App->model( 'DB::User' )->find( { email => 'test@example.com' } )->id }); + $report->update({ user_id => FixMyStreet::App->model( 'DB::User' )->find( { email => $test_email } )->id }); } # Set up a mock to catch (most, see below) requests to the OAuth API @@ -269,11 +270,11 @@ FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', }, sub { -$resolver->mock('address', sub { 'twitter@example.org' }); - -my $tw_email = 'twitter@example.org'; +my $tw_email = $mech->uniquify_email('twitter@example.org'); my $tw_uid = 987654321; +$resolver->mock('address', sub { $tw_email }); + # Twitter has no way of getting the email, so no "okay" state here for my $tw_state ( 'refused', 'existing UID', 'no email' ) { for my $page ( 'my', 'report', 'update' ) { diff --git a/t/app/controller/contact.t b/t/app/controller/contact.t index 908ec971b..5b0fd2581 100644 --- a/t/app/controller/contact.t +++ b/t/app/controller/contact.t @@ -382,6 +382,7 @@ for my $test ( $mech->clear_emails_ok; $mech->get_ok('/contact'); + $test->{fields}{em} = $user->email; $mech->submit_form_ok( { with_fields => $test->{fields} } ); my $email = $mech->get_email; diff --git a/t/app/controller/contact_enquiry.t b/t/app/controller/contact_enquiry.t index 483289d5f..aca4b6de4 100644 --- a/t/app/controller/contact_enquiry.t +++ b/t/app/controller/contact_enquiry.t @@ -95,10 +95,10 @@ FixMyStreet::override_config { subtest 'Enquiry can be submitted when logged in' => sub { my $problems = FixMyStreet::App->model('DB::Problem')->to_body( $body->id ); - my $user = $problems->first->user; + my $prob_user = $problems->first->user; $problems->delete_all; - $mech->log_in_ok( $user->email ); + my $user = $mech->log_in_ok( $prob_user->email ); $mech->get_ok( '/contact/enquiry' ); $mech->submit_form_ok( { @@ -123,7 +123,7 @@ FixMyStreet::override_config { ok $problem->confirmed, 'problem confirmed'; is $problem->name, 'Test User', 'Report created with correct name'; is $problem->user->name, 'Test User', 'User name updated in DB'; - is $problem->user->email, 'testuser@example.org', 'Report user has correct email'; + is $problem->user->email, $user->email, 'Report user has correct email'; $mech->log_out_ok; }; @@ -139,7 +139,7 @@ FixMyStreet::override_config { $mech->submit_form_ok( { with_fields => { name => 'Simon Neil', - username => 'testuser@example.org', + username => $user->email, category => 'General Enquiry', detail => 'This is a general enquiry', } @@ -158,7 +158,7 @@ FixMyStreet::override_config { is $problem->longitude, -0.35, 'Problem has correct longitude'; ok $problem->confirmed, 'problem confirmed'; is $problem->name, 'Simon Neil', 'Report created with correct name'; - is $problem->user->email, 'testuser@example.org', 'Report user has correct email'; + is $problem->user->email, $user->email, 'Report user has correct email'; $user->discard_changes; is $user->name, 'Test User', 'User name in DB not changed'; diff --git a/t/app/controller/moderate.t b/t/app/controller/moderate.t index 256122d9b..e22d9edbc 100644 --- a/t/app/controller/moderate.t +++ b/t/app/controller/moderate.t @@ -204,7 +204,7 @@ subtest 'Problem moderation' => sub { is $report->state, 'hidden', 'Is hidden'; my $email = $mech->get_email; - is $email->header('To'), '"Test User 2" <test-moderation2@example.com>', 'Sent to correct email'; + is $email->header('To'), '"Test User 2" <' . $user2->email . '>', 'Sent to correct email'; my $url = $mech->get_link_from_email($email); ok $url, "extracted complain url '$url'"; diff --git a/t/app/controller/report_as_other.t b/t/app/controller/report_as_other.t index 0c8b7d995..5f9ba7600 100644 --- a/t/app/controller/report_as_other.t +++ b/t/app/controller/report_as_other.t @@ -106,7 +106,7 @@ subtest "Body user, has permission to add report as another (existing) user with FixMyStreet::Script::Reports::send(); $mech->clear_emails_ok; - $mech->create_user_ok('existing@example.net', name => 'Existing User'); + my $existing = $mech->create_user_ok('existing@example.net', name => 'Existing User'); my $report = add_report( 'contribute_as_another_user', form_as => 'another_user', @@ -114,11 +114,11 @@ subtest "Body user, has permission to add report as another (existing) user with detail => 'Test report details.', category => 'Potholes', name => 'Existing Yooser', - username => 'existing@example.net', + username => $existing->email, ); is $report->name, 'Existing Yooser', 'report name is given name'; is $report->user->name, 'Existing User', 'user name remains same'; - is $report->user->email, 'existing@example.net', 'user email correct'; + is $report->user->email, $existing->email, 'user email correct'; isnt $report->user->id, $user->id, 'user does not match'; like $mech->get_text_body_from_email, qr/Your report to Oxfordshire County Council has been logged/; push @users, $report->user; @@ -244,16 +244,17 @@ subtest "Body user, has permission to add update as another user with landline p }; subtest "Body user, has permission to add update as another (existing) user with email" => sub { + my $existing = $mech->create_user_ok('existing@example.net', name => 'Existing User'); my $update = add_update( 'contribute_as_another_user', form_as => 'another_user', update => 'Test Update', name => 'Existing Yooser', - username => 'existing@example.net', + username => $existing->email, ); is $update->name, 'Existing Yooser', 'update name is given name'; is $update->user->name, 'Existing User', 'user name remains same'; - is $update->user->email, 'existing@example.net', 'user email correct'; + is $update->user->email, $existing->email, 'user email correct'; isnt $update->user->id, $user->id, 'user does not match'; like $mech->get_text_body_from_email, qr/Your update has been logged/; }; diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 417d91ef9..20eecb50e 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -963,7 +963,7 @@ foreach my $test ( title => 'Test Report', detail => 'Test report details.', photo1 => '', - username => $test_email, + username => $user->email, password_sign_in => 'secret2', category => 'Street lighting', } @@ -1347,7 +1347,7 @@ subtest "test report creation for a category that is non public" => sub { title => 'Test Report', detail => 'Test report details.', photo1 => '', - username => 'test-2@example.com', + username => $user->email, name => 'Joe Bloggs', category => 'Street lighting', } @@ -1801,7 +1801,7 @@ subtest "test Hart" => sub { # check that the user has been created/ not changed $user = - FixMyStreet::App->model('DB::User')->find( { email => $test_email } ); + FixMyStreet::App->model('DB::User')->find( { email => $user ? $user->email : $test_email } ); ok $user, "user found"; # find the report diff --git a/t/app/controller/report_new_mobile.t b/t/app/controller/report_new_mobile.t index 296007ce3..def140a72 100644 --- a/t/app/controller/report_new_mobile.t +++ b/t/app/controller/report_new_mobile.t @@ -15,21 +15,20 @@ subtest "Check signed up for alert when logged in" => sub { MAPIT_URL => 'http://mapit.zurich', MAPIT_TYPES => [ 'O08' ], }, sub { - $mech->log_in_ok('user@example.org'); + my $user = $mech->log_in_ok('user@example.org'); $mech->post_ok( '/report/new/mobile', { service => 'iPhone', title => 'Title', detail => 'Problem detail', lat => 47.381817, lon => 8.529156, - email => 'user@example.org', + email => $user->email, pc => '', name => 'Name', }); my $res = $mech->response; ok $res->header('Content-Type') =~ m{^application/json\b}, 'response should be json'; - my $user = FixMyStreet::DB->resultset('User')->search({ email => 'user@example.org' })->first; my $a = FixMyStreet::DB->resultset('Alert')->search({ user_id => $user->id })->first; isnt $a, undef, 'User is signed up for alert'; }; diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 8ff5b4d24..983305661 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -1247,6 +1247,7 @@ for my $test ( subtest $test->{desc} => sub { # Set things up my $user = $mech->create_user_ok( $test->{form_values}->{username} ); + $test->{form_values}{username} = $user->email; my $pw = 'secret2'; $user->update( { name => 'Mr Reg', password => $pw } ); $report->comments->delete; @@ -1303,7 +1304,7 @@ subtest 'submit an update for a registered user, creating update by email' => su $mech->submit_form_ok( { with_fields => { submit_update => 1, - username => 'registered@example.com', + username => $user->email, update => 'Update from a user', add_alert => undef, name => 'New Name', @@ -1338,7 +1339,7 @@ subtest 'submit an update for a registered user, creating update by email' => su ok $update, 'found update in database'; is $update->state, 'unconfirmed', 'update unconfirmed'; - is $update->user->email, 'registered@example.com', 'update email'; + is $update->user->email, $user->email, 'update email'; is $update->text, 'Update from a user', 'update text'; $mech->get_ok( $url ); @@ -1505,7 +1506,7 @@ for my $test ( $mech->clear_emails_ok(); - $mech->log_in_ok( $test->{email} ); + my $user = $mech->log_in_ok( $test->{email} ); $mech->get_ok("/report/$report_id"); my $values = $mech->visible_form_values( 'updateForm' ); @@ -1548,7 +1549,7 @@ for my $test ( }; is $update->text, $results->{update}, 'update text'; - is $update->user->email, $test->{email}, 'update user'; + is $update->user->email, $user->email, 'update user'; is $update->state, 'confirmed', 'update confirmed'; is $update->anonymous, $test->{anonymous}, 'user anonymous'; @@ -1678,7 +1679,7 @@ foreach my $test ( $mech->clear_emails_ok(); - $mech->log_in_ok( $test->{email} ); + my $user = $mech->log_in_ok( $test->{email} ); $mech->get_ok("/report/$report_id"); my $values = $mech->visible_form_values('updateForm'); @@ -1708,7 +1709,7 @@ foreach my $test ( my $update = $report->comments->first; ok $update, 'found update'; is $update->text, $results->{update}, 'update text'; - is $update->user->email, $test->{email}, 'update user'; + is $update->user->email, $user->email, 'update user'; is $update->state, 'confirmed', 'update confirmed'; is $update->anonymous, $test->{anonymous}, 'user anonymous'; @@ -1752,7 +1753,7 @@ for my $test ( fields => { submit_update => 1, name => 'Test User', - username => 'test@example.com', + username => $report->user->email, may_show_name => 1, update => 'update from owner', add_alert => undef, @@ -1774,7 +1775,7 @@ for my $test ( submit_update => 1, name => 'Test User', may_show_name => 1, - username => 'test@example.com', + username => $report->user->email, update => 'update from owner', add_alert => undef, fixed => 1, diff --git a/t/app/model/session.t b/t/app/model/session.t index f76533727..f460204e5 100644 --- a/t/app/model/session.t +++ b/t/app/model/session.t @@ -2,13 +2,13 @@ use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; -$mech->log_in_ok('test@example.com'); +my $user = $mech->log_in_ok('test@example.com'); my $session = FixMyStreet::DB->resultset("Session")->first; my $id = $session->id; $id =~ s/\s+$//; is $id, "session:" . $session->id_code; -is $session->user->email, 'test@example.com'; +is $session->user->email, $user->email; done_testing; diff --git a/t/app/model/user.t b/t/app/model/user.t index 88b29ca84..c1981c858 100644 --- a/t/app/model/user.t +++ b/t/app/model/user.t @@ -67,7 +67,7 @@ FixMyStreet::override_config { }; subtest 'Check non-existent methods on user object die' => sub { - my $c = ctx_request(POST '/auth', { username => 'test@example.com', password_sign_in => 'secret' }); + my $c = ctx_request(POST '/auth', { username => $problem->user->email, password_sign_in => 'secret' }); throws_ok( sub { $c->user->is_super_user }, qr/Can't locate object method 'is_super_user'/, diff --git a/t/cobrand/bathnes.t b/t/cobrand/bathnes.t index 1ebddd05a..d434d1160 100644 --- a/t/cobrand/bathnes.t +++ b/t/cobrand/bathnes.t @@ -156,28 +156,28 @@ subtest 'extra CSV columns are present if permission granted' => sub { is $rows[1]->[18], 'iOS', 'Site Used shows whether report made via app'; is $rows[1]->[19], '', 'Reported As is empty if not made on behalf of another user/body'; - is $rows[1]->[20], 'normaluser@example.com', 'User email is correct'; + is $rows[1]->[20], $normaluser->email, 'User email is correct'; is $rows[1]->[21], '+447123456789', 'User phone number is correct'; is $rows[1]->[22], '', 'Staff User is empty if not made on behalf of another user'; is $rows[1]->[23], 'width = 10cm; depth = 25cm', 'Attribute Data is correct'; is $rows[2]->[18], 'bathnes', 'Site Used shows correct cobrand'; is $rows[2]->[19], 'body', 'Reported As is correct if made on behalf of body'; - is $rows[2]->[20], 'counciluser@example.com', 'User email is correct'; + is $rows[2]->[20], $counciluser->email, 'User email is correct'; is $rows[2]->[21], '', 'User phone number is correct'; is $rows[2]->[22], '', 'Staff User is empty if not made on behalf of another user'; is $rows[2]->[23], '', 'Attribute Data is correct'; is $rows[3]->[18], 'bathnes', 'Site Used shows correct cobrand'; is $rows[3]->[19], 'another_user', 'Reported As is set if reported on behalf of another user'; - is $rows[3]->[20], 'normaluser@example.com', 'User email is correct'; + is $rows[3]->[20], $normaluser->email, 'User email is correct'; is $rows[3]->[21], '+447123456789', 'User phone number is correct'; - is $rows[3]->[22], 'counciluser@example.com', 'Staff User is correct if made on behalf of another user'; + is $rows[3]->[22], $counciluser->email, 'Staff User is correct if made on behalf of another user'; is $rows[3]->[23], '', 'Attribute Data is correct'; is $rows[4]->[18], 'bathnes', 'Site Used shows correct cobrand'; is $rows[4]->[19], 'anonymous_user', 'Reported As is set if reported on behalf of another user'; - is $rows[4]->[20], 'counciluser@example.com', 'User email is correct'; + is $rows[4]->[20], $counciluser->email, 'User email is correct'; is $rows[4]->[21], '', 'User phone number is correct'; is $rows[4]->[22], '', 'Staff User is empty if not made on behalf of another user'; is $rows[4]->[23], '', 'Attribute Data is correct'; diff --git a/t/script/inactive.t b/t/script/inactive.t index 4667c989b..489ff55ca 100644 --- a/t/script/inactive.t +++ b/t/script/inactive.t @@ -5,12 +5,12 @@ use_ok 'FixMyStreet::Script::Inactive'; my $in = FixMyStreet::Script::Inactive->new( anonymize => 6, email => 3 ); my $mech = FixMyStreet::TestMech->new; -my $user = FixMyStreet::DB->resultset("User")->find_or_create({ email => 'test@example.com' }); +my $user = $mech->create_user_ok('test@example.com'); my $t = DateTime->new(year => 2016, month => 1, day => 1, hour => 12); $user->last_active($t); $user->update; -my $user_inactive = FixMyStreet::DB->resultset("User")->find_or_create({ email => 'inactive@example.com' }); +my $user_inactive = $mech->create_user_ok('inactive@example.com'); $t = DateTime->now->subtract(months => 4); $user_inactive->last_active($t); $user_inactive->update; diff --git a/templates/web/base/reports/_rss.html b/templates/web/base/reports/_rss.html index 567be92ea..4bb30c274 100644 --- a/templates/web/base/reports/_rss.html +++ b/templates/web/base/reports/_rss.html @@ -4,6 +4,8 @@ SET monikers = ['bromley','hounslow']; IF monikers.grep(c.cobrand.moniker).size AND thing == 'council'; 'Get updates of reports in ' _ c.cobrand.moniker.ucfirst; + ELSIF c.cobrand.moniker == 'isleofwight'; + 'Get updates of reports on the Isle of Wight'; ELSIF c.cobrand.moniker == 'bromley'; 'Get updates of reports in this ward'; ELSIF c.cobrand.is_council; diff --git a/templates/web/isleofwight/report/_council_sent_info.html b/templates/web/isleofwight/report/_council_sent_info.html new file mode 100644 index 000000000..d9edac902 --- /dev/null +++ b/templates/web/isleofwight/report/_council_sent_info.html @@ -0,0 +1,17 @@ +[% SET duration_clause = problem.duration_string(c) %] +[% IF duration_clause || problem.can_display_external_id %] + <p class="council_sent_info"> + [%- IF problem.can_display_external_id %] + [%- IF duration_clause %] + [%- external_ref_clause = tprintf('Enquiry ref: %s', problem.external_id) %] + [%- ELSE %] + [%- external_ref_clause = tprintf(loc('%s ref: %s'), problem.external_body, problem.external_id) %] + [%- END %] + [%- END -%] + [% duration_clause %] + [%- IF external_ref_clause %] + [%- IF duration_clause %]. [% END %] + <strong>[% external_ref_clause %].</strong> + [%- END %] + </p> +[% END %] diff --git a/web/cobrands/fixmystreet/assets.js b/web/cobrands/fixmystreet/assets.js index 0b2205076..a0cf2e29d 100644 --- a/web/cobrands/fixmystreet/assets.js +++ b/web/cobrands/fixmystreet/assets.js @@ -1030,7 +1030,7 @@ fixmystreet.message_controller = (function() { function show_responsibility_error(id, asset_item, asset_type) { $("#js-roads-responsibility").removeClass("hidden"); $("#js-roads-responsibility .js-responsibility-message").addClass("hidden"); - var asset_strings = $('.js-roads-asset'); + var asset_strings = $(id).find('.js-roads-asset'); if (asset_item) { asset_strings.html('a <b class="asset-' + asset_type + '">' + asset_item + '</b>'); } else { diff --git a/web/cobrands/isleofwight/assets.js b/web/cobrands/isleofwight/assets.js index a68b0418b..9d5c8de50 100644 --- a/web/cobrands/isleofwight/assets.js +++ b/web/cobrands/isleofwight/assets.js @@ -4,9 +4,14 @@ if (!fixmystreet.maps) { return; } +var is_live = false; +if ( location.hostname === 'www.fixmystreet.com' || location.hostname === 'fms.islandroads.com' ) { + is_live = true; +} + var defaults = { http_options: { - url: "https://tilma.staging.mysociety.org/mapserver/iow", + url: is_live ? "https://tilma.mysociety.org/mapserver/iow": "https://staging.tilma.mysociety.org/mapserver/iow", params: { SERVICE: "WFS", VERSION: "1.1.0", |