1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
package FixMyStreet::Cobrand::Buckinghamshire;
use parent 'FixMyStreet::Cobrand::Whitelabel';
use strict;
use warnings;
use Moo;
with 'FixMyStreet::Roles::ConfirmOpen311';
with 'FixMyStreet::Roles::ConfirmValidation';
with 'FixMyStreet::Roles::BoroughEmails';
sub council_area_id { return 2217; }
sub council_area { return 'Buckinghamshire'; }
sub council_name { return 'Buckinghamshire Council'; }
sub council_url { return 'buckinghamshire'; }
sub disambiguate_location {
my $self = shift;
my $string = shift;
my $town = 'Buckinghamshire';
return {
%{ $self->SUPER::disambiguate_location() },
town => $town,
centre => '51.7852948471218,-0.812140044990842',
span => '0.596065946222112,0.664092167105497',
bounds => [ 51.4854160129405, -1.1406945585036, 52.0814819591626, -0.476602391398098 ],
};
}
sub on_map_default_status { 'open' }
sub pin_colour {
my ( $self, $p, $context ) = @_;
return 'grey' if $p->state eq 'not responsible' || !$self->owns_problem( $p );
return 'green' if $p->is_fixed || $p->is_closed;
return 'red' if $p->state eq 'confirmed';
return 'yellow';
}
sub admin_user_domain { ( 'buckscc.gov.uk', 'buckinghamshire.gov.uk' ) }
sub send_questionnaires {
return 0;
}
sub open311_pre_send {
my ($self, $row, $open311) = @_;
return unless $row->extra;
my $extra = $row->get_extra_fields;
if (@$extra) {
@$extra = grep { $_->{name} ne 'road-placement' } @$extra;
$row->set_extra_fields(@$extra);
}
}
sub open311_post_send {
my ($self, $row, $h) = @_;
# Check Open311 was successful
return unless $row->external_id;
# For certain categories, send an email also
my $emails = $self->feature('open311_email');
my $addresses = {
'Flytipping' => [ $emails->{flytipping}, "TfB" ],
'Blocked drain' => [ $emails->{flood}, "Flood Management" ],
'Ditch issue' => [ $emails->{flood}, "Flood Management" ],
'Flooded subway' => [ $emails->{flood}, "Flood Management" ],
};
my $dest = $addresses->{$row->category};
return unless $dest;
my $sender = FixMyStreet::SendReport::Email->new( to => [ $dest ] );
$sender->send($row, $h);
}
sub open311_config_updates {
my ($self, $params) = @_;
$params->{mark_reopen} = 1;
}
sub open311_contact_meta_override {
my ($self, $service, $contact, $meta) = @_;
push @$meta, {
code => 'road-placement',
datatype => 'singlevaluelist',
description => 'Is the fly-tip located on',
order => 100,
required => 'true',
variable => 'true',
values => [
{ key => 'road', name => 'The road' },
{ key => 'off-road', name => 'Off the road/on a verge' },
],
} if $service->{service_name} eq 'Flytipping';
}
sub report_new_munge_before_insert {
my ($self, $report) = @_;
return unless $report->category eq 'Flytipping';
my $placement = $self->{c}->get_param('road-placement');
return unless $placement && $placement eq 'off-road';
$report->category('Flytipping (off-road)');
}
sub filter_report_description {
my ($self, $description) = @_;
# this allows _ in the domain name but I figure it's unlikely to
# generate false positives so lets go with that for the same of
# a simpler regex
$description =~ s/\b[\w.!#$%&'*+\-\/=?^_{|}~]+\@[\w\-]+\.[^ ]+\b//g;
$description =~ s/ (?: \+ \d{2} \s? | \b 0 ) (?:
\d{2} \s? \d{4} \s? \d{4} # 0xx( )xxxx( )xxxx
| \d{3} \s \d{3} \s? \d{4} # 0xxx xxx( )xxxx
| \d{3} \s? \d{2} \s \d{4,5} # 0xxx( )xx xxxx(x)
| \d{4} \s \d{5,6} # 0xxxx xxxxx(x)
) \b //gx;
return $description;
}
sub map_type { 'Buckinghamshire' }
sub default_map_zoom { 3 }
sub _dashboard_export_add_columns {
my $self = shift;
my $c = $self->{c};
push @{$c->stash->{csv}->{headers}}, "Staff User";
push @{$c->stash->{csv}->{columns}}, "staff_user";
# All staff users, for contributed_by lookup
my @user_ids = $c->model('DB::User')->search(
{ from_body => $self->body->id },
{ columns => [ 'id', 'email', ] })->all;
my %user_lookup = map { $_->id => $_->email } @user_ids;
$c->stash->{csv}->{extra_data} = sub {
my $report = shift;
my $staff_user = '';
if (my $contributed_by = $report->get_extra_metadata('contributed_by')) {
$staff_user = $user_lookup{$contributed_by};
}
return {
staff_user => $staff_user,
};
};
}
sub dashboard_export_updates_add_columns {
shift->_dashboard_export_add_columns;
}
sub dashboard_export_problems_add_columns {
shift->_dashboard_export_add_columns;
}
# Enable adding/editing of parish councils in the admin
sub add_extra_areas {
my ($self, $areas) = @_;
# This is a list of all Parish Councils within Buckinghamshire,
# taken from https://mapit.mysociety.org/area/2217/covers.json?type=CPC
my $parish_ids = [
"135493",
"135494",
"148713",
"148714",
"53319",
"53360",
"53390",
"53404",
"53453",
"53486",
"53515",
"53542",
"53612",
"53822",
"53874",
"53887",
"53942",
"53991",
"54003",
"54014",
"54158",
"54174",
"54178",
"54207",
"54289",
"54305",
"54342",
"54355",
"54402",
"54465",
"54479",
"54493",
"54590",
"54615",
"54672",
"54691",
"54721",
"54731",
"54787",
"54846",
"54879",
"54971",
"55290",
"55326",
"55534",
"55638",
"55724",
"55775",
"55896",
"55900",
"55915",
"55945",
"55973",
"56007",
"56091",
"56154",
"56268",
"56350",
"56379",
"56418",
"56432",
"56498",
"56524",
"56592",
"56609",
"56641",
"56659",
"56664",
"56709",
"56758",
"56781",
"57099",
"57138",
"57330",
"57332",
"57366",
"57367",
"57507",
"57529",
"57582",
"57585",
"57666",
"57701",
"58166",
"58208",
"58229",
"58279",
"58312",
"58333",
"58405",
"58523",
"58659",
"58815",
"58844",
"58891",
"58965",
"58980",
"59003",
"59007",
"59012",
"59067",
"59144",
"59152",
"59179",
"59211",
"59235",
"59288",
"59353",
"59491",
"59518",
"59727",
"59763",
"59971",
"60027",
"60137",
"60321",
"60322",
"60438",
"60456",
"60462",
"60532",
"60549",
"60598",
"60622",
"60640",
"60731",
"60777",
"60806",
"60860",
"60954",
"61100",
"61102",
"61107",
"61142",
"61144",
"61167",
"61172",
"61249",
"61268",
"61269",
"61405",
"61445",
"61471",
"61479",
"61898",
"61902",
"61920",
"61964",
"62226",
"62267",
"62296",
"62311",
"62321",
"62431",
"62454",
"62640",
"62657",
"62938",
"63040",
"63053",
"63068",
"63470",
"63476",
"63501",
"63507",
"63517",
"63554",
"63715",
"63723"
];
my $ids_string = join ",", @{ $parish_ids };
my $extra_areas = mySociety::MaPit::call('areas', [ $ids_string ]);
my %all_areas = (
%$areas,
%$extra_areas
);
return \%all_areas;
}
# Make sure CPC areas are included in point lookups for new reports
sub add_extra_area_types {
my ($self, $types) = @_;
my @types = (
@$types,
'CPC',
);
return \@types;
}
sub is_two_tier { 1 }
sub should_skip_sending_update {
my ($self, $update ) = @_;
# Bucks don't want to receive updates into Confirm that were made by anyone
# except the original problem reporter.
return $update->user_id != $update->problem->user_id;
}
sub disable_phone_number_entry { 1 }
sub report_sent_confirmation_email { 'external_id' }
sub is_council_with_case_management { 1 }
# Try OSM for Bucks as it provides better disamiguation descriptions.
sub get_geocoder { 'OSM' }
sub categories_restriction {
my ($self, $rs) = @_;
return $rs->search( { category => { '!=', 'Flytipping (off-road)'} } );
}
sub lookup_site_code_config { {
buffer => 200, # metres
url => "https://tilma.mysociety.org/mapserver/bucks",
srsname => "urn:ogc:def:crs:EPSG::27700",
typename => "Whole_Street",
property => "site_code",
accept_feature => sub {
my $feature = shift;
# There are only certain features we care about, the rest can be ignored.
my @valid_types = ( "2", "3A", "3B", "4A", "4B", "HE", "HWOA", "HWSA", "P" );
my %valid_types = map { $_ => 1 } @valid_types;
my $type = $feature->{properties}->{feature_ty};
return $valid_types{$type};
}
} }
around 'munge_sendreport_params' => sub {
my ($orig, $self, $row, $h, $params) = @_;
# The district areas don't exist in MapIt past generation 36, so look up
# what district this report would have been in and temporarily override
# the areas column so BoroughEmails::munge_sendreport_params can do its
# thing.
my ($lat, $lon) = ($row->latitude, $row->longitude);
my $district = FixMyStreet::MapIt::call( 'point', "4326/$lon,$lat", type => 'DIS', generation => 36 );
($district) = keys %$district;
my $original_areas = $row->areas;
$row->areas(",$district,");
$self->$orig($row, $h, $params);
$row->areas($original_areas);
};
1;
|