diff options
-rw-r--r-- | db/schema.sql | 9 | ||||
-rw-r--r-- | db/schema_0023-add_can_be_devolved_and_category_config.sql | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 29 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyBarangay.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Contact.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Open311conf.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/EmptyHomes.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/NI.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 2 |
13 files changed, 75 insertions, 37 deletions
diff --git a/db/schema.sql b/db/schema.sql index 571c71bcd..819a6c0be 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -82,6 +82,12 @@ create table contacts ( -- extra fields required for open311 extra text + + -- per contact endpoint configuration + endpoint text, + jurisdiction text default '', + api_key text default '', + send_method text ); create unique index contacts_area_id_category_idx on contacts(area_id, category); @@ -445,5 +451,6 @@ create table open311conf ( send_method text, send_comments boolean not null default 'f', comment_user_id int references users(id), - suppress_alerts boolean not null default 'f' + suppress_alerts boolean not null default 'f', + can_be_devolved boolean not null default 'f' ); diff --git a/db/schema_0023-add_can_be_devolved_and_category_config.sql b/db/schema_0023-add_can_be_devolved_and_category_config.sql new file mode 100644 index 000000000..6eba0919a --- /dev/null +++ b/db/schema_0023-add_can_be_devolved_and_category_config.sql @@ -0,0 +1,13 @@ +begin; + +ALTER table open311conf + ADD column can_be_devolved BOOL NOT NULL DEFAULT 'f'; + +ALTER table contacts + ADD column endpoint TEXT, + ADD column jurisdiction TEXT DEFAULT '', + ADD column api_key TEXT DEFAULT '', + ADD column send_method TEXT +; + +commit; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index b89eda0c1..64e08f44c 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -644,7 +644,34 @@ Get stats to display on the council reports page sub get_report_stats { return 0; } -sub get_council_sender { return 'Email' }; +sub get_council_sender { + my ( $self, $area_id, $area_info, $category ) = @_; + + my $send_method; + + my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $area_id } )->first; + $send_method = $council_config->send_method if $council_config; + + if ( $council_config && $council_config->can_be_devolved ) { + # look up via category + my $config = FixMyStreet::App->model("DB::Contact")->search( { area_id => $area_id, category => $category } )->first; + if ( $config->send_method ) { + return { method => $config->send_method, config => $config }; + } else { + return { method => $send_method, config => $council_config }; + } + } elsif ( $send_method ) { + return { method => $send_method, config => $council_config }; + } + + return $self->_fallback_council_sender( $area_id, $area_info, $category ); +} + +sub _fallback_council_sender { + my ( $self, $area_id, $area_info, $category ) = @_; + + return { method => 'Email' }; +}; sub example_places { return FixMyStreet->config('EXAMPLE_PLACES') || [ 'High Street', 'Main Street' ]; diff --git a/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm b/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm index 355f1953f..9c102872f 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm @@ -4,19 +4,6 @@ use base 'FixMyStreet::Cobrand::Default'; use strict; use warnings; -sub get_council_sender { - my ( $self, $area_id, $area_info ) = @_; - - my $send_method; - - my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $area_id } )->first; - $send_method = $council_config->send_method if $council_config; - - return $send_method if $send_method; - - return 'Email'; -} - sub path_to_web_templates { my $self = shift; return [ diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index c2618cbd9..f0f3e85f6 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -31,16 +31,8 @@ sub disambiguate_location { }; } -sub get_council_sender { - my ( $self, $area_id, $area_info ) = @_; - - my $send_method; - - my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $area_id } )->first; - $send_method = $council_config->send_method if $council_config; - - return $send_method if $send_method; - +sub _fallback_council_sender { + my ( $self, $area_id, $area_info, $category ) = @_; return 'London' if $area_info->{type} eq 'LBO'; return 'NI' if $area_info->{type} eq 'LGD'; return 'Email'; diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index c32b75d0c..2a6ffa2fe 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -36,13 +36,21 @@ __PACKAGE__->add_columns( { data_type => "text", is_nullable => 0 }, "extra", { data_type => "text", is_nullable => 1 }, + "endpoint", + { data_type => "text", is_nullable => 1 }, + "jurisdiction", + { data_type => "text", default_value => "", is_nullable => 1 }, + "api_key", + { data_type => "text", default_value => "", is_nullable => 1 }, + "send_method", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("contacts_area_id_category_idx", ["area_id", "category"]); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-08 17:19:55 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hyvU0bMWSFxEPAJT7wqM/Q +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-29 17:34:28 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:getDAgTeXkAYQTcxHWflmA __PACKAGE__->filter_column( extra => { diff --git a/perllib/FixMyStreet/DB/Result/Open311conf.pm b/perllib/FixMyStreet/DB/Result/Open311conf.pm index c95b0c8f2..8051e27de 100644 --- a/perllib/FixMyStreet/DB/Result/Open311conf.pm +++ b/perllib/FixMyStreet/DB/Result/Open311conf.pm @@ -34,6 +34,8 @@ __PACKAGE__->add_columns( { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "suppress_alerts", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "can_be_devolved", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("open311conf_area_id_key", ["area_id"]); @@ -50,8 +52,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-05-11 13:30:31 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ByJbRe/Y/9Z1WHdG8kaIHg +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-29 14:04:20 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Yoult8K/ldH6DMAKURtr3Q # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index bac367b87..e946e01c2 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -308,8 +308,8 @@ sub send_reports { foreach my $council (@councils) { my $name = $areas_info->{$council}->{name}; - my $sender = $cobrand->get_council_sender( $council, $areas_info->{$council} ); - $sender = "FixMyStreet::SendReport::$sender"; + my $sender_info = $cobrand->get_council_sender( $council, $areas_info->{$council}, $row->category ); + my $sender = "FixMyStreet::SendReport::" . $sender_info->{method}; if ( ! exists $senders->{ $sender } ) { warn "No such sender [ $sender ] for council $name ( $council )"; @@ -322,7 +322,7 @@ sub send_reports { $reporters{ $sender }->skipped; } else { push @dear, $name; - $reporters{ $sender }->add_council( $council, $areas_info->{$council} ); + $reporters{ $sender }->add_council( $council, $areas_info->{$council}, $sender_info->{config} ); } } diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm index f750ef479..9ba507862 100644 --- a/perllib/FixMyStreet/SendReport.pm +++ b/perllib/FixMyStreet/SendReport.pm @@ -39,8 +39,9 @@ sub add_council { my $self = shift; my $council = shift; my $info = shift; + my $config = shift; - $self->councils->{ $council } = $info; + $self->councils->{ $council } = { info => $info, config => $config }; } diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 654ed6b3a..11ca196fb 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -12,6 +12,7 @@ sub build_recipient_list { my $all_confirmed = 1; foreach my $council ( keys %{ $self->councils } ) { + my $contact = FixMyStreet::App->model("DB::Contact")->find( { deleted => 0, area_id => $council, @@ -32,7 +33,7 @@ sub build_recipient_list { $self->unconfirmed_notes->{$council_email}{$row->category} = $note; } - push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{name} ]; + push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{info}->{name} ]; $recips{$council_email} = 1; } diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm index e1b914523..4a6f058fe 100644 --- a/perllib/FixMyStreet/SendReport/EmptyHomes.pm +++ b/perllib/FixMyStreet/SendReport/EmptyHomes.pm @@ -28,7 +28,7 @@ sub build_recipient_list { #$note{$council_email}{$row->category} = $note; } - push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{name} ]; + push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{ info }->{name} ]; $recips{$council_email} = 1; my $country = $self->councils->{$council}->{country}; diff --git a/perllib/FixMyStreet/SendReport/NI.pm b/perllib/FixMyStreet/SendReport/NI.pm index 0783a385b..810ee60e2 100644 --- a/perllib/FixMyStreet/SendReport/NI.pm +++ b/perllib/FixMyStreet/SendReport/NI.pm @@ -23,7 +23,7 @@ sub build_recipient_list { $email = 'N/A' unless $email; } - my $name = $self->councils->{$council}->{name}; + my $name = $self->councils->{$council}->{info}->{name}; if ( $email =~ /^roads.([^@]*)\@drdni/ ) { $name = "Roads Service (\u$1)"; $h->{councils_name} = $name; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index 56473cf5f..70bce3d47 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -28,7 +28,7 @@ sub send { my $result = -1; foreach my $council ( keys %{ $self->councils } ) { - my $conf = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $council, endpoint => { '!=', '' } } )->first; + my $conf = $self->councils->{$council}->{config}; my $always_send_latlong = 1; my $send_notpinpointed = 0; |