diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-06-13 18:39:05 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2017-06-20 15:02:11 +0100 |
commit | e57cbf483790bedfef6496be3c7ffa42882c3ffc (patch) | |
tree | d01788502457f801a846cdac78213df5ecdf1ea5 /perllib/FixMyStreet/Cobrand | |
parent | a5f311e5147621f285cf31647ce675c502095882 (diff) |
[UK] Remove requirement for fixed body IDs.
Historically in UK cobrands, bodies have had IDs the same as the MapIt
area ID they cover. This can be confusing (if you are setting up a dev
environment, say) and should not be necessary. This commit removes the
requirement entirely, by switching any ID checks to either the name of
the body, or the actual area it covers.
One note: the body name in the test has to match so that we do not get
two bodies both covering 2237 created. This will not be necessary when
the tests are compartmentalized in the next commit.
Diffstat (limited to 'perllib/FixMyStreet/Cobrand')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Angus.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Borsetshire.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bristol.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/EastHerts.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Greenwich.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Hart.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Oxfordshire.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Stevenage.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 25 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Warwickshire.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/WestBerkshire.pm | 2 |
13 files changed, 37 insertions, 31 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Angus.pm b/perllib/FixMyStreet/Cobrand/Angus.pm index 0361c2d11..51a3da56a 100644 --- a/perllib/FixMyStreet/Cobrand/Angus.pm +++ b/perllib/FixMyStreet/Cobrand/Angus.pm @@ -4,7 +4,7 @@ use parent 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; -sub council_id { return 2550; } +sub council_area_id { return 2550; } sub council_area { return 'Angus'; } sub council_name { return 'Angus Council'; } sub council_url { return 'angus'; } @@ -70,13 +70,17 @@ sub temp_update_contacts { my $contact_rs = $self->{c}->model('DB::Contact'); + my $body = FixMyStreet::DB->resultset('Body')->search({ + 'body_areas.area_id' => $self->council_area_id, + }, { join => 'body_areas' })->first; + my $_update = sub { my ($category, $field, $category_details) = @_; # NB: we're accepting just 1 field, but supply as array [ $field ] my $contact = $contact_rs->find_or_create( { - body_id => $self->council_id, + body => $body, category => $category, %{ $category_details || {} }, }, diff --git a/perllib/FixMyStreet/Cobrand/Borsetshire.pm b/perllib/FixMyStreet/Cobrand/Borsetshire.pm index 887de57ed..89869ff1b 100644 --- a/perllib/FixMyStreet/Cobrand/Borsetshire.pm +++ b/perllib/FixMyStreet/Cobrand/Borsetshire.pm @@ -4,7 +4,7 @@ use parent 'FixMyStreet::Cobrand::Whitelabel'; use strict; use warnings; -sub council_id { return 2608; } +sub council_area_id { return 2608; } sub council_area { return 'Borsetshire'; } sub council_name { return 'Borsetshire County Council'; } sub council_url { return 'demo'; } diff --git a/perllib/FixMyStreet/Cobrand/Bristol.pm b/perllib/FixMyStreet/Cobrand/Bristol.pm index fa7f98666..2876ff782 100644 --- a/perllib/FixMyStreet/Cobrand/Bristol.pm +++ b/perllib/FixMyStreet/Cobrand/Bristol.pm @@ -4,7 +4,7 @@ use parent 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; -sub council_id { return 2561; } +sub council_area_id { return 2561; } sub council_area { return 'Bristol'; } sub council_name { return 'Bristol County Council'; } sub council_url { return 'bristol'; } diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index 169175947..e7d5e186a 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -5,7 +5,7 @@ use strict; use warnings; use DateTime::Format::W3CDTF; -sub council_id { return 2482; } +sub council_area_id { return 2482; } sub council_area { return 'Bromley'; } sub council_name { return 'Bromley Council'; } sub council_url { return 'bromley'; } diff --git a/perllib/FixMyStreet/Cobrand/EastHerts.pm b/perllib/FixMyStreet/Cobrand/EastHerts.pm index ea5ed7f55..0e60c6b08 100644 --- a/perllib/FixMyStreet/Cobrand/EastHerts.pm +++ b/perllib/FixMyStreet/Cobrand/EastHerts.pm @@ -4,7 +4,7 @@ use parent 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; -sub council_id { return 2342; } +sub council_area_id { return 2342; } sub council_area { return 'East Hertfordshire'; } sub council_name { return 'East Hertfordshire District Council'; } sub council_url { return 'eastherts'; } @@ -51,4 +51,4 @@ sub contact_email { return join( '@', 'enquiries', 'eastherts.gov.uk' ); } -1;
\ No newline at end of file +1; diff --git a/perllib/FixMyStreet/Cobrand/Greenwich.pm b/perllib/FixMyStreet/Cobrand/Greenwich.pm index 700a12782..ce4fae381 100644 --- a/perllib/FixMyStreet/Cobrand/Greenwich.pm +++ b/perllib/FixMyStreet/Cobrand/Greenwich.pm @@ -4,7 +4,7 @@ use parent 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; -sub council_id { return 2493; } +sub council_area_id { return 2493; } sub council_area { return 'Greenwich'; } sub council_name { return 'Royal Borough of Greenwich'; } sub council_url { return 'greenwich'; } diff --git a/perllib/FixMyStreet/Cobrand/Hart.pm b/perllib/FixMyStreet/Cobrand/Hart.pm index 42c4a636e..3ff2a2a19 100644 --- a/perllib/FixMyStreet/Cobrand/Hart.pm +++ b/perllib/FixMyStreet/Cobrand/Hart.pm @@ -4,7 +4,7 @@ use parent 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; -sub council_id { return 2333; } # http://mapit.mysociety.org/area/2333.html +sub council_area_id { return 2333; } # http://mapit.mysociety.org/area/2333.html sub council_area { return 'Hart'; } sub council_name { return 'Hart Council'; } sub council_url { return 'hart'; } diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index 76d7ee31f..a061ff46c 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -4,7 +4,7 @@ use base 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; -sub council_id { return 2237; } +sub council_area_id { return 2237; } sub council_area { return 'Oxfordshire'; } sub council_name { return 'Oxfordshire County Council'; } sub council_url { return 'oxfordshire'; } diff --git a/perllib/FixMyStreet/Cobrand/Stevenage.pm b/perllib/FixMyStreet/Cobrand/Stevenage.pm index 2c305d326..28734b14b 100644 --- a/perllib/FixMyStreet/Cobrand/Stevenage.pm +++ b/perllib/FixMyStreet/Cobrand/Stevenage.pm @@ -4,7 +4,7 @@ use parent 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; -sub council_id { return 2347; } +sub council_area_id { return 2347; } sub council_area { return 'Stevenage'; } sub council_name { return 'Stevenage Council'; } sub council_url { return 'stevenage'; } diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index 1a5682dad..e067405ee 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -32,12 +32,11 @@ sub disambiguate_location { sub process_open311_extras { my $self = shift; my $ctx = shift; - my $body_id = shift; + my $body = shift; my $extra = shift; my $fields = shift || []; - # XXX Hardcoded body ID matching mapit area ID - if ( $body_id eq '2482' ) { + if ( $body && $body->name =~ /Bromley/ ) { my @fields = ( 'fms_extra_title', @$fields ); for my $field ( @fields ) { my $value = $ctx->get_param($field); @@ -328,15 +327,11 @@ sub report_check_for_errors { ); } - # XXX Hardcoded body ID matching mapit area ID if ( $report->bodies_str && $report->detail ) { # Custom character limit: - # Bromley Council - if ( $report->bodies_str eq '2482' && length($report->detail) > 1750 ) { + if ( $report->to_body_named('Bromley') && length($report->detail) > 1750 ) { $errors{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1750 ); - } - # Oxfordshire - if ( $report->bodies_str eq '2237' && length($report->detail) > 1700 ) { + } elsif ( $report->to_body_named('Oxfordshire') && length($report->detail) > 1700 ) { $errors{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1700 ); } } diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index e0b6b5298..0c044fb86 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -1,7 +1,5 @@ package FixMyStreet::Cobrand::UKCouncils; -use base 'FixMyStreet::Cobrand::UK'; - -# XXX Things using this cobrand base assume that a body ID === MapIt area ID +use parent 'FixMyStreet::Cobrand::UK'; use strict; use warnings; @@ -40,16 +38,25 @@ sub restriction { return { cobrand => shift->moniker }; } +# UK cobrands assume that each MapIt area ID maps both ways with one body +sub body { + my $self = shift; + my $body = FixMyStreet::DB->resultset('Body')->search({ + 'body_areas.area_id' => $self->council_area_id + }, { join => 'body_areas' })->first; + return $body; +} + sub problems_restriction { my ($self, $rs) = @_; return $rs if FixMyStreet->staging_flag('skip_checks'); - return $rs->to_body($self->council_id); + return $rs->to_body($self->body); } sub updates_restriction { my ($self, $rs) = @_; return $rs if FixMyStreet->staging_flag('skip_checks'); - return $rs->to_body($self->council_id); + return $rs->to_body($self->body); } sub users_restriction { @@ -75,7 +82,7 @@ sub users_restriction { )->as_query; my $or_query = [ - from_body => $self->council_id, + from_body => $self->body->id, 'me.id' => [ { -in => $problem_user_ids }, { -in => $update_user_ids } ], ]; if ($self->can('admin_user_domain')) { @@ -108,7 +115,7 @@ sub area_check { return 1 if FixMyStreet->staging_flag('skip_checks'); my $councils = $params->{all_areas}; - my $council_match = defined $councils->{$self->council_id}; + my $council_match = defined $councils->{$self->council_area_id}; if ($council_match) { return 1; } @@ -164,7 +171,7 @@ sub owns_problem { @bodies = values %{$report->bodies}; } my %areas = map { %{$_->areas} } @bodies; - return $areas{$self->council_id} ? 1 : undef; + return $areas{$self->council_area_id} ? 1 : undef; } # If the council is two-tier then show pins for the other council as grey @@ -192,7 +199,7 @@ sub admin_allow_user { my ( $self, $user ) = @_; return 1 if $user->is_superuser; return undef unless defined $user->from_body; - return $user->from_body->id == $self->council_id; + return $user->from_body->areas->{$self->council_area_id}; } sub available_permissions { diff --git a/perllib/FixMyStreet/Cobrand/Warwickshire.pm b/perllib/FixMyStreet/Cobrand/Warwickshire.pm index e52188311..5fa967c62 100644 --- a/perllib/FixMyStreet/Cobrand/Warwickshire.pm +++ b/perllib/FixMyStreet/Cobrand/Warwickshire.pm @@ -4,7 +4,7 @@ use base 'FixMyStreet::Cobrand::UKCouncils'; use strict; use warnings; -sub council_id { return 2243; } +sub council_area_id { return 2243; } sub council_area { return 'Warwickshire'; } sub council_name { return 'Warwickshire County Council'; } sub council_url { return 'warwickshire'; } diff --git a/perllib/FixMyStreet/Cobrand/WestBerkshire.pm b/perllib/FixMyStreet/Cobrand/WestBerkshire.pm index 7e98187bb..e13d701a6 100644 --- a/perllib/FixMyStreet/Cobrand/WestBerkshire.pm +++ b/perllib/FixMyStreet/Cobrand/WestBerkshire.pm @@ -4,7 +4,7 @@ use base 'FixMyStreet::Cobrand::UK'; use strict; use warnings; -sub council_id { 2619 } +sub council_area_id { 2619 } # non standard west berks end points sub open311_pre_send { |