diff options
author | Struan Donald <struan@exo.org.uk> | 2011-06-27 11:03:57 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2011-06-27 11:03:57 +0100 |
commit | a20fc533b0f10646814742f1348c5f9141217efa (patch) | |
tree | 742b49b1347262bd971e397f1d3d52be7c7140d7 | |
parent | df18e6c8b434dfd86177cf5041278fd46d6d2ea7 (diff) |
change to use from_council in users table and store the council id in
there so we can check that the problem is for the council the user is
from
-rw-r--r-- | db/schema_0005-add_council_user_flag.sql | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 8 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 19 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 8 | ||||
-rw-r--r-- | templates/web/default/report/display.html | 2 |
7 files changed, 28 insertions, 20 deletions
diff --git a/db/schema_0005-add_council_user_flag.sql b/db/schema_0005-add_council_user_flag.sql index d8cf1358a..1ab1579b7 100644 --- a/db/schema_0005-add_council_user_flag.sql +++ b/db/schema_0005-add_council_user_flag.sql @@ -1,6 +1,6 @@ begin; ALTER table users - ADD COLUMN from_authority boolean NOT NULL DEFAULT false; + ADD COLUMN from_council integer; commit; diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 2d810d871..652694595 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -153,7 +153,8 @@ sub process_update : Private { if ( $params{state} ) { $params{state} = 'fixed - council' - if $params{state} eq 'fixed' && $c->user && $c->user->from_authority; + if $params{state} eq 'fixed' && $c->user && $c->user->from_council + && $c->user->from_council == $update->problem->council; $update->problem_state( $params{state} ); } @@ -177,7 +178,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_authority; + $error = 1 unless $c->user && $c->user->from_council && $c->user->from_council == $c->stash->{update}->problem->council; my $state = $c->req->param('state'); $error = 1 unless ( grep { $state eq $_ } ( qw/closed fixed investigating planned/, 'in progress', 'fixed', 'fixed - user', 'fixed - council' ) ); diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 9ed9d8b48..00f88e136 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -70,8 +70,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-23 14:25:34 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:scnPU5RAGLnT0fY1gM6Z5A +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-27 10:07:32 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ilLn3dlagg5COdpZDmzrVQ use DateTime::TimeZone; use Image::Size; diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index c7e5e94af..ade8ca934 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -26,8 +26,8 @@ __PACKAGE__->add_columns( { data_type => "text", is_nullable => 1 }, "password", { data_type => "text", default_value => "", is_nullable => 0 }, - "from_authority", - { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "from_council", + { data_type => "integer", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("users_email_key", ["email"]); @@ -51,8 +51,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-22 16:10:43 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:zQIniwAXjl5Lh9wyiGuwFw +# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-27 10:25:21 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9IHuqRTcHZCqJeBAaiQxzw __PACKAGE__->add_columns( "password" => { diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index fc844e31c..23b76fbc4 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -311,24 +311,31 @@ for my $test ( for my $test ( { desc => 'no state dropdown if user not from authority', - from_authority => 0, + from_council => 0, + no_state => 1, }, { desc => 'state dropdown if user from authority', - from_authority => 1, + from_council => 2504, + no_state => 0, + }, + { + desc => 'no state dropdown if user not from same council as problem', + from_council => 2505, + no_state => 1, }, ) { subtest $test->{desc} => sub { $mech->log_in_ok( $user->email ); - $user->from_authority( $test->{from_authority} ); + $user->from_council( $test->{from_council} ); $user->update; $mech->get_ok("/report/$report_id"); my $fields = $mech->visible_form_values( 'updateForm' ); - if ( $test->{from_authority} ) { - ok $fields->{state}; - } else { + if ( $test->{no_state} ) { ok !$fields->{state}; + } else { + ok $fields->{state}; } }; } diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index f0916610b..35e8b9e5f 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -387,7 +387,7 @@ $report->update; subtest 'check non authority user cannot change set state' => sub { $mech->log_in_ok( $user->email ); - $user->from_authority( 0 ); + $user->from_council( 0 ); $user->update; $mech->get_ok("/report/$report_id"); @@ -419,7 +419,7 @@ subtest 'check non authority user cannot change set state' => sub { for my $state ( qw/unconfirmed hidden partial/ ) { subtest "check that update cannot set state to $state" => sub { $mech->log_in_ok( $user->email ); - $user->from_authority( 1 ); + $user->from_council( 2504 ); $user->update; $mech->get_ok("/report/$report_id"); @@ -515,7 +515,7 @@ for my $test ( $report->comments->delete; $mech->log_in_ok( $user->email ); - $user->from_authority( 1 ); + $user->from_council( 2504 ); $user->update; $mech->get_ok("/report/$report_id"); @@ -540,7 +540,7 @@ for my $test ( }; } -$user->from_authority(0); +$user->from_council(0); $user->update; $report->state('confirmed'); diff --git a/templates/web/default/report/display.html b/templates/web/default/report/display.html index 25f3892a6..a8a58ffce 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_authority %] + [% IF c.user && c.user.from_council && c.user.from_council == problem.council %] <div class="form-field"> <label for="form_state">[% loc( 'State:' ) %]</label> <select name="state" id="form_state"> |