diff options
author | Struan Donald <struan@exo.org.uk> | 2012-05-01 19:17:38 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2012-05-01 19:17:38 +0100 |
commit | 4b08e5136db27ab0d69d070e77dcd92193f86752 (patch) | |
tree | 0db9960b36e6f480f112bc7c903ec1c0b04b6bfd | |
parent | ea47736c4e5b8dc2eb72aaefb2aa0ea7d1ffc406 (diff) |
store title in users table so we can persist it for bromley
-rw-r--r-- | db/schema.sql | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Tokens.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 14 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 51 | ||||
-rw-r--r-- | templates/web/default/report/new/extra_name.html | 13 |
8 files changed, 84 insertions, 17 deletions
diff --git a/db/schema.sql b/db/schema.sql index 169939315..cf70cef5c 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -135,7 +135,8 @@ create table users ( phone text, password text not null default '', from_council integer, -- id of council user is from or null/0 if not - flagged boolean not null default 'f' + flagged boolean not null default 'f', + title text ); -- Problems reported by users of site diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index b1ef2f0f3..42e218f61 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -490,7 +490,7 @@ sub search_reports : Path('search_reports') { 'me.id' => $search_n, 'user.email' => { ilike => $like_search }, 'me.name' => { ilike => $like_search }, - title => { ilike => $like_search }, + 'me.title' => { ilike => $like_search }, detail => { ilike => $like_search }, council => { like => $like_search }, cobrand_data => { like => $like_search }, diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 7b630d36f..ca2dfc6b5 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -643,9 +643,10 @@ sub process_user : Private { # The user is already signed in if ( $c->user_exists ) { my $user = $c->user->obj; - my %params = map { $_ => scalar $c->req->param($_) } ( 'name', 'phone' ); + my %params = map { $_ => scalar $c->req->param($_) } ( 'name', 'phone', 'fms_extra_title' ); $user->name( Utils::trim_text( $params{name} ) ) if $params{name}; $user->phone( Utils::trim_text( $params{phone} ) ); + $user->title( Utils::trim_text( $params{fms_extra_title} ) ); $report->user( $user ); $report->name( $user->name ); return 1; @@ -653,7 +654,7 @@ sub process_user : Private { # Extract all the params to a hash to make them easier to work with my %params = map { $_ => scalar $c->req->param($_) } - ( 'email', 'name', 'phone', 'password_register' ); + ( 'email', 'name', 'phone', 'password_register', 'fms_extra_title' ); # cleanup the email address my $email = $params{email} ? lc $params{email} : ''; @@ -681,6 +682,7 @@ sub process_user : Private { $report->user->phone( Utils::trim_text( $params{phone} ) ); $report->user->password( Utils::trim_text( $params{password_register} ) ) if $params{password_register}; + $report->user->title( Utils::trim_text( $params{fms_extra_title} ) ); $report->name( Utils::trim_text( $params{name} ) ); return 1; @@ -973,10 +975,12 @@ sub save_user_and_report : Private { name => $report->user->name, phone => $report->user->phone, password => $report->user->password, + title => $report->user->title, }; $report->user->name( undef ); $report->user->phone( undef ); $report->user->password( '', 1 ); + $report->user->title( undef ); $report->user->insert(); $c->log->info($report->user->id . ' created for this report'); } @@ -992,6 +996,7 @@ sub save_user_and_report : Private { name => $report->user->name, phone => $report->user->phone, password => $report->user->password, + title => $report->user->title, }; $report->user->discard_changes(); $c->log->info($report->user->id . ' exists, but is not logged in for this report'); diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 114c86c28..8be513b08 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -104,13 +104,16 @@ sub process_user : Private { my $user = $c->user->obj; my $name = scalar $c->req->param('name'); $user->name( Utils::trim_text( $name ) ) if $name; + my $title = scalar $c->req->param('fms_extra_title'); + $c->log->debug( 'user exists and title is ' . $title ); + $user->title( Utils::trim_text( $title ) ) if $title; $update->user( $user ); return 1; } # Extract all the params to a hash to make them easier to work with my %params = map { $_ => scalar $c->req->param($_) } - ( 'rznvy', 'name', 'password_register' ); + ( 'rznvy', 'name', 'password_register', 'fms_extra_title' ); # cleanup the email address my $email = $params{rznvy} ? lc $params{rznvy} : ''; @@ -136,6 +139,8 @@ sub process_user : Private { if $params{name}; $update->user->password( Utils::trim_text( $params{password_register} ) ) if $params{password_register}; + $update->user->title( Utils::trim_text( $params{fms_extra_title} ) ) + if $params{fms_extra_title}; return 1; } @@ -295,6 +300,7 @@ sub save_update : Private { } elsif ( $c->user && $c->user->id == $update->user->id ) { # Logged in and same user, so can confirm update straight away + $c->log->debug( 'user exists' ); $update->user->update; $update->confirm; } else { diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm index b974f94e6..1434838f2 100644 --- a/perllib/FixMyStreet/App/Controller/Tokens.pm +++ b/perllib/FixMyStreet/App/Controller/Tokens.pm @@ -71,6 +71,7 @@ sub confirm_problem : Path('/P') { $problem->user->name( $data->{name} ) if $data->{name}; $problem->user->phone( $data->{phone} ) if $data->{phone}; $problem->user->password( $data->{password}, 1 ) if $data->{password}; + $problem->user->title( $data->{title} ) if $data->{title}; $problem->user->update; } $c->authenticate( { email => $problem->user->email }, 'no_password' ); diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 7b0ffca73..6788447d7 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -1,3 +1,4 @@ +use utf8; package FixMyStreet::DB::Result::User; # Created by DBIx::Class::Schema::Loader @@ -7,7 +8,6 @@ use strict; use warnings; use base 'DBIx::Class::Core'; - __PACKAGE__->load_components("FilterColumn", "InflateColumn::DateTime", "EncodedColumn"); __PACKAGE__->table("users"); __PACKAGE__->add_columns( @@ -30,6 +30,8 @@ __PACKAGE__->add_columns( { data_type => "integer", is_nullable => 1 }, "flagged", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "title", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("users_email_key", ["email"]); @@ -46,6 +48,12 @@ __PACKAGE__->has_many( { cascade_copy => 0, cascade_delete => 0 }, ); __PACKAGE__->has_many( + "open311confs", + "FixMyStreet::DB::Result::Open311conf", + { "foreign.comment_user_id" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); +__PACKAGE__->has_many( "problems", "FixMyStreet::DB::Result::Problem", { "foreign.user_id" => "self.id" }, @@ -53,8 +61,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-06-27 10:25:21 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:9IHuqRTcHZCqJeBAaiQxzw +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-05-01 16:20:29 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:LKi8u5IYnHW1+Mez64nvGg __PACKAGE__->add_columns( "password" => { diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 89c8b973c..4a8cbbbfe 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -54,9 +54,17 @@ my $contact4 = FixMyStreet::App->model('DB::Contact')->find_or_create( { category => 'Trees', email => 'trees@example.com', } ); +my $contact5 = FixMyStreet::App->model('DB::Contact')->find_or_create( { + %contact_params, + area_id => 2651, # Edinburgh + category => 'Trees', + email => 'trees@example.com', +} ); ok $contact1, "created test contact 1"; ok $contact2, "created test contact 2"; ok $contact3, "created test contact 3"; +ok $contact4, "created test contact 4"; +ok $contact5, "created test contact 5"; # test that the various bit of form get filled in and errors correctly # generated. @@ -733,8 +741,18 @@ subtest "check that a lat/lon off coast leads to /around" => sub { for my $test ( { + desc => 'user title not set if not bromley problem', + host => 'http://www.fixmystreet.com', + postcode => 'EH99 1SP', + fms_extra_title => '', + extra => undef, + user_title => undef, + }, + { desc => 'title shown for bromley problem on main site', host => 'http://www.fixmystreet.com', + postcode => 'BR1 3UH', + fms_extra_title => 'MR', extra => [ { name => 'fms_extra_title', @@ -742,13 +760,16 @@ for my $test ( description => 'FMS_EXTRA_TITLE', }, ], + user_title => 'MR', }, { desc => 'title, first and last name shown for bromley problem on cobrand', host => 'http://bromley.fixmystreet.com', + postcode => 'BR1 3UH', first_name => 'Test', last_name => 'User', + fms_extra_title => 'MR', extra => [ { name => 'fms_extra_title', @@ -766,6 +787,7 @@ for my $test ( description => 'LAST_NAME', }, ], + user_title => 'MR', }, ) { @@ -773,9 +795,10 @@ for my $test ( $mech->host( $test->{host} ); $mech->log_out_ok; + $mech->clear_emails_ok; - $mech->get_ok('/around'); - $mech->submit_form_ok( { with_fields => { pc => 'BR1 3UH', } }, + $mech->get_ok('/'); + $mech->submit_form_ok( { with_fields => { pc => $test->{postcode}, } }, "submit location" ); $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, @@ -783,7 +806,11 @@ for my $test ( ); my $fields = $mech->visible_form_values('mapSkippedForm'); - ok exists( $fields->{fms_extra_title} ), 'user title field displayed'; + if ( $test->{fms_extra_title} ) { + ok exists( $fields->{fms_extra_title} ), 'user title field displayed'; + } else { + ok !exists( $fields->{fms_extra_title} ), 'user title field not displayed'; + } if ( $test->{first_name} ) { ok exists( $fields->{first_name} ), 'first name field displayed'; ok exists( $fields->{last_name} ), 'last name field displayed'; @@ -801,13 +828,15 @@ for my $test ( detail => 'Test report details.', photo => '', email => 'firstlast@example.com', - fms_extra_title => 'MR', may_show_name => '1', phone => '07903 123 456', category => 'Trees', password_register => '', }; + $submission_fields->{fms_extra_title} = $test->{fms_extra_title} + if $test->{fms_extra_title}; + if ( $test->{first_name} ) { $submission_fields->{first_name} = $test->{first_name}; $submission_fields->{last_name} = $test->{last_name}; @@ -819,6 +848,16 @@ for my $test ( $mech->submit_form_ok( { with_fields => $submission_fields }, "submit good details" ); + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/confirm the problem/i, "confirm the problem"; + + my ($url) = $email->body =~ m{(http://\S+)}; + ok $url, "extracted confirm url '$url'"; + + # confirm token in order to update the user details + $mech->get_ok($url); + my $user = FixMyStreet::App->model('DB::User') ->find( { email => 'firstlast@example.com' } ); @@ -826,9 +865,11 @@ for my $test ( my $report = $user->problems->first; ok $report, "Found the report"; my $extras = $report->extra; + is $user->title, $test->{'user_title'}, 'user title correct'; is_deeply $extras, $test->{extra}, 'extra contains correct values'; $user->problems->delete; + $user->alerts->delete; $user->delete; }; } @@ -836,5 +877,7 @@ for my $test ( $contact1->delete; $contact2->delete; $contact3->delete; +$contact4->delete; +$contact5->delete; done_testing(); diff --git a/templates/web/default/report/new/extra_name.html b/templates/web/default/report/new/extra_name.html index 503b6acc3..e8c2cadaf 100644 --- a/templates/web/default/report/new/extra_name.html +++ b/templates/web/default/report/new/extra_name.html @@ -3,13 +3,16 @@ [% IF field_errors.fms_extra_title %] <p class='form-error'>[% field_errors.fms_extra_title %]</p> [% END %] +[% title = '' %] +[% IF fms_extra_title %][% title = fms_extra_title | upper %] +[% ELSIF c.user && c.user.title %][% title = c.user.title | upper %][% END %] <select class="form-focus-trigger" id="form_fms_extra_title" name="fms_extra_title"> <option></option> - <option value="MR"[% ' selected' IF fms_extra_title == 'Mr' %]>Mr</option> - <option value="MISS"[% ' selected' IF fms_extra_title == 'Miss' %]>Miss</option> - <option value="MRS"[% ' selected' IF fms_extra_title == 'Mrs' %]>Mrs</option> - <option value="MS"[% ' selected' IF fms_extra_title == 'Ms' %]>Ms</option> - <option value="DR"[% ' selected' IF fms_extra_title == 'Dr' %]>Dr</option> + <option value="MR"[% ' selected' IF title == 'MR' %]>Mr</option> + <option value="MISS"[% ' selected' IF title == 'MISS' %]>Miss</option> + <option value="MRS"[% ' selected' IF title == 'MRS' %]>Mrs</option> + <option value="MS"[% ' selected' IF title == 'MS' %]>Ms</option> + <option value="DR"[% ' selected' IF title == 'DR' %]>Dr</option> </select> [% END %] |