aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2012-08-29 17:43:22 +0100
committerStruan Donald <struan@exo.org.uk>2012-08-29 17:43:22 +0100
commit0fad1a7b85ac83dce778b7dd22cd9d74f524ce23 (patch)
treeb74e71b18b6cd8d267b29b264f8af89e801b9ca9 /perllib/FixMyStreet
parent716c333de51d06e289f0dd798ec675b6466e336a (diff)
allow endpoints to be configured at a category level
default cobrand now checks for endpoint configuration and only extra fallbacks are in UK cobrand
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm29
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyBarangay.pm13
-rw-r--r--perllib/FixMyStreet/Cobrand/UK.pm12
-rw-r--r--perllib/FixMyStreet/DB/Result/Contact.pm12
-rw-r--r--perllib/FixMyStreet/DB/Result/Open311conf.pm6
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm6
-rw-r--r--perllib/FixMyStreet/SendReport.pm3
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm3
-rw-r--r--perllib/FixMyStreet/SendReport/EmptyHomes.pm2
-rw-r--r--perllib/FixMyStreet/SendReport/NI.pm2
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm2
11 files changed, 54 insertions, 36 deletions
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;