diff options
-rw-r--r-- | app.psgi | 2 | ||||
-rwxr-xr-x | bin/oxfordshire/send-rdi-emails | 1 | ||||
-rw-r--r-- | cpanfile | 1 | ||||
-rw-r--r-- | cpanfile.snapshot | 21 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 48 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/DefectTypes.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/ReportExtraFields.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/States.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/My.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Integrations/ExorRDI.pm | 28 | ||||
-rw-r--r-- | t/cobrand/oxfordshire.t | 33 | ||||
-rw-r--r-- | t/cobrand/zurich.t | 1 | ||||
-rw-r--r-- | templates/web/base/report/_inspect.html | 1 | ||||
-rw-r--r-- | templates/web/oxfordshire/report/_inspect_extra_info.html | 8 |
16 files changed, 101 insertions, 77 deletions
@@ -8,7 +8,7 @@ use Catalyst::Utils; my $app = FixMyStreet::App->apply_default_middlewares(FixMyStreet::App->psgi_app); builder { - enable 'Debug', panels => [ qw(Parameters Response DBIC::QueryLog CatalystLog Timer Memory FixMyStreet::Template) ] + enable 'Debug', panels => [ qw(Parameters Response DBIC::QueryLog CatalystLog Timer Memory FixMyStreet::Template LWP) ] if Catalyst::Utils::env_value( 'FixMyStreet::App', 'DEBUG' ); $app; diff --git a/bin/oxfordshire/send-rdi-emails b/bin/oxfordshire/send-rdi-emails index 9eff02715..ab58ff525 100755 --- a/bin/oxfordshire/send-rdi-emails +++ b/bin/oxfordshire/send-rdi-emails @@ -38,6 +38,7 @@ foreach my $inspector (@inspectors) { end_date => $end_date, inspection_date => $inspection_date, user => $inspector, + mark_as_processed => 1, }; my $rdi = FixMyStreet::Integrations::ExorRDI->new($params); try { @@ -118,6 +118,7 @@ requires 'File::Find::Rule'; # Modules used for development requires 'Plack::Middleware::Debug'; requires 'Plack::Middleware::Debug::DBIC::QueryLog'; +requires 'Plack::Middleware::Debug::LWP'; requires 'Plack::Middleware::Debug::Template'; recommends 'Linux::Inotify2' if $^O eq 'linux'; recommends 'Mac::FSEvents' if $^O eq 'darwin'; diff --git a/cpanfile.snapshot b/cpanfile.snapshot index ec9e8494c..238e54c1c 100644 --- a/cpanfile.snapshot +++ b/cpanfile.snapshot @@ -3350,6 +3350,16 @@ DISTRIBUTIONS Mozilla::CA 20110101 Net::HTTPS 6 perl 5.008001 + LWPx-Profile-0.2 + pathname: C/CR/CREIN/LWPx-Profile-0.2.tar.gz + provides: + LWPx::Profile 0.2 + requirements: + ExtUtils::MakeMaker 0 + LWP::UserAgent 0 + Time::HiRes 0 + strict 0 + warnings 0 Lexical-SealRequireHints-0.010 pathname: Z/ZE/ZEFRAM/Lexical-SealRequireHints-0.010.tar.gz provides: @@ -4853,6 +4863,17 @@ DISTRIBUTIONS Test::Fatal 0 Test::More 0.96 perl 5.008008 + Plack-Middleware-Debug-LWP-0.3 + pathname: C/CR/CREIN/Plack-Middleware-Debug-LWP-0.3.tar.gz + provides: + Plack::Middleware::Debug::LWP 0.3 + requirements: + ExtUtils::MakeMaker 0 + LWPx::Profile 0 + Plack::Middleware::Debug::Base 0 + parent 0 + strict 0 + warnings 0 Plack-Middleware-Debug-Template-1.00 pathname: M/MY/MYSOCIETY/Plack-Middleware-Debug-Template-1.00.tar.gz provides: diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index f1508f0b1..ed40f4565 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -27,7 +27,7 @@ Admin pages =cut -sub begin : Private { +sub auto : Private { my ( $self, $c ) = @_; $c->uri_disposition('relative'); @@ -44,10 +44,6 @@ sub begin : Private { if ( $c->cobrand->moniker eq 'zurich' ) { $c->cobrand->admin_type(); } -} - -sub auto : Private { - my ( $self, $c ) = @_; $c->forward('check_page_allowed'); } @@ -557,10 +553,10 @@ sub fetch_translations : Private { $c->stash->{translations} = $translations; } -sub lookup_body : Private { - my ( $self, $c ) = @_; +sub body : Chained('/') : PathPart('admin/body') : CaptureArgs(1) { + my ( $self, $c, $body_id ) = @_; - my $body_id = $c->stash->{body_id}; + $c->stash->{body_id} = $body_id; my $body = $c->model('DB::Body')->find($body_id); $c->detach( '/page_error_404_not_found', [] ) unless $body; @@ -572,30 +568,6 @@ sub lookup_body : Private { $c->stash->{example_pc} = $example_postcode; } } - - return 1; -} - -sub body_base : Chained('/') : PathPart('admin/body') : CaptureArgs(0) { } - -# This is for if the category name contains a '/' -sub category_edit_all : Chained('body_base') : PathPart('') { - my ( $self, $c, $body_id, @category ) = @_; - my $category = join( '/', @category ); - - $c->stash->{body_id} = $body_id; - $c->forward( 'lookup_body' ); - - my $contact = $c->stash->{body}->contacts->search( { category => $category } )->first; - $c->stash->{contact} = $contact; - - $c->stash->{template} = 'admin/category_edit.html'; - $c->forward( 'category_edit' ); -} - -sub body : Chained('body_base') : PathPart('') : CaptureArgs(1) { - my ( $self, $c, $body_id ) = @_; - $c->stash->{body_id} = $body_id; } sub edit_body : Chained('body') : PathPart('') : Args(0) { @@ -606,7 +578,6 @@ sub edit_body : Chained('body') : PathPart('') : Args(0) { } $c->forward( '/auth/get_csrf_token' ); - $c->forward( 'lookup_body' ); $c->forward( 'fetch_all_bodies' ); $c->forward( 'body_form_dropdowns' ); $c->forward('fetch_languages'); @@ -635,18 +606,15 @@ sub edit_body : Chained('body') : PathPart('') : Args(0) { return 1; } -sub category : Chained('body') : PathPart('') : CaptureArgs(1) { - my ( $self, $c, $category ) = @_; +sub category : Chained('body') : PathPart('') { + my ( $self, $c, @category ) = @_; + my $category = join( '/', @category ); $c->forward( '/auth/get_csrf_token' ); - $c->forward( 'lookup_body' ); + $c->stash->{template} = 'admin/category_edit.html'; my $contact = $c->stash->{body}->contacts->search( { category => $category } )->first; $c->stash->{contact} = $contact; -} - -sub category_edit : Chained('category') : PathPart('') : Args(0) { - my ( $self, $c ) = @_; $c->stash->{translation_col} = 'category'; $c->stash->{object} = $c->stash->{contact}; diff --git a/perllib/FixMyStreet/App/Controller/Admin/DefectTypes.pm b/perllib/FixMyStreet/App/Controller/Admin/DefectTypes.pm index ef4a0f219..5dab1da2c 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/DefectTypes.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/DefectTypes.pm @@ -6,12 +6,6 @@ use mySociety::ArrayUtils; BEGIN { extends 'Catalyst::Controller'; } -sub begin : Private { - my ( $self, $c ) = @_; - - $c->forward('/admin/begin'); -} - sub index : Path : Args(0) { my ( $self, $c ) = @_; diff --git a/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm b/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm index b03a2ab98..bdeecc1a3 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/ExorDefects.pm @@ -9,12 +9,6 @@ use FixMyStreet::Integrations::ExorRDI; BEGIN { extends 'Catalyst::Controller'; } -sub begin : Private { - my ( $self, $c ) = @_; - - $c->forward('/admin/begin'); -} - sub index : Path : Args(0) { my ( $self, $c ) = @_; @@ -59,6 +53,7 @@ sub download : Path('download') : Args(0) { inspection_date => $start_date, end_date => $end_date + $one_day, user => $c->get_param('user_id'), + mark_as_processed => 0, }; my $rdi = FixMyStreet::Integrations::ExorRDI->new($params); diff --git a/perllib/FixMyStreet/App/Controller/Admin/ReportExtraFields.pm b/perllib/FixMyStreet/App/Controller/Admin/ReportExtraFields.pm index d5ec64698..337fb4bed 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/ReportExtraFields.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/ReportExtraFields.pm @@ -6,12 +6,6 @@ use List::MoreUtils qw(uniq); BEGIN { extends 'Catalyst::Controller'; } -sub begin : Private { - my ( $self, $c ) = @_; - - $c->forward('/admin/begin'); -} - sub index : Path : Args(0) { my ( $self, $c ) = @_; diff --git a/perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm b/perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm index 7b206690e..2613f6ae0 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/ResponsePriorities.pm @@ -5,12 +5,6 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } -sub begin : Private { - my ( $self, $c ) = @_; - - $c->forward('/admin/begin'); -} - sub index : Path : Args(0) { my ( $self, $c ) = @_; diff --git a/perllib/FixMyStreet/App/Controller/Admin/States.pm b/perllib/FixMyStreet/App/Controller/Admin/States.pm index e4c07c9ca..938692af0 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/States.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/States.pm @@ -4,12 +4,6 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } -sub begin : Private { - my ( $self, $c ) = @_; - - $c->forward('/admin/begin'); -} - sub index : Path : Args(0) { my ( $self, $c ) = @_; diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm index ea7aee016..5b80a4a08 100644 --- a/perllib/FixMyStreet/App/Controller/My.pm +++ b/perllib/FixMyStreet/App/Controller/My.pm @@ -19,9 +19,10 @@ Catalyst Controller. =cut -sub begin : Private { +sub auto : Private { my ($self, $c) = @_; $c->detach( '/auth/redirect' ) unless $c->user; + return 1; } =head2 index diff --git a/perllib/FixMyStreet/Integrations/ExorRDI.pm b/perllib/FixMyStreet/Integrations/ExorRDI.pm index 4ce888cff..fc7e9d673 100644 --- a/perllib/FixMyStreet/Integrations/ExorRDI.pm +++ b/perllib/FixMyStreet/Integrations/ExorRDI.pm @@ -23,7 +23,7 @@ use Scalar::Util 'blessed'; use FixMyStreet::DB; use namespace::clean; -has [qw(start_date end_date inspection_date)] => ( +has [qw(start_date end_date inspection_date mark_as_processed)] => ( is => 'ro', required => 1, ); @@ -43,13 +43,23 @@ sub construct { my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker('oxfordshire')->new; my $dtf = $cobrand->problems->result_source->storage->datetime_parser; + my $missed_cutoff = DateTime->now - DateTime::Duration->new( hours => 24 ); my %params = ( -and => [ state => [ 'action scheduled' ], external_id => { '!=' => undef }, - '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) }, + -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) }, + ] + ] ] ); @@ -198,6 +208,16 @@ sub construct { 0, 0, 0 # error counts, always zero ); + if ($self->mark_as_processed) { + # Mark all these problems are having been included in an RDI + my $now = DateTime->now->strftime( '%Y-%m-%d %H:%M' ); + $problems->reset; + while ( my $report = $problems->next ) { + $report->set_extra_metadata('rdi_processed' => $now); + $report->update; + } + } + # The RDI format is very weird CSV - each line must be wrapped in # double quotes. return join "", map { "\"$_\"\r\n" } @$body; diff --git a/t/cobrand/oxfordshire.t b/t/cobrand/oxfordshire.t index 90fa8ccbf..e6c16950c 100644 --- a/t/cobrand/oxfordshire.t +++ b/t/cobrand/oxfordshire.t @@ -1,3 +1,5 @@ +use FixMyStreet::Integrations::ExorRDI; + use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; @@ -47,6 +49,8 @@ my $superuser = $mech->create_user_ok('superuser@example.com', name => 'Super Us 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' => '.' } ], @@ -97,7 +101,6 @@ subtest 'Exor file looks okay' => sub { $dt2->set_extra_metadata(activity_code => 'S'); $dt2->set_extra_metadata(defect_code => 'ACC2'); $dt2->update; - my @problems = FixMyStreet::DB->resultset('Problem')->search({}, { rows => 3 })->all; my $i = 123; foreach my $problem (@problems) { $problem->update({ state => 'action scheduled', external_id => $i }); @@ -142,9 +145,37 @@ subtest 'Exor file looks okay' => sub { "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' ], + }, sub { + my $date = DateTime->new(year => 2017, month => 5, day => 5, hour => 12); + 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; + + my $now = DateTime->now->strftime( '%Y-%m-%d %H:%M' ); + foreach my $problem (@problems) { + $problem->discard_changes; + is $problem->get_extra_metadata('rdi_processed'), $now, "Problem was logged as sent in RDI"; + } + }; +}; + subtest 'response times messages displayed' => sub { my $oxfordshire = $mech->create_body_ok( 2237, 'Oxfordshire County Council' diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 225fbfd41..03b20b087 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -695,6 +695,7 @@ subtest "only superuser can edit bodies" => sub { $user = $mech->log_in_ok( 'dm1@example.org' ); FixMyStreet::override_config { ALLOWED_COBRANDS => [ 'zurich' ], + MAPIT_URL => 'http://mapit.zurich/', }, sub { $mech->get( '/admin/body/' . $zurich->id ); }; diff --git a/templates/web/base/report/_inspect.html b/templates/web/base/report/_inspect.html index a275555f1..436c89e4a 100644 --- a/templates/web/base/report/_inspect.html +++ b/templates/web/base/report/_inspect.html @@ -171,6 +171,7 @@ [% 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> diff --git a/templates/web/oxfordshire/report/_inspect_extra_info.html b/templates/web/oxfordshire/report/_inspect_extra_info.html new file mode 100644 index 000000000..6151d79ae --- /dev/null +++ b/templates/web/oxfordshire/report/_inspect_extra_info.html @@ -0,0 +1,8 @@ +<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> |