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/DB | |
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/DB')
-rw-r--r-- | perllib/FixMyStreet/DB/Factories.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 15 |
3 files changed, 19 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/DB/Factories.pm b/perllib/FixMyStreet/DB/Factories.pm index e877ffd9f..c3060507e 100644 --- a/perllib/FixMyStreet/DB/Factories.pm +++ b/perllib/FixMyStreet/DB/Factories.pm @@ -44,8 +44,6 @@ __PACKAGE__->fields({ ####################### -# This currently creates special 'UK' bodies, with ID == MapIt area_id. -# We should try and end this, it is just confusing. package FixMyStreet::DB::Factory::Body; use parent -norequire, "FixMyStreet::DB::Factory::Base"; @@ -56,10 +54,6 @@ __PACKAGE__->resultset(FixMyStreet::DB->resultset("Body")); __PACKAGE__->exclude(['area_id', 'categories']); __PACKAGE__->fields({ - id => __PACKAGE__->callback(sub { - my $area_id = shift->get('area_id'); - $area_id; - }), name => __PACKAGE__->callback(sub { my $area_id = shift->get('area_id'); my $area = mySociety::MaPit::call('area', $area_id); diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index d59245c15..1218d2f76 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -128,9 +128,10 @@ sub check_for_errors { unless $self->text =~ m/\S/; # Bromley Council custom character limit - if ( $self->text && $self->problem && $self->problem->bodies_str - && $self->problem->bodies_str eq '2482' && length($self->text) > 1750 ) { - $errors{update} = sprintf( _('Updates are limited to %s characters in length. Please shorten your update'), 1750 ); + if ( $self->text && $self->problem && $self->problem->bodies_str) { + if ($self->problem->to_body_named('Bromley') && length($self->text) > 1750) { + $errors{update} = sprintf( _('Updates are limited to %s characters in length. Please shorten your update'), 1750 ); + } } return \%errors; @@ -281,10 +282,7 @@ sub meta_line { $update_state = _( 'marked as an internal referral' ) } - if ($c->cobrand->moniker eq 'bromley' || ( - $self->problem->bodies_str && - $self->problem->bodies_str eq '2482' - )) { + if ($c->cobrand->moniker eq 'bromley' || $self->problem->to_body_named('Bromley')) { if ($state eq 'not responsible') { $update_state = 'marked as third party responsibility' } diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 6703a5102..f62ed6d47 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -510,6 +510,19 @@ sub bodies($) { return { map { $_->id => $_ } @bodies }; } +sub body_names($) { + my $self = shift; + my $bodies = $self->bodies; + my @names = map { $_->name } values %$bodies; + return \@names; +} + +sub to_body_named($$) { + my ($self, $re) = @_; + my $names = join(',,', @{$self->body_names}); + $names =~ /$re/; +} + =head2 url Returns a URL for this problem report. @@ -774,7 +787,7 @@ sub defect_types { # Note: this only makes sense when called on a problem that has been sent! sub can_display_external_id { my $self = shift; - if ($self->external_id && $self->send_method_used && $self->bodies_str =~ /(2237|2550)/) { + if ($self->external_id && $self->send_method_used && $self->to_body_named('Oxfordshire|Angus')) { return 1; } return 0; |