aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-08-28 14:36:59 +0100
committerMatthew Somerville <matthew@mysociety.org>2019-08-30 11:39:47 +0100
commit71b8013bf89590d78fbe757b74d24be912026e9f (patch)
treee2761fdbc959651d97b50207dc0b98ce9d4dc86f
parentbe0da54c728359938cfe003107921a8e5e73036e (diff)
[UK Councils] Config specifying of update closure.
A cobrand feature flag can be used to only allow updates on open reports, by the original reporter, to staff only, or to no-one.
-rw-r--r--perllib/FixMyStreet/Cobrand/FixMyStreet.pm34
-rw-r--r--perllib/FixMyStreet/Cobrand/UKCouncils.pm24
-rw-r--r--perllib/FixMyStreet/Cobrand/Westminster.pm11
-rw-r--r--t/cobrand/councils.t42
-rw-r--r--t/cobrand/westminster.t13
-rw-r--r--templates/web/base/report/_updates_disallowed_message.html5
6 files changed, 118 insertions, 11 deletions
diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
index 5c2aa2be1..015da5e0b 100644
--- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
+++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm
@@ -166,4 +166,38 @@ sub about_hook {
}
}
+sub updates_disallowed {
+ my $self = shift;
+ my ($problem) = @_;
+ my $c = $self->{c};
+
+ # This is a hash of council name to match, and what to do
+ my $cfg = $self->feature('updates_allowed') || {};
+
+ my $type = '';
+ my $body;
+ foreach (keys %$cfg) {
+ if ($problem->to_body_named($_)) {
+ $type = $cfg->{$_};
+ $body = $_;
+ last;
+ }
+ }
+
+ if ($type eq 'none') {
+ return 1;
+ } elsif ($type eq 'staff') {
+ # Only staff and superusers can leave updates
+ my $staff = $c->user_exists && $c->user->from_body && $c->user->from_body->name =~ /$body/;
+ my $superuser = $c->user_exists && $c->user->is_superuser;
+ return 1 unless $staff || $superuser;
+ } elsif ($type eq 'reporter') {
+ return 1 if !$c->user_exists || $c->user->id != $problem->user->id;
+ } elsif ($type eq 'open') {
+ return 1 if $problem->is_fixed || $problem->is_closed;
+ }
+
+ return $self->next::method(@_);
+}
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
index b59c8990b..9f4610143 100644
--- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm
+++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm
@@ -372,6 +372,30 @@ sub contact_email {
return $self->feature('contact_email') || $self->next::method();
}
+# Allow cobrands to disallow updates on some things.
+# Note this only ever locks down more than the default.
+sub updates_disallowed {
+ my $self = shift;
+ my ($problem) = @_;
+ my $c = $self->{c};
+
+ my $cfg = $self->feature('updates_allowed') || '';
+ if ($cfg eq 'none') {
+ return 1;
+ } elsif ($cfg eq 'staff') {
+ # Only staff and superusers can leave updates
+ my $staff = $c->user_exists && $c->user->from_body && $c->user->from_body->name eq $self->council_name;
+ my $superuser = $c->user_exists && $c->user->is_superuser;
+ return 1 unless $staff || $superuser;
+ } elsif ($cfg eq 'reporter') {
+ return 1 if !$c->user_exists || $c->user->id != $problem->user->id;
+ } elsif ($cfg eq 'open') {
+ return 1 if $problem->is_fixed || $problem->is_closed;
+ }
+
+ return $self->next::method(@_);
+}
+
sub extra_contact_validation {
my $self = shift;
my $c = shift;
diff --git a/perllib/FixMyStreet/Cobrand/Westminster.pm b/perllib/FixMyStreet/Cobrand/Westminster.pm
index 95da0c5aa..b3ab35b7b 100644
--- a/perllib/FixMyStreet/Cobrand/Westminster.pm
+++ b/perllib/FixMyStreet/Cobrand/Westminster.pm
@@ -32,17 +32,6 @@ sub enter_postcode_text {
sub send_questionnaires { 0 }
-sub updates_disallowed {
- my $self = shift;
- my $c = $self->{c};
-
- # Only WCC staff and superusers can leave updates
- my $staff = $c->user_exists && $c->user->from_body && $c->user->from_body->name eq $self->council_name;
- my $superuser = $c->user_exists && $c->user->is_superuser;
-
- return ( $staff || $superuser ) ? 0 : 1;
- }
-
sub suppress_reporter_alerts { 1 }
sub report_age { '3 months' }
diff --git a/t/cobrand/councils.t b/t/cobrand/councils.t
index c44605bd9..1cd9c491e 100644
--- a/t/cobrand/councils.t
+++ b/t/cobrand/councils.t
@@ -47,4 +47,46 @@ foreach my $test (
};
+subtest "Test update shown/not shown appropriately" => sub {
+ my $user = $mech->create_user_ok('test@example.com');
+ foreach my $cobrand ('oxfordshire', 'fixmystreet') {
+ foreach my $test (
+ # Three bools are logged out, reporter, staff user
+ { type => 'none', update => [0,0,0] },
+ { type => 'staff', update => [0,0,1] },
+ { type => 'reporter', update => [0,1,1] },
+ { type => 'open', state => 'closed', update => [0,0,0] },
+ { type => 'open', state => 'in progress', update => [1,1,1] },
+ ) {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => $cobrand,
+ MAPIT_URL => 'http://mapit.uk/',
+ COBRAND_FEATURES => {
+ updates_allowed => {
+ oxfordshire => $test->{type},
+ fixmystreet => {
+ Oxfordshire => $test->{type},
+ }
+ }
+ },
+ }, sub {
+ subtest "$cobrand, $test->{type}" => sub {
+ $report->update({ state => $test->{state} || 'confirmed' });
+ $mech->log_out_ok;
+ $user->update({ from_body => undef });
+ $mech->get_ok("/report/$report_id");
+ $mech->contains_or_lacks($test->{update}[0], 'Provide an update');
+ $mech->log_in_ok('test@example.com');
+ $mech->get_ok("/report/$report_id");
+ $mech->contains_or_lacks($test->{update}[1], 'Provide an update');
+ $user->update({ from_body => $oxon->id });
+ $mech->get_ok("/report/$report_id");
+ $mech->contains_or_lacks($test->{update}[2], 'Provide an update');
+ };
+ };
+ }
+ }
+};
+
+
done_testing();
diff --git a/t/cobrand/westminster.t b/t/cobrand/westminster.t
index f223cf4a3..1ceeef6cb 100644
--- a/t/cobrand/westminster.t
+++ b/t/cobrand/westminster.t
@@ -29,6 +29,9 @@ FixMyStreet::override_config {
ALLOWED_COBRANDS => 'westminster',
MAPIT_URL => 'http://mapit.uk/',
COBRAND_FEATURES => {
+ updates_allowed => {
+ westminster => 'staff',
+ },
oidc_login => {
westminster => {
client_id => 'example_client_id',
@@ -64,6 +67,11 @@ subtest 'Reports have an update form for superusers' => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'westminster',
MAPIT_URL => 'http://mapit.uk/',
+ COBRAND_FEATURES => {
+ updates_allowed => {
+ westminster => 'staff',
+ },
+ },
}, sub {
$mech->get_ok('/report/' . $report->id);
$mech->content_contains('Provide an update');
@@ -77,6 +85,11 @@ subtest 'Reports have an update form for staff users' => sub {
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'westminster',
MAPIT_URL => 'http://mapit.uk/',
+ COBRAND_FEATURES => {
+ updates_allowed => {
+ westminster => 'staff',
+ },
+ },
}, sub {
$mech->get_ok('/report/' . $report->id);
$mech->content_contains('Provide an update');
diff --git a/templates/web/base/report/_updates_disallowed_message.html b/templates/web/base/report/_updates_disallowed_message.html
new file mode 100644
index 000000000..de2e36382
--- /dev/null
+++ b/templates/web/base/report/_updates_disallowed_message.html
@@ -0,0 +1,5 @@
+<p>[% loc('This report is now closed to updates.') %]
+ [% tprintf(loc('You can <a href="%s">make a new report in the same location</a>.'),
+ c.uri_for( '/report/new', { longitude = longitude, latitude = latitude } )
+ ) %]
+</p>