aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2019-11-15 14:41:14 +0000
committerStruan Donald <struan@exo.org.uk>2019-11-15 15:27:19 +0000
commit787f2972f0003ee467d84a87458ac2ae6aff1ae4 (patch)
tree344c540619c1a17df50f2bf01e316881294441ae
parent19ec44cbdf19f8c5711effff76735f20290e3855 (diff)
allow staff to submit in disabled categories
If a user belongs to a body override the disabled form check upon submission as mostly staff users can submit in those categories. Fixes mysociety/fixmystreet-freshdesk#98
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/Northamptonshire.pm9
-rw-r--r--t/app/controller/report_new_open311.t51
3 files changed, 64 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 8dec06e86..585337d8b 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -313,6 +313,10 @@ sub disable_form_message : Private {
my ( $self, $c ) = @_;
my %out;
+
+ # do not set disable form message if they are a staff user
+ return \%out if $c->cobrand->call_hook('staff_ignore_form_disable_form');
+
foreach (@{$c->stash->{category_extras}->{$c->stash->{category}}}) {
if ($_->{disable_form} && $_->{disable_form} eq 'true') {
$out{all} .= ' ' if $out{all};
diff --git a/perllib/FixMyStreet/Cobrand/Northamptonshire.pm b/perllib/FixMyStreet/Cobrand/Northamptonshire.pm
index 4ae3b6409..60def9e15 100644
--- a/perllib/FixMyStreet/Cobrand/Northamptonshire.pm
+++ b/perllib/FixMyStreet/Cobrand/Northamptonshire.pm
@@ -137,4 +137,13 @@ sub report_validation {
}
}
+sub staff_ignore_form_disable_form {
+ my $self = shift;
+
+ my $c = $self->{c};
+
+ return $c->user_exists
+ && $c->user->belongs_to_body( $self->body->id );
+}
+
1;
diff --git a/t/app/controller/report_new_open311.t b/t/app/controller/report_new_open311.t
index a0d122a7b..6551946c6 100644
--- a/t/app/controller/report_new_open311.t
+++ b/t/app/controller/report_new_open311.t
@@ -69,6 +69,19 @@ $mech->create_contact_ok(
email => '104',
);
+my $staff_user = $mech->create_user_ok('staff@example.org', name => 'staff', from_body => $body->id);
+
+my $body3 = $mech->create_body_ok(2234, 'Northamptonshire County Council');
+my $ncc_staff_user = $mech->create_user_ok('ncc_staff@example.org', name => 'ncc staff', from_body => $body3->id);
+$mech->create_contact_ok(
+ body_id => $body3->id,
+ category => 'Flooding',
+ email => '104',
+ extra => { _fields => [
+ { description => 'Please ring us!', code => 'ring', variable => 'false', order => '0', disable_form => 'true' }
+ ] },
+);
+
# test that the various bit of form get filled in and errors correctly
# generated.
my $empty_form = {
@@ -362,4 +375,42 @@ subtest "Category extras includes form disabling string" => sub {
};
};
+subtest "Staff users still see disable form categories" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'borsetshire',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+
+ $mech->log_in_ok($staff_user->email);
+
+ $contact2->push_extra_fields({ description => 'Please ring us!', code => 'ring', variable => 'false', order => '0', disable_form => 'true' });
+ $contact2->update;
+
+ # Test new non-JS form disabling flow
+ $mech->get_ok('/report/new?latitude=51.496194&longitude=-2.603439');
+ $mech->submit_form_ok({ with_fields => { category => 'Graffiti Removal' } });
+ $mech->content_contains('<div id="js-category-stopper" class="box-warning" role="alert" aria-live="assertive">');
+ $mech->content_contains('Please ring us!');
+ };
+};
+
+subtest "Staff users disable form categories" => sub {
+ FixMyStreet::override_config {
+ ALLOWED_COBRANDS => 'northamptonshire',
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $mech->log_out_ok;
+ $mech->log_in_ok($ncc_staff_user->email);
+
+ $mech->get_ok('/report/new?latitude=52.236251&longitude=-0.892052');
+ $mech->submit_form_ok({ with_fields => {
+ category => 'Flooding', title => 'Title', detail => 'Detail',
+ } });
+
+ my $prob = $ncc_staff_user->problems->first;
+ ok $prob, 'problem created';
+ is $prob->title, "Title", 'Report title correct';
+ };
+};
+
done_testing();