diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 23 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/BathNES.pm | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Body.pm | 12 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequests.pm | 24 |
4 files changed, 61 insertions, 15 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 6f7214906..33404cb82 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -218,9 +218,14 @@ sub bodies : Path('bodies') : Args(0) { $c->forward('check_for_super_user'); $c->forward('/auth/check_csrf_token'); - my $params = $c->forward('body_params'); + my $values = $c->forward('body_params'); unless ( keys %{$c->stash->{body_errors}} ) { - my $body = $c->model('DB::Body')->create( $params ); + my $body = $c->model('DB::Body')->create( $values->{params} ); + if ($values->{extras}) { + $body->set_extra_metadata( $_ => $values->{extras}->{$_} ) + for keys %{$values->{extras}}; + $body->update; + } my @area_ids = $c->get_param_list('area_ids'); foreach (@area_ids) { $c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } ); @@ -396,9 +401,14 @@ sub update_contacts : Private { $c->forward('check_for_super_user'); $c->forward('/auth/check_csrf_token'); - my $params = $c->forward( 'body_params' ); + my $values = $c->forward( 'body_params' ); unless ( keys %{$c->stash->{body_errors}} ) { - $c->stash->{body}->update( $params ); + $c->stash->{body}->update( $values->{params} ); + if ($values->{extras}) { + $c->stash->{body}->set_extra_metadata( $_ => $values->{extras}->{$_} ) + for keys %{$values->{extras}}; + $c->stash->{body}->update; + } my @current = $c->stash->{body}->body_areas->all; my %current = map { $_->area_id => 1 } @current; my @area_ids = $c->get_param_list('area_ids'); @@ -465,7 +475,10 @@ sub body_params : Private { ); my %params = map { $_ => $c->get_param($_) || $defaults{$_} } keys %defaults; $c->forward('check_body_params', [ \%params ]); - return \%params; + my @extras = qw/fetch_all_problems/; + %defaults = map { $_ => '' } @extras; + my %extras = map { $_ => $c->get_param($_) || $defaults{$_} } @extras; + return { params => \%params, extras => \%extras }; } sub check_body_params : Private { diff --git a/perllib/FixMyStreet/Cobrand/BathNES.pm b/perllib/FixMyStreet/Cobrand/BathNES.pm index 02d491e0e..f83887469 100644 --- a/perllib/FixMyStreet/Cobrand/BathNES.pm +++ b/perllib/FixMyStreet/Cobrand/BathNES.pm @@ -190,5 +190,22 @@ sub enter_postcode_text { return 'Enter a location in ' . $self->council_area; } +sub categories_restriction { + my ($self, $rs) = @_; + # Categories covering BANES have a mixture of Open311 and Email + # send methods. BANES only want specific categories to be visible on their + # cobrand, not the email categories from FMS.com. + # The FMS.com categories have a devolved send_method set to Email, so we can + # filter these out. + # NB. BANES have a 'Street Light Fault' category that has its + # send_method set to 'Email::BathNES' (to use a custom template) which must + # be show on the cobrand. + return $rs->search( { -or => [ + 'me.send_method' => undef, # Open311 categories + 'me.send_method' => '', # Open311 categories that have been edited in the admin + 'me.send_method' => 'Email::BathNES', # Street Light Fault + ] } ); +} + 1; diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm index 0b11f2771..74a38f225 100644 --- a/perllib/FixMyStreet/DB/Result/Body.pm +++ b/perllib/FixMyStreet/DB/Result/Body.pm @@ -50,6 +50,8 @@ __PACKAGE__->add_columns( { data_type => "boolean", default_value => \"false", is_nullable => 1 }, "convert_latlong", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "extra", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( @@ -124,13 +126,17 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07035 @ 2018-03-15 12:38:36 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:rturOWpYmPRO0yE9yWHXjA +# Created by DBIx::Class::Schema::Loader v0.07035 @ 2018-04-05 14:29:33 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:HV8IM2C1ErrpvXoRTZ1B1Q + +__PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); +__PACKAGE__->rabx_column('extra'); use Moo; use namespace::clean; -with 'FixMyStreet::Roles::Translatable'; +with 'FixMyStreet::Roles::Translatable', + 'FixMyStreet::Roles::Extra'; sub url { my ( $self, $c, $args ) = @_; diff --git a/perllib/Open311/GetServiceRequests.pm b/perllib/Open311/GetServiceRequests.pm index 78e9647fa..48e35acab 100644 --- a/perllib/Open311/GetServiceRequests.pm +++ b/perllib/Open311/GetServiceRequests.pm @@ -9,6 +9,7 @@ use DateTime::Format::W3CDTF; has system_user => ( is => 'rw' ); has start_date => ( is => 'ro', default => sub { undef } ); has end_date => ( is => 'ro', default => sub { undef } ); +has fetch_all => ( is => 'rw', default => 0 ); has verbose => ( is => 'ro', default => 0 ); has schema => ( is =>'ro', lazy => 1, default => sub { FixMyStreet::DB->schema->connect } ); has convert_latlong => ( is => 'rw', default => 0 ); @@ -26,19 +27,28 @@ sub fetch { ); while ( my $body = $bodies->next ) { - - my $o = Open311->new( - endpoint => $body->endpoint, - api_key => $body->api_key, - jurisdiction => $body->jurisdiction, - ); + my $o = $self->create_open311_object( $body ); $self->system_user( $body->comment_user ); $self->convert_latlong( $body->convert_latlong ); + $self->fetch_all( $body->get_extra_metadata('fetch_all_problems') ); $self->create_problems( $o, $body ); } } +# this is so we can test +sub create_open311_object { + my ($self, $body) = @_; + + my $o = Open311->new( + endpoint => $body->endpoint, + api_key => $body->api_key, + jurisdiction => $body->jurisdiction, + ); + + return $o; +} + sub create_problems { my ( $self, $open311, $body ) = @_; @@ -49,7 +59,7 @@ sub create_problems { $args->{start_date} = DateTime::Format::W3CDTF->format_datetime( $self->start_date ); $args->{end_date} = DateTime::Format::W3CDTF->format_datetime( $self->end_date ); - } else { + } elsif ( !$self->fetch_all ) { my $end_dt = DateTime->now(); my $start_dt = $end_dt->clone; $start_dt->add( hours => -1 ); |