aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2012-12-14 19:07:08 +0000
committerMatthew Somerville <matthew@mysociety.org>2012-12-19 14:43:26 +0000
commitddf9dbdbf6486c781ca4a5822614b0b7cee2c062 (patch)
tree09c12affc3390138b03292d3f90810287b4941d0
parentda29e8a75eaa92e98807ad89d29d3d1f3c01bc14 (diff)
Allow bodies to span multiple area IDs, and areas can be covered by more than one body.
-rwxr-xr-xbin/send-comments6
-rw-r--r--db/schema.sql7
-rw-r--r--db/schema_0033-body-areas-many-many.sql15
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm20
-rw-r--r--perllib/FixMyStreet/App/Controller/Dashboard.pm9
-rw-r--r--perllib/FixMyStreet/App/Controller/Open311.pm4
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm5
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm6
-rw-r--r--perllib/FixMyStreet/Cobrand/LichfieldDC.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/UK.pm8
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm19
-rw-r--r--perllib/FixMyStreet/DB/Result/BodyArea.pm32
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Body.pm17
-rw-r--r--perllib/FixMyStreet/SendReport/Barnet.pm4
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm4
-rw-r--r--perllib/FixMyStreet/TestMech.pm9
-rw-r--r--perllib/Open311/GetServiceRequestUpdates.pm11
-rw-r--r--perllib/Open311/PopulateServiceList.pm12
-rw-r--r--t/app/controller/admin.t4
-rw-r--r--t/app/controller/report_new_open311.t12
-rw-r--r--t/app/model/problem.t16
-rw-r--r--t/app/sendreport/email.t3
-rw-r--r--t/cobrand/get_body_sender.t10
-rw-r--r--t/open311/getservicerequestupdates.t14
-rw-r--r--t/open311/populate-service-list.t5
-rw-r--r--templates/web/default/admin/body-form.html7
-rwxr-xr-xtemplates/web/default/reports/body.html2
-rwxr-xr-xtemplates/web/default/reports/index.html2
-rwxr-xr-xtemplates/web/emptyhomes/reports/body.html2
-rwxr-xr-xtemplates/web/emptyhomes/reports/index.html2
30 files changed, 192 insertions, 77 deletions
diff --git a/bin/send-comments b/bin/send-comments
index ed13f10ba..1a12fa684 100755
--- a/bin/send-comments
+++ b/bin/send-comments
@@ -57,7 +57,7 @@ while ( my $body = $bodies->next ) {
}
);
- if ( $body->area_id == 2482 ) {
+ if ( $body->areas->{2482} ) {
$use_extended = 1;
}
@@ -68,7 +68,7 @@ while ( my $body = $bodies->next ) {
use_extended_updates => $use_extended,
);
- if ( $body->area_id == 2482 ) {
+ if ( $body->areas->{2482} ) {
my $endpoints = $o->endpoints;
$endpoints->{update} = 'update.xml';
$endpoints->{service_request_updates} = 'update.xml';
@@ -82,7 +82,7 @@ while ( my $body = $bodies->next ) {
next if bromley_retry_timeout( $comment );
}
- if ( $body->area_id == 2482 ) {
+ if ( $body->areas->{2482} ) {
my $extra = $comment->extra;
if ( !$extra ) {
$extra = {};
diff --git a/db/schema.sql b/db/schema.sql
index 8045ca6c4..fd0a3abd4 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -420,7 +420,6 @@ create table admin_log (
create table body (
id serial primary key,
name text not null,
- area_id integer not null unique,
endpoint text,
jurisdiction text,
api_key text,
@@ -430,3 +429,9 @@ create table body (
suppress_alerts boolean not null default 'f',
can_be_devolved boolean not null default 'f'
);
+
+create table body_areas (
+ body_id integer not null references body(id),
+ area_id integer not null
+);
+create unique index body_areas_body_id_area_id_idx on body_areas(body_id, area_id);
diff --git a/db/schema_0033-body-areas-many-many.sql b/db/schema_0033-body-areas-many-many.sql
new file mode 100644
index 000000000..e03f3fa44
--- /dev/null
+++ b/db/schema_0033-body-areas-many-many.sql
@@ -0,0 +1,15 @@
+begin;
+
+create table body_areas (
+ body_id integer not null references body(id),
+ area_id integer not null
+);
+create unique index body_areas_body_id_area_id_idx on body_areas(body_id, area_id);
+
+INSERT INTO body_areas (body_id, area_id)
+ SELECT id, area_id FROM body;
+
+ALTER TABLE body DROP COLUMN area_id;
+
+commit;
+
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index e64db0135..c9c3dc503 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -222,12 +222,15 @@ sub bodies : Path('bodies') : Args(0) {
$c->stash->{edit_activity} = $edit_activity;
- my $posted = $c->req->param('posted');
+ my $posted = $c->req->param('posted') || '';
if ( $posted eq 'body' ) {
$c->forward('check_token');
my $params = $c->forward('body_params');
- $c->model('DB::Body')->create( $params );
+ my $body = $c->model('DB::Body')->create( $params );
+ foreach ($c->req->params->{area_ids}) {
+ $c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } );
+ }
$c->stash->{updated} = _('New body added');
}
@@ -350,6 +353,14 @@ sub update_contacts : Private {
my $params = $c->forward( 'body_params' );
$c->stash->{body}->update( $params );
+ my @current = $c->stash->{body}->body_areas->all;
+ my %current = map { $_->area_id => 1 } @current;
+ foreach ($c->req->params->{area_ids}) {
+ $c->model('DB::BodyArea')->find_or_create( { body => $c->stash->{body}, area_id => $_ } );
+ delete $current{$_};
+ }
+ # Remove any others
+ $c->stash->{body}->body_areas->search( { area_id => [ keys %current ] } )->delete;
$c->stash->{updated} = _('Configuration updated - contacts will be generated automatically later');
}
@@ -358,10 +369,9 @@ sub update_contacts : Private {
sub body_params : Private {
my ( $self, $c ) = @_;
- my @fields = qw/name area_id endpoint jurisdiction api_key send_method send_comments suppress_alerts comment_user_id can_be_devolved/;
+ my @fields = qw/name endpoint jurisdiction api_key send_method send_comments suppress_alerts comment_user_id can_be_devolved/;
my %defaults = map { $_ => '' } @fields;
%defaults = ( %defaults,
- area_id => undef,
send_comments => 0,
suppress_alerts => 0,
comment_user_id => undef,
@@ -398,7 +408,7 @@ sub lookup_body : Private {
unless $body;
$c->stash->{body} = $body;
- my $example_postcode = mySociety::MaPit::call('area/example_postcode', $body->area_id);
+ my $example_postcode = mySociety::MaPit::call('area/example_postcode', $body->body_areas->first->area_id);
if ($example_postcode && ! ref $example_postcode) {
$c->stash->{example_pc} = $example_postcode;
}
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm
index 3a66cf1e0..657751e5c 100644
--- a/perllib/FixMyStreet/App/Controller/Dashboard.pm
+++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm
@@ -92,15 +92,18 @@ sub index : Path : Args(0) {
# Set up the data for the dropdowns
- my $council_detail = mySociety::MaPit::call('area', $body->area_id );
+ # Just take the first area ID we find
+ my $area_id = $body->body_areas->first->area_id;
+
+ my $council_detail = mySociety::MaPit::call('area', $area_id );
$c->stash->{council} = $council_detail;
- my $children = mySociety::MaPit::call('area/children', $body->area_id,
+ my $children = mySociety::MaPit::call('area/children', $area_id,
type => $c->cobrand->area_types_children,
);
$c->stash->{children} = $children;
- $c->stash->{all_areas} = { $body->area_id => $council_detail };
+ $c->stash->{all_areas} = { $area_id => $council_detail };
$c->forward( '/report/new/setup_categories_and_bodies' );
# See if we've had anything from the dropdowns
diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm
index 62cdaffaf..3a6794325 100644
--- a/perllib/FixMyStreet/App/Controller/Open311.pm
+++ b/perllib/FixMyStreet/App/Controller/Open311.pm
@@ -168,8 +168,8 @@ sub get_services : Private {
"4326/$lon,$lat",
type => $area_types);
$categories = $categories->search( {
- 'body.area_id' => [ keys %$all_areas ],
- }, { join => 'body' } );
+ 'body_areas.area_id' => [ keys %$all_areas ],
+ }, { join => { 'body' => 'body_areas' } } );
}
my @categories = $categories->search( undef, {
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 09e46ccef..c3525b2c9 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -580,7 +580,10 @@ sub setup_categories_and_bodies : Private {
my $all_areas = $c->stash->{all_areas};
my $first_area = ( values %$all_areas )[0];
- my @bodies = $c->model('DB::Body')->search( { area_id => [ keys %$all_areas ] } )->all;
+ my @bodies = $c->model('DB::Body')->search(
+ { 'body_areas.area_id' => [ keys %$all_areas ] },
+ { join => 'body_areas' }
+ )->all;
my %bodies = map { $_->id => $_ } @bodies;
my $first_body = ( values %bodies )[0];
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 630409227..bf65fe1d5 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -99,7 +99,7 @@ sub ward : Path : Args(2) {
$c,
latitude => @$pins ? $pins->[0]{latitude} : 0,
longitude => @$pins ? $pins->[0]{longitude} : 0,
- area => $c->stash->{ward} ? $c->stash->{ward}->{id} : $c->stash->{body}->area_id,
+ area => $c->stash->{ward} ? $c->stash->{ward}->{id} : [ keys %{$c->stash->{body}->areas} ],
pins => $pins,
any_zoom => 1,
);
@@ -109,7 +109,7 @@ sub ward : Path : Args(2) {
# List of wards
# Ignore external_body special body thing
unless ($c->stash->{ward} || !$c->stash->{body}->id) {
- my $children = mySociety::MaPit::call('area/children', [ $c->stash->{body}->area_id ],
+ my $children = mySociety::MaPit::call('area/children', [ $c->stash->{body}->body_areas->first->area_id ],
type => $c->cobrand->area_types_children,
);
unless ($children->{error}) {
@@ -301,7 +301,7 @@ sub ward_check : Private {
# Could be from RSS area, or body...
my $parent_id;
if ( $c->stash->{body} ) {
- $parent_id = $c->stash->{body}->area_id;
+ $parent_id = $c->stash->{body}->body_areas->first->area_id;
} else {
$parent_id = $c->stash->{area}->{id};
}
diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
index f9d5e3632..99797f9c9 100644
--- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
+++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm
@@ -30,7 +30,7 @@ sub disambiguate_location {
sub base_url_for_report {
my ( $self, $report ) = @_;
my $bodies = $report->bodies;
- my %areas = map { $_->area_id => 1 } values %$bodies;
+ my %areas = map { %{$_->areas} } values %$bodies;
if ( $areas{2434} ) {
return $self->base_url;
} else {
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm
index 3ad58437e..ff613ffa8 100644
--- a/perllib/FixMyStreet/Cobrand/UK.pm
+++ b/perllib/FixMyStreet/Cobrand/UK.pm
@@ -34,7 +34,8 @@ sub disambiguate_location {
sub _fallback_body_sender {
my ( $self, $body, $category ) = @_;
- my $area_info = mySociety::MaPit::call('area', $body->area_id);
+ my $first_area = $body->body_areas->first->area_id;
+ my $area_info = mySociety::MaPit::call('area', $first_area);
return { method => 'London' } if $area_info->{type} eq 'LBO';
return { method => 'NI' } if $area_info->{type} eq 'LGD';
return { method => 'Email' };
@@ -43,11 +44,12 @@ sub _fallback_body_sender {
sub process_extras {
my $self = shift;
my $ctx = shift;
- my $area_id = shift;
+ my $body_id = shift;
my $extra = shift;
my $fields = shift || [];
- if ( $area_id eq '2482' ) {
+ # XXX Hardcoded body ID matching mapit area ID
+ if ( $body_id eq '2482' ) {
my @fields = ( 'fms_extra_title', @$fields );
for my $field ( @fields ) {
my $value = $ctx->request->param( $field );
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
index 73d763a6e..a4da74f80 100644
--- a/perllib/FixMyStreet/DB/Result/Body.pm
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -18,8 +18,6 @@ __PACKAGE__->add_columns(
is_nullable => 0,
sequence => "body_id_seq",
},
- "area_id",
- { data_type => "integer", is_nullable => 0 },
"endpoint",
{ data_type => "text", is_nullable => 1 },
"jurisdiction",
@@ -40,7 +38,12 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 0 },
);
__PACKAGE__->set_primary_key("id");
-__PACKAGE__->add_unique_constraint("body_area_id_key", ["area_id"]);
+__PACKAGE__->has_many(
+ "body_areas",
+ "FixMyStreet::DB::Result::BodyArea",
+ { "foreign.body_id" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
__PACKAGE__->belongs_to(
"comment_user",
"FixMyStreet::DB::Result::User",
@@ -66,8 +69,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 09:23:59
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tvTHtIa0GrtptadZYHEM1Q
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 17:54:33
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2Z3gCosNomCTcjrwWy/RNA
sub url {
my ( $self, $c ) = @_;
@@ -75,4 +78,10 @@ sub url {
return $c->uri_for( '/reports/' . $c->cobrand->short_name( $self ) );
}
+sub areas {
+ my $self = shift;
+ my %ids = map { $_->area_id => 1 } $self->body_areas->all;
+ return \%ids;
+}
+
1;
diff --git a/perllib/FixMyStreet/DB/Result/BodyArea.pm b/perllib/FixMyStreet/DB/Result/BodyArea.pm
new file mode 100644
index 000000000..508203cc8
--- /dev/null
+++ b/perllib/FixMyStreet/DB/Result/BodyArea.pm
@@ -0,0 +1,32 @@
+use utf8;
+package FixMyStreet::DB::Result::BodyArea;
+
+# Created by DBIx::Class::Schema::Loader
+# DO NOT MODIFY THE FIRST PART OF THIS FILE
+
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Core';
+__PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn");
+__PACKAGE__->table("body_areas");
+__PACKAGE__->add_columns(
+ "body_id",
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
+ "area_id",
+ { data_type => "integer", is_nullable => 0 },
+);
+__PACKAGE__->belongs_to(
+ "body",
+ "FixMyStreet::DB::Result::Body",
+ { id => "body_id" },
+ { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" },
+);
+
+
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 17:54:33
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:jTU6Nu/MQEvg9o8Hf5YQUQ
+
+ __PACKAGE__->set_primary_key(__PACKAGE__->columns);
+
+1;
diff --git a/perllib/FixMyStreet/DB/ResultSet/Body.pm b/perllib/FixMyStreet/DB/ResultSet/Body.pm
new file mode 100644
index 000000000..6802ed604
--- /dev/null
+++ b/perllib/FixMyStreet/DB/ResultSet/Body.pm
@@ -0,0 +1,17 @@
+package FixMyStreet::DB::ResultSet::Body;
+use base 'DBIx::Class::ResultSet';
+
+use strict;
+use warnings;
+
+sub for_areas {
+ my ( $rs, @areas ) = @_;
+
+ my $result = $rs->search(
+ { 'body_areas.area_id' => \@areas },
+ { join => 'body_areas' }
+ );
+ return $result;
+}
+
+1;
diff --git a/perllib/FixMyStreet/SendReport/Barnet.pm b/perllib/FixMyStreet/SendReport/Barnet.pm
index 21d4a06a5..05ca20809 100644
--- a/perllib/FixMyStreet/SendReport/Barnet.pm
+++ b/perllib/FixMyStreet/SendReport/Barnet.pm
@@ -80,7 +80,7 @@ sub send {
? $h{query} : $nearest_postcode; # use given postcode if available
# note: endpoint can be of form 'https://username:password@url'
- my $body = FixMyStreet::App->model("DB::Body")->search( { area_id => COUNCIL_ID_BARNET} )->first;
+ my $body = FixMyStreet::App->model("DB::Body")->search( { 'body_areas.area_id' => COUNCIL_ID_BARNET }, { join => "body_areas" } )->first;
if ($body and $body->endpoint) {
$interface->set_proxy($body->endpoint);
# Barnet web service doesn't like namespaces in the elements so use a prefix
@@ -90,7 +90,7 @@ sub send {
#$interface->outputxml(1);
#$interface->no_dispatch(1);
} else {
- die "Barnet webservice FAIL: looks like you're missing some config data: no endpoint (URL) found for area_id=" . COUNCIL_ID_BARNET;
+ die "Barnet webservice FAIL: looks like you're missing some config data: no endpoint (URL) found for area ID " . COUNCIL_ID_BARNET;
}
eval {
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index 5277b639a..b7c15a643 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -21,8 +21,8 @@ sub build_recipient_list {
my ($body_email, $confirmed, $note) = ( $contact->email, $contact->confirmed, $contact->note );
- $body_email = essex_contact($row->latitude, $row->longitude) if $body->area_id == 2225;
- $body_email = oxfordshire_contact($row->latitude, $row->longitude) if $body->area_id == 2237 && $body_email eq 'SPECIAL';
+ $body_email = essex_contact($row->latitude, $row->longitude) if $body->areas->{2225};
+ $body_email = oxfordshire_contact($row->latitude, $row->longitude) if $body->areas->{2237} && $body_email eq 'SPECIAL';
unless ($confirmed) {
$all_confirmed = 0;
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index cc4e45f45..addbb1752 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -536,11 +536,18 @@ sub create_body_ok {
my $self = shift;
my ( $id, $name ) = @_;
- my $params = { id => $id, area_id => $id, name => $name };
+ my $params = { id => $id, name => $name };
my $body = FixMyStreet::App->model('DB::Body')->find_or_create($params);
$body->update($params); # Make sure
ok $body, "found/created user for $id $name";
+
+ FixMyStreet::App->model('DB::BodyArea')->find_or_create({
+ area_id => $id,
+ body_id => $id,
+ });
+
return $body;
+
}
sub create_problems_for_body {
diff --git a/perllib/Open311/GetServiceRequestUpdates.pm b/perllib/Open311/GetServiceRequestUpdates.pm
index 875769eac..27cb21c3a 100644
--- a/perllib/Open311/GetServiceRequestUpdates.pm
+++ b/perllib/Open311/GetServiceRequestUpdates.pm
@@ -31,7 +31,7 @@ sub fetch {
jurisdiction => $body->jurisdiction,
);
- if ( $body->area_id == 2482 ) {
+ if ( $body->areas->{2482} ) {
my $endpoints = $o->endpoints;
$endpoints->{update} = 'update.xml';
$endpoints->{service_request_updates} = 'update.xml';
@@ -40,7 +40,7 @@ sub fetch {
$self->suppress_alerts( $body->suppress_alerts );
$self->system_user( $body->comment_user );
- $self->update_comments( $o, { areaid => $body->area_id }, );
+ $self->update_comments( $o, { areas => $body->areas }, );
}
}
@@ -55,7 +55,7 @@ sub update_comments {
push @args, $self->start_date;
push @args, $self->end_date;
# default to asking for last 2 hours worth if not Bromley
- } elsif ( $body_details->{areaid} != 2482 ) {
+ } elsif ( ! $body_details->{areas}->{2482} ) {
my $end_dt = DateTime->now();
my $start_dt = $end_dt->clone;
$start_dt->add( hours => -2 );
@@ -67,7 +67,7 @@ sub update_comments {
my $requests = $open311->get_service_request_updates( @args );
unless ( $open311->success ) {
- warn "Failed to fetch ServiceRequest Updates for " . $body_details->{areaid} . ":\n" . $open311->error
+ warn "Failed to fetch ServiceRequest Updates for " . join(",", keys %{$body_details->{areas}}) . ":\n" . $open311->error
if $self->verbose;
return 0;
}
@@ -83,7 +83,8 @@ sub update_comments {
FixMyStreet::App->model('DB::Problem')
->search( {
external_id => $request_id,
- bodies_str => { like => '%' . $body_details->{areaid} . '%' },
+ # XXX This assumes that areas will actually only be one area.
+ bodies_str => { like => '%' . join(",", keys %{$body_details->{areas}}) . '%' },
} );
if (my $p = $problem->first) {
diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm
index 8000378e3..bd90e10e9 100644
--- a/perllib/Open311/PopulateServiceList.pm
+++ b/perllib/Open311/PopulateServiceList.pm
@@ -42,8 +42,8 @@ sub process_body {
my $list = $open311->get_service_list;
unless ( $list ) {
my $id = $self->_current_body->id;
- my $area_id = $self->_current_body->area_id;
- warn "Body $id for area $area_id - http://mapit.mysociety.org/area/$area_id.html - did not return a service list\n"
+ my $areas = join( ",", keys %{$self->_current_body->areas} );
+ warn "Body $id for areas $areas - http://mapit.mysociety.org/areas/$areas.html - did not return a service list\n"
if $self->verbose >= 1;
return;
}
@@ -56,7 +56,7 @@ sub _check_endpoints {
my $self = shift;
# west berks end point not standard
- if ( $self->_current_body->area_id == 2619 ) {
+ if ( $self->_current_body->areas->{2619} ) {
$self->_current_open311->endpoints(
{
services => 'Services',
@@ -82,7 +82,7 @@ sub process_services {
sub process_service {
my $self = shift;
- my $category = $self->_current_body->area_id == 2218 ?
+ my $category = $self->_current_body->areas->{2218} ?
$self->_current_service->{description} :
$self->_current_service->{service_name};
@@ -226,7 +226,7 @@ sub _add_meta_to_contact {
# we add these later on from bromley so don't list them here
# as we don't want to display them
- if ( $self->_current_body->area_id == 2482 ) {
+ if ( $self->_current_body->areas->{2482} ) {
my %ignore = map { $_ => 1 } qw/
service_request_id_ext
requested_datetime
@@ -257,7 +257,7 @@ sub _normalize_service_name {
# FIXME - at the moment it makes more sense to use the description
# for cambridgeshire but need a more flexible way to set this
- my $service_name = $self->_current_body->area_id == 2218 ?
+ my $service_name = $self->_current_body->areas->{2218} ?
$self->_current_service->{description} :
$self->_current_service->{service_name};
# remove trailing whitespace as it upsets db queries
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index d759c1238..d8b721ca9 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -259,7 +259,7 @@ subtest 'check open311 configuring' => sub {
$mech->content_contains('Configuration updated - contacts will be generated automatically later');
my $open311 =
- FixMyStreet::App->model('DB::Body')->search( { area_id => 2650 } );
+ FixMyStreet::App->model('DB::Body')->search( { 'body_areas.area_id' => 2650 }, { join => 'body_areas' } );
is $open311->count, 1, 'only one configuration';
my $conf = $open311->first;
@@ -283,7 +283,7 @@ subtest 'check open311 configuring' => sub {
$mech->content_contains('Configuration updated');
$open311 =
- FixMyStreet::App->model('DB::Body')->search( { area_id => 2650 } );
+ FixMyStreet::App->model('DB::Body')->search( { 'body_areas.area_id' => 2650 }, { join => 'body_areas' } );
is $open311->count, 1, 'only one configuration';
$conf = $open311->first;
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t
index e9ada9f41..22d2d1f97 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -7,12 +7,12 @@ use Web::Scraper;
my $mech = FixMyStreet::TestMech->new;
-FixMyStreet::App->model('DB::Body')->find_or_create( {
- area_id => 2651,
- endpoint => 'http://example.com/open311',
- jurisdiction => 'mySociety',
- api_key => 'apikey',
-} );
+my $body = $mech->create_body_ok(2651, 'City of Edinburgh Council');
+$body->update({
+ endpoint => 'http://example.com/open311',
+ jurisdiction => 'mySociety',
+ api_key => 'apikey',
+});
my %contact_params = (
confirmed => 1,
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index ec82a3a4e..b2243fcf5 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -357,14 +357,14 @@ my %contact_params = (
);
for my $body (
- { id => 2651, area_id => 2651, name => 'City of Edinburgh Council' },
- { id => 2226, area_id => 2226, name => 'Gloucestershire County Council' },
- { id => 2326, area_id => 2326, name => 'Cheltenham Borough Council' },
- { id => 2434, area_id => 2434, name => 'Lichfield District Council' },
- { id => 2240, area_id => 2240, name => 'Staffordshire County Council' },
- { id => 14279, area_id => 14279, name => 'Ballymoney Borough Council' },
- { id => 2636, area_id => 2636, name => 'Isle of Wight Council' },
- { id => 2649, area_id => 2649, name => 'Fife Council' },
+ { id => 2651, name => 'City of Edinburgh Council' },
+ { id => 2226, name => 'Gloucestershire County Council' },
+ { id => 2326, name => 'Cheltenham Borough Council' },
+ { id => 2434, name => 'Lichfield District Council' },
+ { id => 2240, name => 'Staffordshire County Council' },
+ { id => 14279, name => 'Ballymoney Borough Council' },
+ { id => 2636, name => 'Isle of Wight Council' },
+ { id => 2649, name => 'Fife Council' },
) {
$mech->create_body_ok($body->{id}, $body->{name});
}
diff --git a/t/app/sendreport/email.t b/t/app/sendreport/email.t
index 17abd6243..106a31c42 100644
--- a/t/app/sendreport/email.t
+++ b/t/app/sendreport/email.t
@@ -14,7 +14,8 @@ use mySociety::Locale;
my $e = FixMyStreet::SendReport::Email->new();
-my $params = { id => 1000, area_id => 1000, name => 'Council of the Thousand' };
+# area id 1000
+my $params = { id => 1000, name => 'Council of the Thousand' };
my $body = FixMyStreet::App->model('DB::Body')->find_or_create($params);
ok $body, "found/created body";
diff --git a/t/cobrand/get_body_sender.t b/t/cobrand/get_body_sender.t
index 8475f5eed..245cb1a13 100644
--- a/t/cobrand/get_body_sender.t
+++ b/t/cobrand/get_body_sender.t
@@ -12,23 +12,27 @@ mySociety::Locale::gettext_domain( 'FixMyStreet' );
my $c = FixMyStreet::Cobrand::FixMyStreet->new();
+FixMyStreet::App->model('DB::BodyArea')->search( { body_id => 1000 } )->delete;
FixMyStreet::App->model('DB::Body')->search( { name => 'Body of a Thousand' } )->delete;
my $body = FixMyStreet::App->model('DB::Body')->find_or_create({
- area_id => 1000,
+ id => 1000,
name => 'Body of a Thousand',
});
+my $body_area = $body->body_areas->find_or_create({ area_id => 1000 });
+
is_deeply $c->get_body_sender( $body ), { method => 'Email' }, 'defaults to email';
-$body->area_id( 2481 ); # Croydon LBO
+$body_area->update({ area_id => 2481 }); # Croydon LBO
is_deeply $c->get_body_sender( $body ), { method => 'London' }, 'returns london report it if London borough';
$body->send_method( 'TestMethod' );
is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to London';
-$body->area_id( 1000 ); # Nothing
+$body_area->update({ area_id => 1000 }); # Nothing
is $c->get_body_sender( $body )->{ method }, 'TestMethod', 'uses send_method in preference to Email';
+$body_area->delete;
$body->delete;
done_testing();
diff --git a/t/open311/getservicerequestupdates.t b/t/open311/getservicerequestupdates.t
index 40868cfdd..da23c944e 100644
--- a/t/open311/getservicerequestupdates.t
+++ b/t/open311/getservicerequestupdates.t
@@ -204,7 +204,7 @@ for my $test (
$problem->state( $test->{start_state} );
$problem->update;
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
my $update = Open311::GetServiceRequestUpdates->new( system_user => $user );
$update->update_comments( $o, $council_details );
@@ -243,7 +243,7 @@ foreach my $test (
$problem->comments->delete;
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
my $update = Open311::GetServiceRequestUpdates->new( system_user => $user );
$update->update_comments( $o, $council_details );
@@ -312,7 +312,7 @@ for my $test (
my $o = Open311->new( jurisdiction => 'mysociety', endpoint => 'http://example.com', test_mode => 1, test_get_returns => { 'servicerequestupdates.xml' => $local_requests_xml } );
- my $council_details = { areaid => $test->{area_id} };
+ my $council_details = { areas => { $test->{area_id} => 1 } };
my $update = Open311::GetServiceRequestUpdates->new( system_user => $user );
$update->update_comments( $o, $council_details );
@@ -352,7 +352,7 @@ subtest 'using start and end date' => sub {
end_date => $end_dt,
);
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
$update->update_comments( $o, $council_details );
my $start = $start_dt . '';
@@ -412,7 +412,7 @@ subtest 'check that existing comments are not duplicated' => sub {
system_user => $user,
);
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
$update->update_comments( $o, $council_details );
$problem->discard_changes;
@@ -473,7 +473,7 @@ foreach my $test ( {
system_user => $user,
);
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
$update->update_comments( $o, $council_details );
$problem->discard_changes;
@@ -525,7 +525,7 @@ foreach my $test ( {
suppress_alerts => $test->{suppress_alerts},
);
- my $council_details = { areaid => 2482 };
+ my $council_details = { areas => { 2482 => 1 } };
$update->update_comments( $o, $council_details );
$problem->discard_changes;
diff --git a/t/open311/populate-service-list.t b/t/open311/populate-service-list.t
index ae5879896..f33fc97b4 100644
--- a/t/open311/populate-service-list.t
+++ b/t/open311/populate-service-list.t
@@ -20,11 +20,16 @@ ok $processor, 'created object';
my $body = FixMyStreet::App->model('DB::Body')->find_or_create( {
id => 1,
name => 'Body Numero Uno',
+} );
+$body->body_areas->find_or_create({
area_id => 1
} );
+
my $bromley = FixMyStreet::App->model('DB::Body')->find_or_create( {
id => 2482,
name => 'Bromley Council',
+} );
+$bromley->body_areas->find_or_create({
area_id => 2482
} );
diff --git a/templates/web/default/admin/body-form.html b/templates/web/default/admin/body-form.html
index 405309d93..222d9b04c 100644
--- a/templates/web/default/admin/body-form.html
+++ b/templates/web/default/admin/body-form.html
@@ -6,11 +6,12 @@
</p>
<p>
- <label for="area_id">Area covered</label>
- <select name="area_id">
+ <label for="area_ids">Area covered</label>
+ <select name="area_ids" multiple>
<option value=""> -- Select an area -- </option>
[% FOR area IN areas %]
- <option value="[% area.id %]"[% ' selected' IF body.area_id == area.id %]>[% area.name %]</option>
+ [% SET aid = area.id %]
+ <option value="[% area.id %]"[% ' selected' IF body.areas.$aid %]>[% area.name %]</option>
[% END %]
</select>
</p>
diff --git a/templates/web/default/reports/body.html b/templates/web/default/reports/body.html
index 8da5b8e7a..284915571 100755
--- a/templates/web/default/reports/body.html
+++ b/templates/web/default/reports/body.html
@@ -44,7 +44,7 @@
[% END %]
</h1>
-[% IF NOT body.area_id AND c.cobrand.country == 'GB' %]
+[% IF NOT body.areas AND c.cobrand.country == 'GB' %]
<p id="unknown" class="alert">This council no longer exists.
[% IF council.name.match('Penwith|Kerrier|Carrick|Restormel|Caradon|North Cornwall') %]
Its area is now covered by <a href="/reports/Cornwall">Cornwall Council</a>.
diff --git a/templates/web/default/reports/index.html b/templates/web/default/reports/index.html
index 12159d741..780438634 100755
--- a/templates/web/default/reports/index.html
+++ b/templates/web/default/reports/index.html
@@ -24,7 +24,7 @@
<tbody>
[% FOREACH body IN bodies %]
<tr align="center"
-[%- IF NOT body.area_id %] class="gone"
+[%- IF NOT body.areas %] class="gone"
[%- ELSIF ! (loop.count % 2) %] class="a"
[%- END %]>
<td class="title"><a href="[% body.url(c) %]">[% body.name %]</a></td>
diff --git a/templates/web/emptyhomes/reports/body.html b/templates/web/emptyhomes/reports/body.html
index 19de81c36..eff87d823 100755
--- a/templates/web/emptyhomes/reports/body.html
+++ b/templates/web/emptyhomes/reports/body.html
@@ -26,7 +26,7 @@
<div id="side">
-[% IF NOT body.area_id AND c.cobrand.country == 'GB' %]
+[% IF NOT body.areas AND c.cobrand.country == 'GB' %]
<p id="unknown">This council no longer exists.
[% IF council.name.match('Penwith|Kerrier|Carrick|Restormel|Caradon|North Cornwall') %]
Its area is now covered by <a href="/reports/Cornwall">Cornwall Council</a>.
diff --git a/templates/web/emptyhomes/reports/index.html b/templates/web/emptyhomes/reports/index.html
index 28dea49af..9ce2b66ca 100755
--- a/templates/web/emptyhomes/reports/index.html
+++ b/templates/web/emptyhomes/reports/index.html
@@ -16,7 +16,7 @@
[% FOREACH body IN bodies %]
<tr align="center"
-[%- IF NOT body.area_id %] class="gone"
+[%- IF NOT body.areas %] class="gone"
[%- ELSIF loop.count % 2 %] class="a"
[%- END -%]
>