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
|
package FixMyStreet::Cobrand::FixMyStreet;
use base 'FixMyStreet::Cobrand::UK';
use strict;
use warnings;
use mySociety::Random;
use constant COUNCIL_ID_BROMLEY => 2482;
sub on_map_default_status { return 'open'; }
sub enable_category_groups { 1 }
# Special extra
sub path_to_web_templates {
my $self = shift;
return [
FixMyStreet->path_to( 'templates/web/fixmystreet.com' ),
];
}
sub path_to_email_templates {
my ( $self, $lang_code ) = @_;
return [
FixMyStreet->path_to( 'templates', 'email', 'fixmystreet.com'),
];
}
sub add_response_headers {
my $self = shift;
# uncoverable branch true
return if $self->{c}->debug;
my $csp_nonce = $self->{c}->stash->{csp_nonce} = unpack('h*', mySociety::Random::random_bytes(16, 1));
$self->{c}->res->header('Content-Security-Policy', "script-src 'self' www.google-analytics.com www.googleadservices.com 'unsafe-inline' 'nonce-$csp_nonce'")
}
# FixMyStreet should return all cobrands
sub restriction {
return {};
}
sub title_list {
my $self = shift;
my $areas = shift;
my $first_area = ( values %$areas )[0];
return ["MR", "MISS", "MRS", "MS", "DR"] if $first_area->{id} eq COUNCIL_ID_BROMLEY;
return undef;
}
sub extra_contact_validation {
my $self = shift;
my $c = shift;
# Don't care about dest if reporting abuse
return () if $c->stash->{problem};
my %errors;
$c->stash->{dest} = $c->get_param('dest');
if (!$c->get_param('dest')) {
$errors{dest} = "Please enter who your message is for";
} elsif ( $c->get_param('dest') eq 'council' || $c->get_param('dest') eq 'update' ) {
$errors{not_for_us} = 1;
}
return %errors;
}
=head2 council_dashboard_hook
This is for council-specific dashboard pages, which can only be seen by
superusers and logged-in users with an email domain matching a body name.
=cut
sub council_dashboard_hook {
my $self = shift;
my $c = $self->{c};
unless ( $c->user_exists ) {
$c->res->redirect('/about/council-dashboard');
$c->detach;
}
$c->forward('/admin/fetch_contacts');
$c->detach('/reports/summary') if $c->user->is_superuser;
my $body = $c->user->from_body || _user_to_body($c);
if ($body) {
# Matching URL and user's email body
$c->detach('/reports/summary') if $body->id eq $c->stash->{body}->id;
# Matched /a/ body, redirect to its summary page
$c->stash->{body} = $body;
$c->stash->{wards} = [ { name => 'summary' } ];
$c->detach('/reports/redirect_body');
}
$c->res->redirect('/about/council-dashboard');
}
sub _user_to_body {
my $c = shift;
my $email = lc $c->user->email;
return _email_to_body($c, $email);
}
sub _email_to_body {
my ($c, $email) = @_;
my ($domain) = $email =~ m{ @ (.*) \z }x;
my @data = eval { FixMyStreet->path_to('../data/fixmystreet-councils.csv')->slurp };
my $body;
foreach (@data) {
chomp;
my ($d, $b) = split /\|/;
if ($d eq $domain) {
$body = $b;
last;
}
}
# If we didn't find a lookup entry, default to the first part of the domain
unless ($body) {
$domain =~ s/\.gov\.uk$//;
$body = ucfirst $domain;
}
$body = $c->forward('/reports/body_find', [ $body ]);
return $body;
}
sub about_hook {
my $self = shift;
my $c = $self->{c};
if ($c->stash->{template} eq 'about/council-dashboard.html') {
$c->stash->{form_name} = $c->get_param('name') || '';
$c->stash->{email} = $c->get_param('username') || '';
if ($c->user_exists) {
my $body = $c->user->from_body || _user_to_body($c);
if ($body) {
$c->stash->{body} = $body;
$c->stash->{wards} = [ { name => 'summary' } ];
$c->detach('/reports/redirect_body');
}
}
if (my $email = $c->get_param('username')) {
$email = lc $email;
$email =~ s/\s+//g;
my $body = _email_to_body($c, $email);
if ($body) {
# Send confirmation email (hopefully)
$c->stash->{template} = 'auth/general.html';
$c->detach('/auth/general');
} else {
$c->stash->{error} = 'bad_email';
}
}
}
}
1;
|