diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 19 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 17 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 21 | ||||
-rw-r--r-- | templates/web/default/report/display.html | 2 |
5 files changed, 59 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 03130f60b..add9d1371 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -180,8 +180,7 @@ sub process_update : Private { if ( $params{state} ) { $params{state} = 'fixed - council' - if $params{state} eq 'fixed' && $c->user && $c->user->from_council - && $c->user->from_council == $update->problem->council; + if $params{state} eq 'fixed' && $c->user && $c->user->belongs_to_council( $update->problem->council ); $update->problem_state( $params{state} ); } @@ -205,7 +204,7 @@ sub check_for_errors : Private { # they have to be an authority user to update the state if ( $c->req->param('state') ) { my $error = 0; - $error = 1 unless $c->user && $c->user->from_council && $c->user->from_council == $c->stash->{update}->problem->council; + $error = 1 unless $c->user && $c->user->belongs_to_council( $c->stash->{update}->problem->council ); my $state = $c->req->param('state'); $error = 1 unless ( grep { $state eq $_ } ( qw/confirmed closed fixed investigating planned/, 'in progress', 'fixed', 'fixed - user', 'fixed - council' ) ); diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index ada19a406..ceced7267 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -151,4 +151,23 @@ sub council { return $result; } +=head2 belongs_to_council + + $belongs_to_council = $user->belongs_to_council( $council_list ); + +Returns true if the user belongs to the comma seperated list of council ids passed in + +=cut + +sub belongs_to_council { + my $self = shift; + my $council = shift; + + my %councils = map { $_ => 1 } split ',', $council; + + return 1 if $self->from_council && $councils{ $self->from_council }; + + return 0; +} + 1; diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 23b76fbc4..a70d5b9e9 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -313,16 +313,25 @@ for my $test ( desc => 'no state dropdown if user not from authority', from_council => 0, no_state => 1, + report_council => '2504', }, { desc => 'state dropdown if user from authority', from_council => 2504, no_state => 0, + report_council => '2504', }, { desc => 'no state dropdown if user not from same council as problem', from_council => 2505, no_state => 1, + report_council => '2504', + }, + { + desc => 'state dropdown if user from authority and problem sent to multiple councils', + from_council => 2504, + no_state => 0, + report_council => '2504,2506', }, ) { subtest $test->{desc} => sub { @@ -330,6 +339,10 @@ for my $test ( $user->from_council( $test->{from_council} ); $user->update; + $report->discard_changes; + $report->council( $test->{report_council} ); + $report->update; + $mech->get_ok("/report/$report_id"); my $fields = $mech->visible_form_values( 'updateForm' ); if ( $test->{no_state} ) { @@ -340,6 +353,10 @@ for my $test ( }; } +$report->discard_changes; +$report->council( 2504 ); +$report->update; + # tidy up $mech->delete_user('test@example.com'); done_testing(); diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index 0a9c5db1f..d7b234a6e 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -539,14 +539,31 @@ for my $test ( may_show_name => 1, add_alert => 0, photo => '', - update => 'Set state to investigating', + update => 'Set state to confirmed', state => 'confirmed', }, state => 'confirmed', }, + { + desc => 'from authority user marks report sent to two councils as fixed', + fields => { + name => $user->name, + may_show_name => 1, + add_alert => 0, + photo => '', + update => 'Set state to fixed', + state => 'fixed', + }, + state => 'fixed - council', + report_councils => '2504,2505', + }, ) { subtest $test->{desc} => sub { $report->comments->delete; + if ( $test->{ report_councils } ) { + $report->council( $test->{ report_councils } ); + $report->update; + } $mech->log_in_ok( $user->email ); $user->from_council( 2504 ); @@ -561,6 +578,7 @@ for my $test ( 'submit update' ); + $report->discard_changes; my $update = $report->comments->first; ok $update, 'found update'; is $update->text, $test->{fields}->{update}, 'update text'; @@ -580,6 +598,7 @@ $user->from_council(0); $user->update; $report->state('confirmed'); +$report->council('2504'); $report->update; for my $test ( diff --git a/templates/web/default/report/display.html b/templates/web/default/report/display.html index a9ce12dd4..b3eb0d779 100644 --- a/templates/web/default/report/display.html +++ b/templates/web/default/report/display.html @@ -85,7 +85,7 @@ <textarea name="update" id="form_update" rows="7" cols="30">[% update.text | html %]</textarea> </div> - [% IF c.user && c.user.from_council && c.user.from_council == problem.council %] + [% IF c.user && c.user.belongs_to_council( problem.council ) %] <div class="form-field"> <label for="form_state">[% loc( 'State:' ) %]</label> <select name="state" id="form_state"> |