aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2011-05-25 16:43:28 +0100
committerStruan Donald <struan@exo.org.uk>2011-05-25 16:43:28 +0100
commit6a679dbe9f0d7021f176ca23106a74bc2475539e (patch)
tree731af77d81f4855c045faadd3726fadbb1bb0c18
parent34296c409fe2ab9f02e5aeb14100570a8fb68dea (diff)
submission for questionnaire when problem owner marks it fixed
-rwxr-xr-xperllib/FixMyStreet/App/Controller/Questionnaire.pm55
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm2
-rw-r--r--t/app/controller/report_updates.t25
-rw-r--r--templates/web/default/questionnaire/creator_fixed.html5
-rw-r--r--templates/web/default/tokens/confirm_update.html8
5 files changed, 87 insertions, 8 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
index 96650a1c6..7169bc9e7 100755
--- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm
+++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm
@@ -57,6 +57,54 @@ sub load_questionnaire : Private {
sub submit : Path('submit') {
my ( $self, $c ) = @_;
+ if ( $c->req->params->{token} ) {
+ $c->forward('submit_standard');
+ } elsif ( $c->req->params->{problem} ) {
+ $c->forward('submit_creator_fixed');
+ } else {
+ return;
+ }
+
+ return 1;
+}
+
+sub submit_creator_fixed : Private {
+ my ( $self, $c ) = @_;
+
+ my @errors;
+
+ map { $c->stash->{$_} = $c->req->params->{$_} || '' } qw(reported problem);
+
+ push @errors, _('Please say whether you\'ve ever reported a problem to your council before') unless $c->stash->{reported};
+
+ $c->stash->{problem_id} = $c->stash->{problem};
+ $c->stash->{errors} = \@errors;
+ $c->detach( 'creator_fixed' ) if scalar @errors;
+
+ my $questionnaire = $c->model( 'DB::Questionnaire' )->find_or_new(
+ {
+ problem_id => $c->stash->{problem},
+ old_state => 'confirmed',
+ new_state => 'fixed',
+ }
+ );
+
+ unless ( $questionnaire->in_storage ) {
+ $questionnaire->ever_reported( $c->stash->{reported} eq 'Yes' ? 'y' : 'n' );
+ $questionnaire->whensent( \'ms_current_timestamp()' );
+ $questionnaire->whenanswered( \'ms_current_timestamp()' );
+ $questionnaire->insert;
+ }
+
+ $c->stash->{creator_fixed} = 1;
+ $c->stash->{template} = 'tokens/confirm_update.html';
+
+ return 1;
+}
+
+sub submit_standard : Private {
+ my ( $self, $c ) = @_;
+
$c->forward( '/tokens/load_questionnaire_id', [ $c->req->params->{token} ] );
$c->forward( 'load_questionnaire' );
@@ -218,6 +266,13 @@ sub display : Private {
$c->stash->{cobrand_form_elements} = $c->cobrand->form_elements('questionnaireForm');
}
+=head2 creator_fixed
+
+Display the reduced questionnaire that we display when the reporter of a
+problem submits an update marking it as fixed.
+
+=cut
+
sub creator_fixed : Private {
my ( $self, $c ) = @_;
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index 1bc15f1f3..8af3cd2a2 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -68,7 +68,7 @@ sub update_problem : Private {
$problem->lastupdate( \'ms_current_timestamp()' );
$problem->update;
- $c->stash->{problem} = $problem;
+ $c->stash->{problem_id} = $problem->id;
if ($display_questionnaire) {
$c->detach('/questionnaire/creator_fixed');
diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t
index f921b9ebb..1836423ba 100644
--- a/t/app/controller/report_updates.t
+++ b/t/app/controller/report_updates.t
@@ -498,10 +498,6 @@ for my $test (
is $mech->uri->path, "/report/" . $report_id, "redirected to report page";
- if ( $mech->uri->path eq '/report/update' ) {
- print $mech->content;
- }
-
is $mech->extract_problem_banner->{text}, $test->{endstate_banner}, 'submitted banner';
$mech->email_count_is(0);
@@ -639,6 +635,27 @@ foreach my $test (
is $update->state, 'confirmed', 'update confirmed';
is $update->anonymous, $test->{anonymous}, 'user anonymous';
+ SKIP: {
+ skip( 'not answering questionnaire', 5 ) if $questionnaire;
+
+ $mech->submit_form_ok( );
+
+ my @errors = @{ $mech->page_errors };
+ ok scalar @errors, 'displayed error messages';
+ is $errors[0], "Please say whether you've ever reported a problem to your council before", 'error message';
+
+ $mech->submit_form_ok( { with_fields => { reported => 'Yes' } } );
+
+ $mech->content_contains( 'Thank you &mdash; you can' );
+
+ $questionnaire = FixMyStreet::App->model( 'DB::Questionnaire' )->find(
+ { problem_id => $report_id }
+ );
+
+ ok $questionnaire, 'questionnaire exists';
+ ok $questionnaire->ever_reported, 'ever reported is yes';
+ };
+
if ($questionnaire) {
$questionnaire->delete;
ok !$questionnaire->in_storage, 'questionnaire deleted';
diff --git a/templates/web/default/questionnaire/creator_fixed.html b/templates/web/default/questionnaire/creator_fixed.html
index ebf392dd5..0d3181ec1 100644
--- a/templates/web/default/questionnaire/creator_fixed.html
+++ b/templates/web/default/questionnaire/creator_fixed.html
@@ -1,8 +1,9 @@
[% INCLUDE 'header.html', title = loc('Confirmation') %]
<form method="post" action="/questionnaire/submit" id="questionnaire">
-<input type="hidden" name="type" value="questionnaire">
-<input type="hidden" name="token" value="[% token | html %]">
+<input type="hidden" name="problem" value="[% problem_id | html %]">
+
+[% INCLUDE 'errors.html' %]
<p>
[% loc("Thanks, glad to hear it's been fixed! Could we just ask if you have ever reported a problem to a council before?") %]
diff --git a/templates/web/default/tokens/confirm_update.html b/templates/web/default/tokens/confirm_update.html
index 72816be51..cae702073 100644
--- a/templates/web/default/tokens/confirm_update.html
+++ b/templates/web/default/tokens/confirm_update.html
@@ -3,10 +3,16 @@
<h1>[% loc('Confirmation') %]</h1>
<p class="confirmed">
-[%
+[% IF creator_fixed %]
+[%
+ tprintf(loc('Thank you &mdash; you can <a href="%s">view your updated problem</a> on the site.'), c.uri_for( '/report', problem_id ) );
+%]
+[% ELSE %]
+[%
tprintf( loc('You have successfully confirmed your update and you can now <a href="%s">view it on the site</a>'), c.uri_for( '/report',
update.problem.id ) _ '#' _ update.id );
%]
+[% END %]
</p>
[% display_crossell_advert( update.user.email, update.name ) %]