diff options
23 files changed, 16 insertions, 780 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ddb95d9d..4429bb95e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ here’ link. - Allow contact send method to be unset always. - Fix z-index stacking bug that was causing unclickable RSS icons on /alert page. #2624 + - Fix issue with inspector duplication workflow. - Front end improvements: - Set report title autocomplete to off to prevent email autocompleting - Development improvements: diff --git a/bin/oxfordshire/send-rdi-emails b/bin/oxfordshire/send-rdi-emails deleted file mode 100755 index 9cc3e5502..000000000 --- a/bin/oxfordshire/send-rdi-emails +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env perl - -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 DateTime; -use Try::Tiny; -use FixMyStreet; -use FixMyStreet::Cobrand; -use FixMyStreet::Email; -use FixMyStreet::Integrations::ExorRDI; - -my $end_date = DateTime->now( time_zone => FixMyStreet->time_zone || FixMyStreet->local_time_zone ) - ->truncate(to => 'hour')->set_hour(16); -my $start_date = $end_date->clone->subtract(days => 1); -my $inspection_date = $end_date; # All inspections are considered to have happened on the same date. - -my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('oxfordshire')->new; -$cobrand->set_lang_and_domain('en-gb', 1); -my @inspectors = $cobrand->users->search({ - 'user_body_permissions.permission_type' => 'report_inspect' -}, { - join => 'user_body_permissions', - distinct => 1, -})->all; - -foreach my $inspector (@inspectors) { - my $params = { - start_date => $start_date, - end_date => $end_date, - inspection_date => $inspection_date, - user => $inspector, - mark_as_processed => 1, - }; - my $email_params = { - start_date => $start_date, - end_date => $end_date, - user => $inspector, - staging_site => FixMyStreet->config('STAGING_SITE'), - }; - my $rdi = FixMyStreet::Integrations::ExorRDI->new($params); - try { - my $hdrs = { - To => join('', 'fms', '_', 'admin', '@', $cobrand->admin_user_domain), - _attachments_ => [ { - body_str => $rdi->construct, - attributes => { - filename => $rdi->filename, - charset => 'utf-8', - encoding => 'quoted-printable', - content_type => 'text/csv', - name => $rdi->filename, - } - } ], - }; - - my $result = FixMyStreet::Email::send_cron( - FixMyStreet::DB->schema, - "rdi.txt", $email_params, $hdrs, - undef, 0, $cobrand, - ); - if ($result) { - say "Failed to send inspection for " . $inspector->id; - } - } catch { - die $_ unless $_ =~ /FixMyStreet::Integrations::ExorRDI::Error/; - # Nothing to report, continue - } -} - -1; diff --git a/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm b/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm deleted file mode 100644 index 0026acb9c..000000000 --- a/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm +++ /dev/null @@ -1,81 +0,0 @@ -package FixMyStreet::App::Controller::Admin::ExorDefects; -use Moose; -use namespace::autoclean; - -use DateTime; -use Try::Tiny; -use FixMyStreet::Integrations::ExorRDI; -use FixMyStreet::DateRange; - -BEGIN { extends 'Catalyst::Controller'; } - - -sub index : Path : Args(0) { - my ( $self, $c ) = @_; - - foreach (qw(error_message start_date end_date user_id)) { - if ( defined $c->flash->{$_} ) { - $c->stash->{$_} = $c->flash->{$_}; - } - } - - my @inspectors = $c->cobrand->users->search({ - 'user_body_permissions.permission_type' => 'report_inspect' - }, { - join => 'user_body_permissions', - distinct => 1, - } - )->all; - $c->stash->{inspectors} = \@inspectors; - - # Default start/end date is today - my $now = DateTime->now( time_zone => - FixMyStreet->time_zone || FixMyStreet->local_time_zone ); - $c->stash->{start_date} ||= $now; - $c->stash->{end_date} ||= $now; - -} - -sub download : Path('download') : Args(0) { - my ( $self, $c ) = @_; - - if ( !$c->cobrand->can('exor_rdi_link_id') ) { - # This only works on the Oxfordshire cobrand currently. - $c->detach( '/page_error_404_not_found', [] ); - } - - my $range = FixMyStreet::DateRange->new( - start_date => $c->get_param('start_date'), - end_date => $c->get_param('end_date'), - parser => DateTime::Format::Strptime->new( pattern => '%Y-%m-%d' ), - ); - - my $params = { - start_date => $range->start, - inspection_date => $range->start, - end_date => $range->end, - user => $c->get_param('user_id'), - mark_as_processed => 0, - }; - my $rdi = FixMyStreet::Integrations::ExorRDI->new($params); - - try { - my $out = $rdi->construct; - $c->res->content_type('text/csv; charset=utf-8'); - $c->res->header('content-disposition' => "attachment; filename=" . $rdi->filename); - $c->res->body( $out ); - } catch { - die $_ unless $_ =~ /FixMyStreet::Integrations::ExorRDI::Error/; - if ($params->{user}) { - $c->flash->{error_message} = _("No inspections by that inspector in the selected date range."); - } else { - $c->flash->{error_message} = _("No inspections in the selected date range."); - } - $c->flash->{start_date} = $params->{start_date}; - $c->flash->{end_date} = $params->{end_date}; - $c->flash->{user_id} = $params->{user}; - $c->res->redirect( $c->uri_for( '' ) ); - }; -} - -1; diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 662f865c3..692379de6 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -475,14 +475,6 @@ sub inspect : Private { }; $c->user->create_alert($problem->id, $options); } - - # If the state has been changed to action scheduled and they've said - # they want to raise a defect, consider the report to be inspected. - if ($problem->state eq 'action scheduled' && $c->get_param('raise_defect') && !$problem->get_extra_metadata('inspected')) { - $update_params{extra} = { 'defect_raised' => 1 }; - $problem->set_extra_metadata( inspected => 1 ); - $c->forward( '/admin/log_edit', [ $problem->id, 'problem', 'inspected' ] ); - } } $problem->non_public($c->get_param('non_public') ? 1 : 0); @@ -523,14 +515,6 @@ sub inspect : Private { } } - if ($permissions->{report_inspect}) { - if ( $c->get_param('defect_type') ) { - $problem->defect_type($problem->defect_types->find($c->get_param('defect_type'))); - } else { - $problem->defect_type(undef); - } - } - $c->cobrand->call_hook(report_inspect_update_extra => $problem); if ($valid) { diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 5407ec937..03623259c 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -706,12 +706,6 @@ sub setup_categories_and_bodies : Private { # keysort does not appear to obey locale so use strcoll (see i18n.t) @contacts = sort { strcoll( $a->category, $b->category ) } @contacts; - # Get defect types for inspectors - if ($c->cobrand->can('council_area_id')) { - my $category_defect_types = FixMyStreet::App->model('DB::DefectType')->by_categories($c->cobrand->council_area_id, @contacts); - $c->stash->{category_defect_types} = $category_defect_types; - } - my %seen; foreach my $contact (@contacts) { diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index ea6f14904..f99cdf84d 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -164,11 +164,6 @@ sub admin_pages { my $pages = $self->next::method(); - # Oxfordshire have a custom admin page for downloading reports in an Exor- - # friendly format which anyone with report_instruct permission can use. - if ( $user->has_body_permission_to('report_instruct') ) { - $pages->{exordefects} = [ ('Download Exor RDI'), 10 ]; - } if ( $user->has_body_permission_to('defect_type_edit') ) { $pages->{defecttypes} = [ ('Defect Types'), 11 ]; $pages->{defecttype_edit} = [ undef, undef ]; @@ -177,16 +172,6 @@ sub admin_pages { return $pages; } -sub defect_types { - { - SFP2 => "SFP2: sweep and fill <1m2", - POT2 => "POT2", - }; -} - -sub exor_rdi_link_id { 1989169 } -sub exor_rdi_link_length { 50 } - sub reputation_increment_states { return { 'action scheduled' => 1, diff --git a/perllib/FixMyStreet/Integrations/ExorRDI.pm b/perllib/FixMyStreet/Integrations/ExorRDI.pm deleted file mode 100644 index ce59df9be..000000000 --- a/perllib/FixMyStreet/Integrations/ExorRDI.pm +++ /dev/null @@ -1,250 +0,0 @@ -package FixMyStreet::Integrations::ExorRDI::Error; - -use Moo; -with 'Throwable'; - -has message => (is => 'ro'); - -package FixMyStreet::Integrations::ExorRDI::CSV; - -use parent 'Text::CSV'; - -sub add_row { - my ($self, $data, @data) = @_; - $self->combine(@data); - push @$data, $self->string; -} - -package FixMyStreet::Integrations::ExorRDI; - -use DateTime; -use Moo; -use Scalar::Util 'blessed'; -use FixMyStreet::DB; -use namespace::clean; - -has [qw(start_date end_date inspection_date mark_as_processed)] => ( - is => 'ro', - required => 1, -); - -has user => ( - is => 'ro', - coerce => sub { - return $_[0] if blessed($_[0]) && $_[0]->isa('FixMyStreet::DB::Result::User'); - FixMyStreet::DB->resultset('User')->find( { id => $_[0] } ) - if $_[0]; - }, -); - -sub construct { - my $self = shift; - - my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('oxfordshire')->new; - my $dtf = $cobrand->problems->result_source->storage->datetime_parser; - my $now = DateTime->now( - time_zone => FixMyStreet->time_zone || FixMyStreet->local_time_zone - ); - - my $tmo = $cobrand->traffic_management_options; - my %tm_lookup = map { $tmo->[$_] => $_ + 1 } 0..$#$tmo; - - my $missed_cutoff = $now - DateTime::Duration->new( hours => 24 ); - my %params = ( - -and => [ - state => [ 'action scheduled' ], - external_id => { '!=' => undef }, - -or => [ - -and => [ - 'admin_log_entries.action' => 'inspected', - 'admin_log_entries.whenedited' => { '>=', $dtf->format_datetime($self->start_date) }, - 'admin_log_entries.whenedited' => { '<=', $dtf->format_datetime($self->end_date) }, - ], - -and => [ - extra => { -not_like => '%rdi_processed%' }, - 'admin_log_entries.action' => 'inspected', - 'admin_log_entries.whenedited' => { '<=', $dtf->format_datetime($missed_cutoff) }, - ] - ] - ] - ); - - $params{'admin_log_entries.user_id'} = $self->user->id if $self->user; - - my $problems = $cobrand->problems->search( - \%params, - { - join => 'admin_log_entries', - distinct => 1, - } - ); - FixMyStreet::Integrations::ExorRDI::Error->throw unless $problems->count; - - # A single RDI file might contain inspections from multiple inspectors, so - # we need to group inspections by inspector within G records. - my $inspectors = {}; - my $inspector_initials = {}; - while ( my $report = $problems->next ) { - my $user = $report->inspection_log_entry->user; - $inspectors->{$user->id} ||= []; - push @{ $inspectors->{$user->id} }, $report; - unless ( $inspector_initials->{$user->id} ) { - $inspector_initials->{$user->id} = $user->get_extra_metadata('initials'); - } - } - - my $csv = FixMyStreet::Integrations::ExorRDI::CSV->new({ binary => 1, eol => "" }); - - my $p_count = 0; - my $link_id = $cobrand->exor_rdi_link_id; - - # RDI first line is always the same - my $body = []; - $csv->add_row($body, "1", "1.8", "1.0.0.0", "ENHN", ""); - - my $i = 0; - foreach my $inspector_id (keys %$inspectors) { - my $inspections = $inspectors->{$inspector_id}; - my $initials = $inspector_initials->{$inspector_id} || "XX"; - - my %body_by_activity_code; - foreach my $report (@$inspections) { - my ($eastings, $northings) = $report->local_coords; - - my $location = "${eastings}E ${northings}N"; - $location = "[DID NOT USE MAP] $location" unless $report->used_map; - my $closest_address = $cobrand->find_closest($report); - if (%$closest_address) { - $location .= " Nearest road: $closest_address->{name}." if $closest_address->{name}; - $location .= " Nearest postcode: $closest_address->{postcode}{postcode}." if $closest_address->{postcode}; - } - - my $traffic_information = $report->get_extra_metadata('traffic_information') || 'none'; - my $description = sprintf("%s %s %s %s", - $report->external_id || "", - $initials, - 'TM' . ($tm_lookup{$traffic_information} || '0'), - $report->get_extra_metadata('detailed_information') || ""); - # Maximum length of 180 characters total - $description = substr($description, 0, 180); - my $activity_code = $report->defect_type ? - $report->defect_type->get_extra_metadata('activity_code') - : 'MC'; - $body_by_activity_code{$activity_code} ||= []; - - $csv->add_row($body_by_activity_code{$activity_code}, - "I", # beginning of defect record - $activity_code, # activity code - minor carriageway, also FC (footway) - "", # empty field, can also be A (seen on MC) or B (seen on FC) - sprintf("%03d", ++$i), # randomised sequence number - $location, # defect location field, which we don't capture from inspectors - $report->inspection_log_entry->whenedited->strftime("%H%M"), # defect time raised - "","","","","","","", # empty fields - "TM $traffic_information", - $description, # defect description - ); - - my $defect_type = $report->defect_type ? - $report->defect_type->get_extra_metadata('defect_code') - : 'SFP2'; - $csv->add_row($body_by_activity_code{$activity_code}, - "J", # georeferencing record - $defect_type, # defect type - SFP2: sweep and fill <1m2, POT2 also seen - $report->response_priority ? - $report->response_priority->external_id : - "2", # priority of defect - "","", # empty fields - $eastings, # eastings - $northings, # northings - "","","","","" # empty fields - ); - - my $m_row_activity_code = $activity_code; - $m_row_activity_code .= 'I' if length $activity_code == 1; - - $csv->add_row($body_by_activity_code{$activity_code}, - "M", # bill of quantities record - "resolve", # permanent repair - "","", # empty fields - "/C$m_row_activity_code", # /C + activity code + perhaps an "I" - "", "" # empty fields - ); - } - - foreach my $activity_code (sort keys %body_by_activity_code) { - $csv->add_row($body, - "G", # start of an area/sequence - $link_id, # area/link id, fixed value for our purposes - "","", # must be empty - $initials, # inspector initials - $self->inspection_date->strftime("%y%m%d"), # date of inspection yymmdd - "1600", # time of inspection hhmm, set to static value for now - "D", # inspection variant, should always be D - "INS", # inspection type, always INS - "N", # Area of the county - north (N) or south (S) - "", "", "", "" # empty fields - ); - - $csv->add_row($body, - "H", # initial inspection type - $activity_code # e.g. MC = minor carriageway - ); - - # List of I/J/M entries from above - push @$body, @{$body_by_activity_code{$activity_code}}; - - # end this group of defects with a P record - $csv->add_row($body, - "P", # end of area/sequence - 0, # always 0 - 999999, # charging code, always 999999 in OCC - ); - $p_count++; - } - } - - # end the RDI file with an X record - my $record_count = $i; - $csv->add_row($body, - "X", # end of inspection record - $p_count, - $p_count, - $record_count, # number of I records - $record_count, # number of J records - 0, 0, 0, # always zero - $record_count, # number of M records - 0, # always zero - $p_count, - 0, 0, 0 # error counts, always zero - ); - - if ($self->mark_as_processed) { - # Mark all these problems are having been included in an RDI - $problems->reset; - while ( my $report = $problems->next ) { - $report->set_extra_metadata('rdi_processed' => $now->strftime( '%Y-%m-%d %H:%M' )); - $report->update; - } - } - - # The RDI format is very weird CSV - each line must be wrapped in - # double quotes. - return join "", map { "\"$_\"\r\n" } @$body; -} - -has filename => ( - is => 'lazy', - default => sub { - my $self = shift; - my $start = $self->inspection_date->strftime("%Y%m%d"); - my $end = $self->end_date->strftime("%Y%m%d"); - my $filename = sprintf("exor_defects-%s-%s.rdi", $start, $end); - if ( $self->user ) { - my $initials = $self->user->get_extra_metadata("initials") || ""; - $filename = sprintf("exor_defects-%s-%s-%s.rdi", $start, $end, $initials); - } - return $filename; - }, -); - -1; diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm index ecd461cd9..59de86db1 100644 --- a/perllib/FixMyStreet/Script/Reports.pm +++ b/perllib/FixMyStreet/Script/Reports.pm @@ -159,7 +159,6 @@ sub send(;$) { $reputation_threshold_met = $user_reputation >= $reputation_threshold; } unless ( - $row->get_extra_metadata('inspected') || $row->user->has_permission_to( trusted => $row->bodies_str_ids ) || $reputation_threshold_met ) { diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t index ef05288c7..b6498e840 100644 --- a/t/app/controller/report_inspect.t +++ b/t/app/controller/report_inspect.t @@ -8,14 +8,6 @@ my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council', { can_be_de my $contact = $mech->create_contact_ok( body_id => $oxon->id, category => 'Cows', email => 'cows@example.net' ); my $contact2 = $mech->create_contact_ok( body_id => $oxon->id, category => 'Sheep', email => 'SHEEP', send_method => 'Open311' ); my $contact3 = $mech->create_contact_ok( body_id => $oxon->id, category => 'Badgers', email => 'badgers@example.net' ); -my $dt = FixMyStreet::DB->resultset("DefectType")->create({ - body => $oxon, - name => 'Small Defect', description => "Teeny", -}); -FixMyStreet::DB->resultset("ContactDefectType")->create({ - contact => $contact, - defect_type => $dt, -}); my $rp = FixMyStreet::DB->resultset("ResponsePriority")->create({ body => $oxon, name => 'High Priority', @@ -144,7 +136,7 @@ FixMyStreet::override_config { $mech->get_ok("/report/$report_id"); $mech->submit_form_ok({ button => 'save', with_fields => { public_update => "This is a public update.", include_update => "1", - state => 'action scheduled', raise_defect => 1, + state => 'action scheduled', } }); $mech->get_ok("/report/$report_id"); $mech->submit_form_ok({ with_fields => { @@ -153,28 +145,23 @@ FixMyStreet::override_config { $report->discard_changes; my $comment = ($report->comments( undef, { order_by => { -desc => 'id' } } )->all)[1]->text; is $comment, "This is a public update.", 'Update was created'; - is $report->get_extra_metadata('inspected'), 1, 'report marked as inspected'; is $report->user->get_extra_metadata('reputation'), $reputation, "User reputation wasn't changed"; $mech->get_ok("/report/$report_id"); my $meta = $mech->extract_update_metas; like $meta->[0], qr/State changed to: Action scheduled/, 'First update mentions action scheduled'; - like $meta->[2], qr/Posted by .*defect raised/, 'Update mentions defect raised'; $user->unset_extra_metadata('categories'); $user->update; }; subtest "test update is required when instructing" => sub { - $report->unset_extra_metadata('inspected'); $report->update; - $report->inspection_log_entry->delete; $report->comments->delete_all; $mech->get_ok("/report/$report_id"); $mech->submit_form_ok({ button => 'save', with_fields => { public_update => undef, include_update => "1" } }); is_deeply $mech->page_errors, [ "Please provide a public update for this report." ], 'errors match'; $report->discard_changes; is $report->comments->count, 0, "Update wasn't created"; - is $report->get_extra_metadata('inspected'), undef, 'report not marked as inspected'; }; subtest "test location changes" => sub { @@ -448,24 +435,6 @@ FixMyStreet::override_config { is $report->response_priority->id, $rp->id, 'response priority set'; }; - subtest "check can set defect type for category when changing from category with no defect types" => sub { - $report->update({ category => 'Sheep', defect_type_id => undef }); - $user->user_body_permissions->delete; - $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' }); - $mech->get_ok("/report/$report_id"); - $mech->submit_form_ok({ - button => 'save', - with_fields => { - include_update => 0, - defect_type => $dt->id, - category => 'Cows', - } - }); - $report->discard_changes; - is $report->defect_type->id, $dt->id, 'defect type set'; - $report->update({ defect_type_id => undef }); - }; - subtest "check can't set priority that isn't for a category" => sub { $report->discard_changes; $report->update({ category => 'Cows', response_priority_id => $rp->id }); @@ -627,7 +596,6 @@ FixMyStreet::override_config { subtest "test positive reputation" => sub { $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_instruct' }); - $report->unset_extra_metadata('inspected'); $report->update; $report->inspection_log_entry->delete if $report->inspection_log_entry; my $reputation = $report->user->get_extra_metadata("reputation") || 0; @@ -636,24 +604,16 @@ FixMyStreet::override_config { state => 'in progress', include_update => undef, } }); $report->discard_changes; - is $report->get_extra_metadata('inspected'), undef, 'report not marked as inspected'; $mech->submit_form_ok({ button => 'save', with_fields => { state => 'action scheduled', include_update => undef, } }); $report->discard_changes; - is $report->get_extra_metadata('inspected'), undef, 'report not marked as inspected'; is $report->user->get_extra_metadata('reputation'), $reputation+1, "User reputation was increased"; $mech->submit_form_ok({ button => 'save', with_fields => { state => 'action scheduled', include_update => undef, - raise_defect => 1, } }); - $report->discard_changes; - is $report->get_extra_metadata('inspected'), 1, 'report marked as inspected'; - $mech->get_ok("/report/$report_id"); - my $meta = $mech->extract_update_metas; - like $meta->[-1], qr/Updated by .*defect raised/, 'Update mentions defect raised'; }; subtest "Oxfordshire-specific traffic management options are shown" => sub { @@ -697,7 +657,6 @@ FixMyStreet::override_config { priority => $rp->id, include_update => '1', detailed_information => 'XXX164XXXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', - defect_type => '', traffic_information => '' }; my $values = $mech->visible_form_values('report_inspect_form'); diff --git a/t/app/sendreport/inspection_required.t b/t/app/sendreport/inspection_required.t index 64d6f70ee..5eff516f5 100644 --- a/t/app/sendreport/inspection_required.t +++ b/t/app/sendreport/inspection_required.t @@ -34,21 +34,8 @@ subtest "Report isn't sent if uninspected" => sub { is $report->whensent, undef, "Report hasn't been sent"; }; -subtest 'Report is sent when inspected' => sub { - $mech->clear_emails_ok; - $report->set_extra_metadata(inspected => 1); - $report->update; - - FixMyStreet::Script::Reports::send(); - - $report->discard_changes; - $mech->email_count_is( 1 ); - ok $report->whensent, 'Report marked as sent'; -}; - subtest 'Uninspected report is sent when made by trusted user' => sub { $mech->clear_emails_ok; - $report->unset_extra_metadata('inspected'); $report->whensent( undef ); $report->update; @@ -63,7 +50,6 @@ subtest 'Uninspected report is sent when made by trusted user' => sub { $report->discard_changes; $mech->email_count_is( 1 ); ok $report->whensent, 'Report marked as sent'; - is $report->get_extra_metadata('inspected'), undef, 'Report not marked as inspected'; }; subtest "Uninspected report isn't sent when user rep is too low" => sub { @@ -94,7 +80,6 @@ subtest 'Uninspected report is sent when user rep is high enough' => sub { $report->discard_changes; $mech->email_count_is( 1 ); ok $report->whensent, 'Report marked as sent'; - is $report->get_extra_metadata('inspected'), undef, 'Report not marked as inspected'; }; done_testing(); diff --git a/t/cobrand/oxfordshire.t b/t/cobrand/oxfordshire.t index 2625aa0d5..b8422a28b 100644 --- a/t/cobrand/oxfordshire.t +++ b/t/cobrand/oxfordshire.t @@ -1,6 +1,4 @@ - use Test::MockModule; -use FixMyStreet::Integrations::ExorRDI; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -47,145 +45,8 @@ subtest 'check /around?ajax defaults to open reports only' => sub { } }; -my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super User', is_superuser => 1); -my $inspector = $mech->create_user_ok('inspector@example.com', name => 'Inspector'); -$inspector->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' }); - my @problems = FixMyStreet::DB->resultset('Problem')->search({}, { rows => 3 })->all; -subtest 'Exor RDI download appears on Oxfordshire cobrand admin' => sub { - FixMyStreet::override_config { - ALLOWED_COBRANDS => [ { 'oxfordshire' => '.' } ], - }, sub { - $mech->log_in_ok( $superuser->email ); - $mech->get_ok('/admin'); - $mech->content_contains("Download Exor RDI"); - } -}; - -subtest "Exor RDI download doesn't appear outside of Oxfordshire cobrand admin" => sub { - FixMyStreet::override_config { - ALLOWED_COBRANDS => [ { 'fixmystreet' => '.' } ], - }, sub { - $mech->log_in_ok( $superuser->email ); - $mech->get_ok('/admin'); - $mech->content_lacks("Download Exor RDI"); - } -}; - -subtest 'Exor file looks okay' => sub { - FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'oxfordshire' ], - MAPIT_URL => 'http://mapit.uk/', - }, sub { - $mech->log_in_ok( $superuser->email ); - $mech->get_ok('/admin/exordefects'); - $mech->submit_form_ok( { with_fields => { - start_date => '2017-05-05', - end_date => '2017-05-05', - user_id => $inspector->id, - } }, 'submit download'); - $mech->content_contains("No inspections by that inspector in the selected date range"); - - my $dt = FixMyStreet::DB->resultset('DefectType')->create({ - body => $oxon, - name => 'Footpath', - description => 'Footpath stuff', - }); - $dt->set_extra_metadata(activity_code => 'FC'); - $dt->set_extra_metadata(defect_code => 'SFP1'); - $dt->update; - my $dt2 = FixMyStreet::DB->resultset('DefectType')->create({ - body => $oxon, - name => 'Accidental sign damage', - description => 'Accidental sign damage', - }); - $dt2->set_extra_metadata(activity_code => 'S'); - $dt2->set_extra_metadata(defect_code => 'ACC2'); - $dt2->update; - my $i = 123; - foreach my $problem (@problems) { - $problem->update({ state => 'action scheduled', external_id => $i }); - $problem->update({ defect_type => $dt }) if $i == 123; - $problem->set_extra_metadata(traffic_information => 'Signs and Cones') if $i == 124; - $problem->update({ defect_type => $dt2 }) if $i == 124; - FixMyStreet::DB->resultset('AdminLog')->create({ - admin_user => $inspector->name, - user => $inspector, - object_type => 'problem', - action => 'inspected', - object_id => $problem->id, - whenedited => DateTime->new(year => 2017, month => 5, day => 5, hour => 12), - }); - $i++; - } - $mech->submit_form_ok( { with_fields => { - start_date => '2017-05-05', - end_date => '2017-05-05', - user_id => $inspector->id, - } }, 'submit download'); - (my $rdi = $mech->content) =~ s/\r\n/\n/g; - $rdi =~ s/(I,[FMS]C?,,)\d+/$1XXX/g; # Remove unique ID figures, unknown order - is $rdi, <<EOF, "RDI file matches expected"; -"1,1.8,1.0.0.0,ENHN," -"G,1989169,,,XX,170505,1600,D,INS,N,,,," -"H,FC" -"I,FC,,XXX,"434970E 209683N Nearest postcode: OX28 4DS.",1200,,,,,,,,"TM none","123 XX TM0 "" -"J,SFP1,2,,,434970,209683,,,,," -"M,resolve,,,/CFC,," -"P,0,999999" -"G,1989169,,,XX,170505,1600,D,INS,N,,,," -"H,MC" -"I,MC,,XXX,"434970E 209683N Nearest postcode: OX28 4DS.",1200,,,,,,,,"TM none","125 XX TM0 "" -"J,SFP2,2,,,434970,209683,,,,," -"M,resolve,,,/CMC,," -"P,0,999999" -"G,1989169,,,XX,170505,1600,D,INS,N,,,," -"H,S" -"I,S,,XXX,"434970E 209683N Nearest postcode: OX28 4DS.",1200,,,,,,,,"TM Signs and Cones","124 XX TM1 "" -"J,ACC2,2,,,434970,209683,,,,," -"M,resolve,,,/CSI,," -"P,0,999999" -"X,3,3,3,3,0,0,0,3,0,3,0,0,0" -EOF - foreach my $problem (@problems) { - $problem->discard_changes; - is $problem->get_extra_metadata('rdi_processed'), undef, "Problem was not logged as sent in RDI"; - } - - } -}; - -subtest 'Reports are marked as inspected correctly' => sub { - FixMyStreet::override_config { - ALLOWED_COBRANDS => [ 'oxfordshire' ], - MAPIT_URL => 'http://mapit.uk/', - }, sub { - my $date = DateTime->new(year => 2017, month => 5, day => 5, hour => 12); - - my $now = DateTime->now( - time_zone => FixMyStreet->time_zone || FixMyStreet->local_time_zone - ); - my $datetime = Test::MockModule->new('DateTime'); - $datetime->mock('now', sub { $now }); - - my $params = { - start_date => $date, - end_date => $date, - inspection_date => $date, - user => $inspector, - mark_as_processed => 1, - }; - my $rdi = FixMyStreet::Integrations::ExorRDI->new($params); - $rdi->construct; - - foreach my $problem (@problems) { - $problem->discard_changes; - is $problem->get_extra_metadata('rdi_processed'), $now->strftime( '%Y-%m-%d %H:%M' ), "Problem was logged as sent in RDI"; - } - }; -}; - subtest 'can use customer reference to search for reports' => sub { FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'oxfordshire' ], @@ -195,7 +56,6 @@ subtest 'can use customer reference to search for reports' => sub { $problem->set_extra_metadata( customer_reference => 'ENQ12456' ); $problem->update; - $mech->log_out_ok; $mech->get_ok('/around?pc=ENQ12456'); is $mech->uri->path, '/report/' . $problem->id, 'redirects to report'; }; diff --git a/templates/web/base/admin/defecttypes/list.html b/templates/web/base/admin/defecttypes/list.html index ffff89eff..5730710d9 100644 --- a/templates/web/base/admin/defecttypes/list.html +++ b/templates/web/base/admin/defecttypes/list.html @@ -10,10 +10,9 @@ </tr> </thead> <tbody> - [% PROCESS 'defect_type/format.html' %] [% FOR d IN defect_types %] <tr> - <td> [% defect_type_format(defect_type=d) %] </td> + <td> [% d.name | html %] </td> <td> [% d.description | html %] </td> <td> [% UNLESS d.contacts.size %] diff --git a/templates/web/base/admin/exordefects/index.html b/templates/web/base/admin/exordefects/index.html deleted file mode 100644 index 65b2aa486..000000000 --- a/templates/web/base/admin/exordefects/index.html +++ /dev/null @@ -1,39 +0,0 @@ -[% INCLUDE 'admin/header.html' title=('Download Exor RDI') -%] - -[% IF error_message %] - <h2>Error</h2> - <p>[% error_message %]</p> -[% END %] - -<form method="get" action="[% c.uri_for('download') %]" enctype="application/x-www-form-urlencoded" accept-charset="utf-8"> - <div class="filters"> - <p> - <label for="start_date">[% ('Start Date:') %]</label><input type="date" class="form-control" - name="start_date" id="start_date" - value="[% start_date ? start_date.strftime( '%Y-%m-%d') : '' | html %]" /> - </p> - - <p> - <label for="end_date">[% ('End Date:') %]</label><input type="date" class="form-control" - name="end_date" id="end_date" size="5" - value="[% end_date ? end_date.strftime( '%Y-%m-%d') : '' | html %]" /> - </p> - - <p> - <label for="user_id">[% ('Inspector:') %]</label> - <select class="form-control" id='user_id' name='user_id'> - <option value=''>[% ('All inspectors') %]</option> - [% FOR inspector IN inspectors %] - <option value="[% inspector.id %]" [% 'selected' IF user_id == inspector.id %]>[% inspector.name %] ([% inspector.get_extra_metadata('initials') %])</option> - [% END %] - </select> - </p> - </div> - - <p> - <input type="submit" class="btn" size="30" value="Download RDI file" /> - </p> -</form> - - -[% INCLUDE 'admin/footer.html' %] diff --git a/templates/web/base/common_scripts.html b/templates/web/base/common_scripts.html index 60775fcae..56b2e6d2e 100644 --- a/templates/web/base/common_scripts.html +++ b/templates/web/base/common_scripts.html @@ -39,6 +39,11 @@ IF c.user_exists AND (c.user.from_body OR c.user.is_superuser); version('/jslib/jquery-1.7.2.min.js'), version('/cobrands/fixmystreet/staff.js') ); + IF bodyclass.match('mappage'); + scripts.push( + version('/js/duplicates.js') + ); + END; IF c.user.has_body_permission_to('planned_reports'); scripts.push( version('/cobrands/fixmystreet/offline.js'), diff --git a/templates/web/base/defect_type/format.html b/templates/web/base/defect_type/format.html deleted file mode 100644 index 3c0781501..000000000 --- a/templates/web/base/defect_type/format.html +++ /dev/null @@ -1,9 +0,0 @@ -[% -# This template can be overridden by cobrands if they've added extra fields -# to the DefectType model (e.g Cobrand::Oxfordshire->defect_type_extra_fields) -# which should be used to represent this DefectType -# to the user in the inspect form. -~%] -[% MACRO defect_type_format BLOCK ~%] -[%~ defect_type.name | html ~%] -[%~ END %]
\ No newline at end of file diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html index 10f3b6b84..c6873d473 100644 --- a/templates/web/base/report/_inspect.html +++ b/templates/web/base/report/_inspect.html @@ -1,6 +1,3 @@ -[% extra_js = [ - version('/js/duplicates.js'), -] -%] [% permissions = c.user.permissions(problem) %] [% second_column = BLOCK -%] <div id="side-inspect"> @@ -27,7 +24,6 @@ <p data-category="[% cat_name | html %]" [%~ IF cat_name != problem.category %] class="hidden"[% END %] data-priorities='[% priorities_by_category.$cat_name | html %]' - data-defect-types='[% category_defect_types.$cat_name | html %]' data-templates='[% templates_by_category.$cat_name | html %]'> [% IF cat_name == problem.category %] [% INCLUDE 'report/new/category_extras_fields.html' metas=category_extras.$cat_name hide_notices=1 show_hidden=1 %] @@ -38,32 +34,10 @@ [% END %] [% IF permissions.report_inspect %] - [% PROCESS 'defect_type/format.html' %] - <p> - <label for="defect_type">[% loc('Defect type') %]</label> - <select id="defect_type" name="defect_type" class="form-control"> - <option value=""[% ' selected' IF NOT problem.defect_type %]>-</option> - [% FOREACH defect_type IN problem.defect_types %] - <option[% ' selected' IF problem.defect_type_id == defect_type.id %] value="[% defect_type.id %]">[% defect_type_format() %]</option> - [% END %] - </select> - </p> - <p> <label for="state">[% loc('State') %]</label> [% INCLUDE 'report/inspect/state_groups_select.html' %] </p> - [% IF permissions.report_instruct AND NOT problem.get_extra_metadata('inspected') %] - <div id="js-inspect-action-scheduled" class="[% "hidden" UNLESS problem.state == 'action scheduled' %]"> - <p>[% loc('Do you want to automatically raise a defect?') %]</p> - <p class="segmented-control segmented-control--radio"> - <input type="radio" name="raise_defect" id="raise_defect_yes" value="1"> - <label class="btn" for="raise_defect_yes">[% loc('Yes') %]</label> - <input type="radio" name="raise_defect" id="raise_defect_no" value="0"> - <label class="btn" for="raise_defect_no">[% loc('No') %]</label> - </p> - </div> - [% END %] <div id="js-duplicate-reports" class="[% "hidden" UNLESS problem.duplicate_of %]"> <input type="hidden" name="duplicate_of" value="[% problem.duplicate_of.id %]"> <p class="[% "hidden" UNLESS problem.duplicate_of %]"><strong>[% loc('Duplicate of') %]</strong></p> @@ -132,15 +106,6 @@ [% INCLUDE 'report/inspect/public_update.html' %] [% END %] - [% IF problem.get_extra_metadata('inspected') %] - [% IF problem.whensent %] - <p>[% loc("<strong>Note:</strong> This report has been sent onwards for action. Any changes made won't be passed on.") %]</p> - [% ELSE %] - <p>[% loc("<strong>Note:</strong> This report hasn't yet been sent onwards for action. Any changes made may not be passed on.") %]</p> - [% END %] - [% TRY %][% INCLUDE 'report/_inspect_extra_info.html' %][% CATCH file %][% END %] - [% END %] - <p> <input type="hidden" name="token" value="[% csrf_token %]" /> [% IF permissions.planned_reports %] diff --git a/templates/web/base/report/new/category_extras_fields.html b/templates/web/base/report/new/category_extras_fields.html index e9237f83b..9ab9722cf 100644 --- a/templates/web/base/report/new/category_extras_fields.html +++ b/templates/web/base/report/new/category_extras_fields.html @@ -8,7 +8,7 @@ [% ELSIF meta.variable != 'false' || NOT hide_notices %] - <label for="[% cat_prefix %]form_[% meta_name %]">[% meta.description %]</label> + <label for="[% cat_prefix %]form_[% meta_name %]">[% meta.description OR meta.code %]</label> [% TRY %][% INCLUDE 'report/new/_category_extra_field_notice.html' %][% CATCH file %][% END %] [% IF field_errors.$x_meta_name %] <p class='form-error'>[% field_errors.$x_meta_name %]</p> diff --git a/templates/web/oxfordshire/defect_type/format.html b/templates/web/oxfordshire/defect_type/format.html deleted file mode 100644 index 9cbf2d873..000000000 --- a/templates/web/oxfordshire/defect_type/format.html +++ /dev/null @@ -1,4 +0,0 @@ -[% MACRO defect_type_format BLOCK ~%] -[%~ defect_type.get_extra_metadata('defect_code') | html %] - [% defect_type.get_extra_metadata('activity_code') | html %] -([% defect_type.name | html %]) -[%~ END %]
\ No newline at end of file diff --git a/templates/web/oxfordshire/footer_extra_js.html b/templates/web/oxfordshire/footer_extra_js.html index 1c48aa5cf..d3f1f03ee 100644 --- a/templates/web/oxfordshire/footer_extra_js.html +++ b/templates/web/oxfordshire/footer_extra_js.html @@ -3,7 +3,6 @@ IF bodyclass.match('mappage'); scripts.push( version('/cobrands/fixmystreet/assets.js'), version('/vendor/OpenLayers.Projection.OrdnanceSurvey.js'), - version('/cobrands/oxfordshire/js.js'), version('/cobrands/highways/assets.js'), version('/cobrands/fixmystreet-uk-councils/council_validation_rules.js'), ); diff --git a/templates/web/oxfordshire/report/_inspect_extra_info.html b/templates/web/oxfordshire/report/_inspect_extra_info.html deleted file mode 100644 index 6151d79ae..000000000 --- a/templates/web/oxfordshire/report/_inspect_extra_info.html +++ /dev/null @@ -1,8 +0,0 @@ -<p><small> -RDI sent: -[% IF problem.get_extra_metadata('rdi_processed') %] - [% problem.get_extra_metadata('rdi_processed') %] -[% ELSE %] - <strong>not yet sent</strong> -[% END %] -</small></p> diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index c13bf5c46..ea0e1e905 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -1491,9 +1491,6 @@ fixmystreet.display = { $('.two_column_sidebar').remove(); fixmystreet.mobile_reporting.remove_ui(); - if (fixmystreet.map.updateSize && ($twoColReport.length || $('html').hasClass('mobile'))) { - fixmystreet.map.updateSize(); - } // Insert this report's content if ($twoColReport.length) { @@ -1502,6 +1499,11 @@ fixmystreet.display = { } else { $sideReport.appendTo('#map_sidebar'); } + + if (fixmystreet.map.updateSize && ($twoColReport.length || $('html').hasClass('mobile'))) { + fixmystreet.map.updateSize(); + } + $('#map_sidebar').scrollTop(0); if ($("html").hasClass("mobile")) { $(document).scrollTop(0); @@ -1583,7 +1585,6 @@ fixmystreet.display = { if (fixmystreet.maps.setup_inspector) { fixmystreet.maps.setup_inspector(); - fixmystreet.map.updateSize(); } diff --git a/web/cobrands/fixmystreet/staff.js b/web/cobrands/fixmystreet/staff.js index 17bd54b8b..86e9bf449 100644 --- a/web/cobrands/fixmystreet/staff.js +++ b/web/cobrands/fixmystreet/staff.js @@ -1,23 +1,4 @@ fixmystreet.staff_set_up = { - action_scheduled_raise_defect: function() { - $("#report_inspect_form").find('[name=state]').on('change', function() { - if ($(this).val() !== "action scheduled") { - $("#js-inspect-action-scheduled").addClass("hidden"); - $('#raise_defect_yes').prop('required', false); - $('#defect_type').prop('required', false); - } else { - $("#js-inspect-action-scheduled").removeClass("hidden"); - $('#raise_defect_yes').prop('required', true); - var dt_required = $('#defect_type')[0].length > 1 && $('input[name=raise_defect]:checked').val(); - $('#defect_type').prop('required', dt_required ? true : false); - } - }); - $('input[name=raise_defect]').change(function() { - var dt_required = $('#defect_type')[0].length > 1 && this.value; - $('#defect_type').prop('required', dt_required ? true : false); - }); - }, - list_item_actions: function() { $('#js-reports-list').on('click', ':submit', function(e) { e.preventDefault(); @@ -195,8 +176,6 @@ fixmystreet.staff_set_up = { selector = "[data-category='" + category + "']", entry = $inspect_form.find(selector), $priorities = $('#problem_priority'), - $defect_types = $('#defect_type'), - defect_types_data = entry.data('defect-types') || [], priorities_data = entry.data('priorities') || [], curr_pri = $priorities.val(); @@ -204,7 +183,6 @@ fixmystreet.staff_set_up = { entry.removeClass("hidden"); populateSelect($priorities, priorities_data, 'priorities_type_format'); - populateSelect($defect_types, defect_types_data, 'defect_type_format'); updateTemplates({'category': category}); $priorities.val(curr_pri); }); @@ -386,15 +364,15 @@ $(fixmystreet).on('display:report', function() { fixmystreet.staff_set_up.response_templates(); if ($("#report_inspect_form").length) { fixmystreet.staff_set_up.report_page_inspect(); - fixmystreet.staff_set_up.action_scheduled_raise_defect(); } }); $(fixmystreet).on('report_new:category_change', function() { var $this = $('#form_category'); var category = $this.val(); + if (category === '-- Pick a category --') { return; } var prefill_reports = $this.data('prefill'); - var display_names = fixmystreet.reporting_data.display_names || {}; + var display_names = fixmystreet.reporting_data ? fixmystreet.reporting_data.display_names || {} : {}; var body = display_names[ $this.data('body') ] || $this.data('body'); if (prefill_reports) { @@ -477,9 +455,6 @@ $(fixmystreet).on('map:zoomend', function() { fixmystreet.utils = fixmystreet.utils || {}; $.extend(fixmystreet.utils, { - defect_type_format: function(data) { - return data.name; - }, priorities_type_format: function(data) { return data.name; }, diff --git a/web/cobrands/oxfordshire/js.js b/web/cobrands/oxfordshire/js.js deleted file mode 100644 index ad9639383..000000000 --- a/web/cobrands/oxfordshire/js.js +++ /dev/null @@ -1,5 +0,0 @@ -fixmystreet.utils = fixmystreet.utils || {}; - -fixmystreet.utils.defect_type_format = function(data) { - return data.extra.defect_code + ' - ' + data.extra.activity_code + ' (' + data.name + ')'; -}; |