aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm74
-rw-r--r--t/app/controller/report_new.t25
-rw-r--r--templates/web/default/report/new/fill_in_details.html2
3 files changed, 69 insertions, 32 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 2ddaf31f7..67fe12697 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -79,7 +79,7 @@ sub report_new : Path : Args(0) {
# set up the page
$c->forward('setup_page');
-
+
# create the report - loading a partial if available
$c->forward('initialize_report');
@@ -278,8 +278,8 @@ Setup the page - notably add the map js to the stash
=cut
sub setup_page : Private {
- my ( $self, $c) = @_;
-
+ my ( $self, $c ) = @_;
+
$c->stash->{extra_js_verbatim} = FixMyStreet::Map::header_js();
return 1;
@@ -304,45 +304,59 @@ sub initialize_report : Private {
# create a new one. Stick it on the stash.
my $report = undef;
- for my $partial ( scalar $c->req->param('partial') ) {
+ if ( my $partial = scalar $c->req->param('partial') ) {
- # did we find a token
- last unless $partial;
+ for (1) { # use as pseudo flow control
- # is it in the database
- my $token =
- $c->model("DB::Token")
- ->find( { scope => 'partial', token => $partial } ) #
- || last;
+ # did we find a token
+ last unless $partial;
- # can we get an id from it?
- my $id = $token->data #
- || last;
+ # is it in the database
+ my $token =
+ $c->model("DB::Token")
+ ->find( { scope => 'partial', token => $partial } ) #
+ || last;
- # load the related problem
- $report = $c->model("DB::Problem") #
- ->search( { id => $id, state => 'partial' } ) #
- ->first;
+ # can we get an id from it?
+ my $id = $token->data #
+ || last;
- if ($report) {
+ # load the related problem
+ $report = $c->model("DB::Problem") #
+ ->search( { id => $id, state => 'partial' } ) #
+ ->first;
- # log the problem creation user in to the site
- $c->authenticate( { email => $report->user->email },
- 'no_password' );
+ if ($report) {
- # save the token to delete at the end
- $c->stash->{partial_token} = $token if $report;
+ # log the problem creation user in to the site
+ $c->authenticate( { email => $report->user->email },
+ 'no_password' );
+
+ # save the token to delete at the end
+ $c->stash->{partial_token} = $token if $report;
+
+ }
+ else {
+ # no point keeping it if it is done.
+ $token->delete;
+ }
}
- else {
+ }
+ else {
- # no point keeping it if it is done.
- $token->delete;
+ # If we didn't find a partial then create a new one
+ $report = $c->model('DB::Problem')->new( {} );
+
+ # If we have a user logged in let's prefill some values for them.
+ if ( $c->user ) {
+ my $user = $c->user->obj;
+ $report->user($user);
+ $report->name( $user->name );
}
+
}
- # If we didn't find a partial then create a new one
- $report ||= $c->model('DB::Problem')->new( {} );
$c->stash->{report} = $report;
return 1;
@@ -810,7 +824,7 @@ sub process_report : Private {
# Short circuit unless the form has been submitted
return 1 unless $params{submit_problem};
-
+
# set some simple bool values (note they get inverted)
$report->anonymous( $params{may_show_name} ? 0 : 1 );
$report->used_map( $params{skipped} ? 0 : 1 );
diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t
index 61f009619..dca86db77 100644
--- a/t/app/controller/report_new.t
+++ b/t/app/controller/report_new.t
@@ -380,11 +380,35 @@ subtest "test report creation for a user who is logged in" => sub {
$mech->clear_emails_ok;
my $user = $mech->log_in_ok($test_email);
+ # setup the user.
+ ok $user->update(
+ {
+ name => 'Test User',
+ phone => '01234 567 890',
+ }
+ ),
+ "set users details";
+
# submit initial pc form
$mech->get_ok('/report/new');
$mech->submit_form_ok( { with_fields => { pc => 'SW1A 1AA', } },
"submit location" );
+ # check that the fields are correctly prefilled
+ is_deeply(
+ $mech->visible_form_values,
+ {
+ title => '',
+ detail => '',
+ may_show_name => '1',
+ email => $test_email,
+ name => 'Test User',
+ phone => '01234 567 890',
+ photo => '',
+ },
+ "user's details prefilled"
+ );
+
TODO: {
local $TODO =
"'/report/<<id>>' not handled by catalyst yet - form creation redirects to there on success if logged in";
@@ -397,7 +421,6 @@ subtest "test report creation for a user who is logged in" => sub {
photo => '',
name => 'Joe Bloggs',
may_show_name => '1',
- email => $test_email,
phone => '07903 123 456',
}
},
diff --git a/templates/web/default/report/new/fill_in_details.html b/templates/web/default/report/new/fill_in_details.html
index 6b1d363a6..c7ed908a8 100644
--- a/templates/web/default/report/new/fill_in_details.html
+++ b/templates/web/default/report/new/fill_in_details.html
@@ -107,7 +107,7 @@
<div class='form-field'>
<label for="form_name">[% loc('Name:') %]</label>
- <input type="text" value="[% report.name || report_user.name | html %]" name="name" id="form_name" size="25">
+ <input type="text" value="[% report.name | html %]" name="name" id="form_name" size="25">
</div>