aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/schema.sql2
-rw-r--r--db/schema_0032-add-from_body-reference.sql6
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm2
-rw-r--r--perllib/FixMyStreet/App/Controller/Dashboard.pm10
-rw-r--r--perllib/FixMyStreet/DB/Result/Body.pm10
-rw-r--r--perllib/FixMyStreet/DB/Result/User.pm33
-rw-r--r--t/app/controller/admin.t5
-rw-r--r--t/app/controller/report_display.t5
-rw-r--r--t/app/controller/report_interest_count.t22
-rw-r--r--t/app/controller/report_updates.t12
-rw-r--r--templates/web/default/admin/update_edit.html4
-rw-r--r--templates/web/default/admin/user_edit.html2
-rw-r--r--templates/web/default/admin/users.html2
13 files changed, 65 insertions, 50 deletions
diff --git a/db/schema.sql b/db/schema.sql
index 1608b08ba..8045ca6c4 100644
--- a/db/schema.sql
+++ b/db/schema.sql
@@ -111,7 +111,7 @@ create table users (
name text,
phone text,
password text not null default '',
- from_body integer, -- id of body user is from or null/0 if not
+ from_body integer references body(id), -- id of body user is from or null/0 if not
flagged boolean not null default 'f',
title text
);
diff --git a/db/schema_0032-add-from_body-reference.sql b/db/schema_0032-add-from_body-reference.sql
new file mode 100644
index 000000000..4fa526963
--- /dev/null
+++ b/db/schema_0032-add-from_body-reference.sql
@@ -0,0 +1,6 @@
+begin;
+
+ALTER TABLE users ADD CONSTRAINT users_from_body_fkey
+ FOREIGN KEY (from_body) REFERENCES body(id);
+
+commit;
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index d64ca4862..56789b81c 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -827,7 +827,7 @@ sub user_edit : Path('user_edit') : Args(1) {
if ( $user->email ne $c->req->param('email') ||
$user->name ne $c->req->param('name' ) ||
- $user->from_body != $c->req->param('body') ) {
+ $user->from_body->id != $c->req->param('body') ) {
$edited = 1;
}
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm
index a355606f4..3a66cf1e0 100644
--- a/perllib/FixMyStreet/App/Controller/Dashboard.pm
+++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm
@@ -88,19 +88,19 @@ Show the dashboard table.
sub index : Path : Args(0) {
my ( $self, $c ) = @_;
- my $council = $c->forward('check_page_allowed');
+ my $body = $c->forward('check_page_allowed');
# Set up the data for the dropdowns
- my $council_detail = mySociety::MaPit::call('area', $council );
+ my $council_detail = mySociety::MaPit::call('area', $body->area_id );
$c->stash->{council} = $council_detail;
- my $children = mySociety::MaPit::call('area/children', $council,
+ my $children = mySociety::MaPit::call('area/children', $body->area_id,
type => $c->cobrand->area_types_children,
);
$c->stash->{children} = $children;
- $c->stash->{all_areas} = { $council => $council_detail };
+ $c->stash->{all_areas} = { $body->area_id => $council_detail };
$c->forward( '/report/new/setup_categories_and_bodies' );
# See if we've had anything from the dropdowns
@@ -109,7 +109,7 @@ sub index : Path : Args(0) {
$c->stash->{category} = $c->req->param('category');
my %where = (
- bodies_str => $council, # XXX This will break in a two tier council. Restriction needs looking at...
+ bodies_str => $body->id, # XXX Does this break in a two tier council? Restriction needs looking at...
'problem.state' => [ FixMyStreet::DB::Result::Problem->visible_states() ],
);
$where{areas} = { 'like', '%,' . $c->stash->{ward} . ',%' }
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm
index 7f5777908..e4725d141 100644
--- a/perllib/FixMyStreet/DB/Result/Body.pm
+++ b/perllib/FixMyStreet/DB/Result/Body.pm
@@ -58,10 +58,16 @@ __PACKAGE__->has_many(
{ "foreign.body_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
+__PACKAGE__->has_many(
+ "users",
+ "FixMyStreet::DB::Result::User",
+ { "foreign.from_body" => "self.id" },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-13 12:36:19
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Yl1KHSUzPi7KDjMenUe8qw
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 09:23:59
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tvTHtIa0GrtptadZYHEM1Q
# You can replace this text with custom code or comments, and it will be preserved on regeneration
diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm
index 997577b69..481b654c9 100644
--- a/perllib/FixMyStreet/DB/Result/User.pm
+++ b/perllib/FixMyStreet/DB/Result/User.pm
@@ -27,7 +27,7 @@ __PACKAGE__->add_columns(
"password",
{ data_type => "text", default_value => "", is_nullable => 0 },
"from_body",
- { data_type => "integer", is_nullable => 1 },
+ { data_type => "integer", is_foreign_key => 1, is_nullable => 1 },
"flagged",
{ data_type => "boolean", default_value => \"false", is_nullable => 0 },
"title",
@@ -53,6 +53,17 @@ __PACKAGE__->has_many(
{ "foreign.user_id" => "self.id" },
{ cascade_copy => 0, cascade_delete => 0 },
);
+__PACKAGE__->belongs_to(
+ "from_body",
+ "FixMyStreet::DB::Result::Body",
+ { id => "from_body" },
+ {
+ is_deferrable => 1,
+ join_type => "LEFT",
+ on_delete => "CASCADE",
+ on_update => "CASCADE",
+ },
+);
__PACKAGE__->has_many(
"problems",
"FixMyStreet::DB::Result::Problem",
@@ -61,8 +72,8 @@ __PACKAGE__->has_many(
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-12 13:06:09
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:L6gtjOQeVkebGUIHJcHuUA
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 09:23:59
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:aw374WQraL5ysOvUmUIU3w
__PACKAGE__->add_columns(
"password" => {
@@ -146,20 +157,8 @@ sub alert_for_problem {
sub body {
my $self = shift;
-
return '' unless $self->from_body;
-
- my $key = 'body_name:' . $self->from_body;
- my $result = Memcached::get($key);
-
- ### TODO: Add a 'name' column to body which is used instead of calling mapit
- unless ($result) {
- my $area_info = mySociety::MaPit::call('area', $self->from_body);
- $result = $area_info->{name};
- Memcached::set($key, $result, 86400);
- }
-
- return $result;
+ return $self->from_body->name;
}
=head2 belongs_to_body
@@ -176,7 +175,7 @@ sub belongs_to_body {
my %bodies = map { $_ => 1 } split ',', $bodies;
- return 1 if $self->from_body && $bodies{ $self->from_body };
+ return 1 if $self->from_body && $bodies{ $self->from_body->id };
return 0;
}
diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t
index a43a875c3..d759c1238 100644
--- a/t/app/controller/admin.t
+++ b/t/app/controller/admin.t
@@ -845,6 +845,8 @@ for my $test (
};
}
+$mech->create_body_ok(2504, 'Westminster City Council');
+
for my $test (
{
desc => 'user is problem owner',
@@ -1082,6 +1084,8 @@ subtest 'show flagged entries' => sub {
$mech->content_contains( $user->email );
};
+$mech->create_body_ok(2509, 'Haringey Borough Council');
+
subtest 'user search' => sub {
$mech->get_ok('/admin/users');
$mech->get_ok('/admin/users?search=' . $user->name);
@@ -1115,7 +1119,6 @@ is $log_entries->count, 0, 'no admin log entries';
$user->flagged( 0 );
$user->update;
-$mech->create_body_ok(2509, 'Haringey Borough Council');
$mech->create_body_ok(2607, 'Southend-on-Sea Borough Council');
for my $test (
diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t
index 4c7b33f73..5ae3bdfb3 100644
--- a/t/app/controller/report_display.t
+++ b/t/app/controller/report_display.t
@@ -345,10 +345,13 @@ for my $test (
};
}
+$mech->create_body_ok(2504, 'Westminster City Council');
+$mech->create_body_ok(2505, 'Camden Borough Council');
+
for my $test (
{
desc => 'no state dropdown if user not from authority',
- from_body => 0,
+ from_body => undef,
no_state => 1,
report_body => '2504',
},
diff --git a/t/app/controller/report_interest_count.t b/t/app/controller/report_interest_count.t
index d0e0054c4..bfd1a8d1f 100644
--- a/t/app/controller/report_interest_count.t
+++ b/t/app/controller/report_interest_count.t
@@ -16,11 +16,6 @@ my $user =
->find_or_create( { email => 'test@example.com', name => 'Test User' } );
ok $user, "created test user";
-my $user2 =
- FixMyStreet::App->model('DB::User')
- ->find_or_create( { email => 'test2@example.com', name => 'Other User' } );
-ok $user2, "created test user";
-
my $dt = DateTime->new(
year => 2011,
month => 04,
@@ -59,10 +54,13 @@ ok $report, "created test report - $report_id";
SKIP: {
skip( "Need 'fixmybarangay' in ALLOWED_COBRANDS config", 29 )
unless FixMyStreet::Cobrand->exists('fixmybarangay');
+
+ $mech->create_body_ok(2504, 'Westminster City Council');
+
for my $test (
{
desc => 'if not from body then no supporter button',
- from_body => 0,
+ from_body => undef,
support_string => 'No supporters',
},
{
@@ -84,9 +82,9 @@ SKIP: {
$user->from_body( $test->{from_body} );
$user->update;
- $report->discard_changes;
- $report->bodies_str( $test->{report_council} );
- $report->update;
+ $report->update( {
+ bodies_str => $test->{report_council}
+ } );
$mech->get_ok("/report/$report_id");
$mech->content_contains( $test->{support_string} );
@@ -106,16 +104,14 @@ SKIP: {
subtest 'check non body user cannot increment support count' => sub {
ok $mech->host('fixmybarangay.com'), 'changed to fixmybarangay';
- $report->discard_changes;
- $report->interest_count(1);
- ok $report->update(), 'updated interest count';
- $report->discard_changes;
+ ok $report->update({ interest_count => 1 }), 'updated interest count';
is $report->interest_count, 1, 'correct interest count';
$mech->get_ok("/report/$report_id");
$mech->content_contains( '1 supporter' );
+ # This doesn't send cookie, so is logged out
$mech->post_ok("/report/support", { id => $report_id } );
is $mech->uri, "http://fixmybarangay.com/report/$report_id", 'add support redirects to report page';
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index fe1c27199..5accb9ce4 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -409,7 +409,7 @@ $report->update;
subtest 'check non authority user cannot change set state' => sub {
$mech->log_in_ok( $user->email );
- $user->from_body( 0 );
+ $user->from_body( undef );
$user->update;
$mech->get_ok("/report/$report_id");
@@ -434,6 +434,8 @@ subtest 'check non authority user cannot change set state' => sub {
is $report->state, 'confirmed', 'state unchanged';
};
+$mech->create_body_ok(2504, 'Westminster City Council');
+
for my $state ( qw/unconfirmed hidden partial/ ) {
subtest "check that update cannot set state to $state" => sub {
$mech->log_in_ok( $user->email );
@@ -547,13 +549,13 @@ for my $test (
state => 'fixed',
},
state => 'fixed - council',
- report_councils => '2504,2505',
+ report_bodies => '2504,2505',
},
) {
subtest $test->{desc} => sub {
$report->comments->delete;
- if ( $test->{ report_councils } ) {
- $report->bodies_str( $test->{ report_councils } );
+ if ( $test->{ report_bodies } ) {
+ $report->bodies_str( $test->{ report_bodies } );
$report->update;
}
@@ -629,7 +631,7 @@ subtest 'check meta correct for comments marked confirmed but not marked open' =
unlike $update_meta->[0], qr/reopened$/, 'update meta does not say reopened';
};
-$user->from_body(0);
+$user->from_body(undef);
$user->update;
$report->state('confirmed');
diff --git a/templates/web/default/admin/update_edit.html b/templates/web/default/admin/update_edit.html
index c0db82f28..752a6f9db 100644
--- a/templates/web/default/admin/update_edit.html
+++ b/templates/web/default/admin/update_edit.html
@@ -22,8 +22,8 @@
</select></li>
<li>[% loc('Name:') %] <input type='text' name='name' id='name' value='[% update.name | html %]'></li>
<li>[% loc('Email:') %] <input type='text' id='email' name='email' value='[% update.user.email | html %]'>
-[%- IF update.user.from_body && update.user.from_body == update.problem.bodies_str %]
-[% ' (' _ tprintf(loc('user is from same council as problem - %d'), update.user.from_body ) _')' %]
+[%- IF update.user.from_body && update.user.from_body.id == update.problem.bodies_str %]
+[% ' (' _ tprintf(loc('user is from same council as problem - %d'), update.user.from_body.id ) _')' %]
[% END -%]
[%- IF update.user.id == update.problem.user.id %]
[% ' (' _ loc('user is problem owner') _')' %]
diff --git a/templates/web/default/admin/user_edit.html b/templates/web/default/admin/user_edit.html
index 205e6561e..f1fc83c05 100644
--- a/templates/web/default/admin/user_edit.html
+++ b/templates/web/default/admin/user_edit.html
@@ -12,7 +12,7 @@
<li>[% loc('Council:') %] <select id='body' name='body'>
<option value=''>[% loc('No council') %]</option>
[% FOR body IN bodies %]
- <option value="[% body.id %]"[% ' selected' IF body.id == user.from_body %]>[% body.name %]</option>
+ <option value="[% body.id %]"[% ' selected' IF body.id == user.from_body.id %]>[% body.name %]</option>
[% END %]
</select>
<li>[% loc('Flagged:') %] <input type="checkbox" id="flagged" name="flagged"[% user.flagged ? ' checked' : '' %]></li>
diff --git a/templates/web/default/admin/users.html b/templates/web/default/admin/users.html
index 12f681741..b9839e9f7 100644
--- a/templates/web/default/admin/users.html
+++ b/templates/web/default/admin/users.html
@@ -19,7 +19,7 @@
<tr>
<td>[% PROCESS value_or_nbsp value=user.name %]</td>
<td><a href="[% c.uri_for( 'reports', search => user.email ) %]">[% PROCESS value_or_nbsp value=user.email %]</a></td>
- <td>[% PROCESS value_or_nbsp value=user.from_body %]</td>
+ <td>[% PROCESS value_or_nbsp value=user.from_body.id %]</td>
<td>[% user.flagged == 2 ? loc('(Email in abuse table)') : user.flagged ? loc('Yes') : '&nbsp;' %]</td>
<td>[% IF user.id %]<a href="[% c.uri_for( 'user_edit', user.id ) %]">[% loc('Edit') %]</a>[% END %]</td>
</tr>