diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 43 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 9 | ||||
-rw-r--r-- | t/app/controller/report_display.t | 2 | ||||
-rw-r--r-- | t/app/controller/report_updates.t | 12 | ||||
-rw-r--r-- | templates/web/default/report/display.html | 2 | ||||
-rwxr-xr-x | web/index.cgi | 120 |
6 files changed, 90 insertions, 98 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index ff471d7cd..0b235a06e 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -43,10 +43,6 @@ Display a report. sub display : Path('') : Args(1) { my ( $self, $c, $id ) = @_; -# my ($q, $errors, $field_errors) = @_; -# my @errors = @$errors; -# my %field_errors = %{$field_errors}; -# my $cobrand = Page::get_cobrand($q); # push @errors, _('There were problems with your update. Please see below.') if (scalar keys %field_errors); # my @vars = qw(id name rznvy update fixed add_alert upload_fileid submit_update); @@ -63,39 +59,14 @@ sub display : Path('') : Args(1) { } $c->forward('load_problem_or_display_error', [ $id ] ); - - # my $extra_data = Cobrand::extra_data($cobrand, $q); - # my $google_link = Cobrand::base_url_for_emails($cobrand, $extra_data) - # . '/report/' . $problem->{id}; - # # truncate the lat,lon for nicer rss urls - # my ( $short_lat, $short_lon ) = - # map { Utils::truncate_coordinate($_) } # - # ( $problem->{latitude}, $problem->{longitude} ); - - - -# my $fixed = ($input{fixed}) ? ' checked' : ''; - $c->forward( 'format_problem_for_display' ); -# my %vars = ( -# url_home => Cobrand::url($cobrand, '/', $q), -# field_errors => \%field_errors, -# add_alert_checked => ($input{add_alert} || !$input{submit_update}) ? ' checked' : '', -# form_action => Cobrand::url($cobrand, '/', $q), -# ); # # $vars{update_blurb} = $q->p($q->small(_('Please note that updates are not sent to the council. If you leave your name it will be public. Your information will only be used in accordance with our <a href="/faq#privacy">privacy policy</a>'))) # unless $q->{site} eq 'emptyhomes'; # No council blurb # # my %params = ( -# rss => [ _('Updates to this problem, FixMyStreet'), "/rss/$input_h{id}" ], -# robots => 'index, nofollow', # js => FixMyStreet::Map::header_js(), -# title => $problem->{title} # ); -# -# my $page = Page::template_include('problem', $q, Page::template_root($q), %vars); -# return ($page, %params); } @@ -196,14 +167,20 @@ sub format_problem_for_display : Private { ( $problem->latitude, $problem->longitude ); $c->stash->{report_name} = $c->req->param('name'); - $c->stash->{update} = $c->req->param('update'); - $c->stash->{email} = $c->req->param('rznvy'); + + if ( $c->req->param('submit_update' ) ) { + $c->stash->{update} = $c->req->param('update'); + $c->stash->{email} = $c->req->param('rznvy'); + $c->stash->{fixed} = $c->req->param('fixed') ? ' checked' : ''; + $c->stash->{add_alert} = $c->req->param('add_alert') ? ' checked' : ''; + } else { + $c->stash->{add_alert} = ' checked'; + } + $c->forward('generate_map_tags'); $c->forward('generate_problem_meta'); - # problem_updates => Page::display_problem_updates($input{id}, $q), - return 1; } diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 999bd08ff..1100cf17b 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -100,10 +100,12 @@ sub process_update : Private { $params{update} = Utils::cleanup_text( $params{update}, { allow_multiline => 1 } ); + my $name = Utils::trim_text( $params{ name } ); + my $update = $c->model('DB::Comment')->new( { text => $params{update}, - name => Utils::trim_text( $params{name} ), + name => $name, problem => $c->stash->{problem}, user => $c->stash->{update_user}, state => 'unconfirmed', @@ -111,6 +113,7 @@ sub process_update : Private { cobrand => $c->cobrand->moniker, cobrand_data => $c->cobrand->extra_update_data, lang => $c->stash->{lang_code}, + anonymous => ( $name ? 'f': 't' ), } ); @@ -147,6 +150,10 @@ sub check_for_errors : Private { $c->stash->{field_errors} = \%field_errors; + $c->stash->{errors} ||= []; + push @{ $c->stash->{errors} }, + _('There were problems with your update. Please see below.'); + return; } diff --git a/t/app/controller/report_display.t b/t/app/controller/report_display.t index 7be9f387e..aa7e507d9 100644 --- a/t/app/controller/report_display.t +++ b/t/app/controller/report_display.t @@ -113,7 +113,7 @@ subtest "test a good report" => sub { name => '', rznvy => '', update => '', - add_alert => undef, + add_alert => 1, # defaults to true fixed => undef ); is $update_form->value($_), $fields{$_}, "$_ value" for keys %fields; diff --git a/t/app/controller/report_updates.t b/t/app/controller/report_updates.t index f1717a64e..3c07ac054 100644 --- a/t/app/controller/report_updates.t +++ b/t/app/controller/report_updates.t @@ -67,6 +67,7 @@ my $comment = FixMyStreet::App->model('DB::Comment')->find_or_create( text => 'This is some update text', state => 'confirmed', confirmed => $dt->ymd . ' ' . $dt->hms, + anonymous => 'f', } ); @@ -152,6 +153,7 @@ subtest "several updates shown in correct order" => sub { text => 'First update', state => 'confirmed', confirmed => '2011-03-10 12:23:15', + anonymous => 'f', }, { problem_id => $report_id, @@ -161,6 +163,7 @@ subtest "several updates shown in correct order" => sub { text => 'Second update', state => 'confirmed', confirmed => '2011-03-10 12:23:16', + anonymous => 'f', }, { problem_id => $report_id, @@ -224,8 +227,10 @@ subtest "submit an update for a non registered user" => sub { $mech->submit_form_ok( { with_fields => { + submit_update => 1, rznvy => 'unregistered@example.com', - update => 'update from an unregistered user' + update => 'update from an unregistered user', + add_alert => 0, } }, 'submit update' @@ -266,8 +271,10 @@ for my $test ( { desc => 'submit update for register user', fields => { + submit_update => 1, rznvy => 'test@example.com', - update => 'update from a registered user' + update => 'update from a registered user', + add_alert => 0, }, changed => { update => 'Update from a registered user' @@ -277,6 +284,7 @@ for my $test ( { desc => 'submit update for register user and sign up', fields => { + submit_update => 1, rznvy => 'test@example.com', update => 'update from a registered user', add_alert => 1, diff --git a/templates/web/default/report/display.html b/templates/web/default/report/display.html index c1981c093..7e0501610 100644 --- a/templates/web/default/report/display.html +++ b/templates/web/default/report/display.html @@ -115,7 +115,7 @@ <div class="checkbox"> - <input type="checkbox" name="add_alert" id="form_add_alert" value="1"{{ $add_alert_checked }}> + <input type="checkbox" name="add_alert" id="form_add_alert" value="1"[% add_alert %]> <label for="form_add_alert">[% loc( 'Alert me to future updates' ) %]</label> </div> diff --git a/web/index.cgi b/web/index.cgi index d04467342..50251c01f 100755 --- a/web/index.cgi +++ b/web/index.cgi @@ -85,10 +85,10 @@ sub main { # $params{title} = _('Submitting your report'); # ( $out, %params ) = submit_problem($q); # } - elsif ( $q->param('submit_update') ) { - $params{title} = _('Submitting your update'); - ( $out, %params ) = submit_update($q); - } + #elsif ( $q->param('submit_update') ) { + # $params{title} = _('Submitting your update'); + # ( $out, %params ) = submit_update($q); + #} # elsif ( $q->param('submit_map') ) { # ( $out, %params ) = display_form( $q, [], {} ); # $params{title} = _('Reporting a problem'); @@ -222,62 +222,62 @@ Page::do_fastcgi(\&main); # return ($out, %params); # } -sub submit_update { - my $q = shift; - my @vars = qw(id name rznvy update fixed upload_fileid add_alert); - my %input = map { $_ => $q->param($_) || '' } @vars; - my @errors; - my %field_errors; - - my $fh = $q->upload('photo'); - if ($fh) { - my $err = Page::check_photo($q, $fh); - push @errors, $err if $err; - } - $field_errors{update} = _('Please enter a message') unless $input{update} =~ /\S/; - $input{name} = undef unless $input{name} =~ /\S/; - if ($input{rznvy} !~ /\S/) { - $field_errors{email} = _('Please enter your email'); - } elsif (!mySociety::EmailUtil::is_valid_email($input{rznvy})) { - $field_errors{email} = _('Please enter a valid email'); - } - - my $image; - if ($fh) { - try { - $image = Page::process_photo($fh); - } catch Error::Simple with { - my $e = shift; - push(@errors, sprintf(_("That image doesn't appear to have uploaded correctly (%s), please try again."), $e)); - }; - } - - if ($input{upload_fileid}) { - open FP, mySociety::Config::get('UPLOAD_CACHE') . $input{upload_fileid}; - $image = join('', <FP>); - close FP; - } - - return display_problem($q, \@errors, \%field_errors) if (@errors || scalar(keys(%field_errors))); - my $cobrand = Page::get_cobrand($q); - my $cobrand_data = Cobrand::extra_update_data($cobrand, $q); - my $id = dbh()->selectrow_array("select nextval('comment_id_seq');"); - Utils::workaround_pg_bytea("insert into comment - (id, problem_id, name, email, website, text, state, mark_fixed, photo, lang, cobrand, cobrand_data) - values (?, ?, ?, ?, '', ?, 'unconfirmed', ?, ?, ?, ?, ?)", 7, - $id, $input{id}, $input{name}, $input{rznvy}, $input{update}, - $input{fixed} ? 't' : 'f', $image, $mySociety::Locale::lang, $cobrand, $cobrand_data); - - my %h = (); - $h{update} = $input{update}; - $h{name} = $input{name} ? $input{name} : _("Anonymous"); - my $base = Page::base_url_with_lang($q, undef, 1); - $h{url} = $base . '/C/' . mySociety::AuthToken::store('update', { id => $id, add_alert => $input{add_alert} } ); - dbh()->commit(); - - my $out = Page::send_confirmation_email($q, $input{rznvy}, $input{name}, 'update', %h); - return $out; -} +#sub submit_update { +# my $q = shift; +# my @vars = qw(id name rznvy update fixed upload_fileid add_alert); +# my %input = map { $_ => $q->param($_) || '' } @vars; +# my @errors; +# my %field_errors; +# +# my $fh = $q->upload('photo'); +# if ($fh) { +# my $err = Page::check_photo($q, $fh); +# push @errors, $err if $err; +# } +# $field_errors{update} = _('Please enter a message') unless $input{update} =~ /\S/; +# $input{name} = undef unless $input{name} =~ /\S/; +# if ($input{rznvy} !~ /\S/) { +# $field_errors{email} = _('Please enter your email'); +# } elsif (!mySociety::EmailUtil::is_valid_email($input{rznvy})) { +# $field_errors{email} = _('Please enter a valid email'); +# } +# +# my $image; +# if ($fh) { +# try { +# $image = Page::process_photo($fh); +# } catch Error::Simple with { +# my $e = shift; +# push(@errors, sprintf(_("That image doesn't appear to have uploaded correctly (%s), please try again."), $e)); +# }; +# } +# +# if ($input{upload_fileid}) { +# open FP, mySociety::Config::get('UPLOAD_CACHE') . $input{upload_fileid}; +# $image = join('', <FP>); +# close FP; +# } +# +# return display_problem($q, \@errors, \%field_errors) if (@errors || scalar(keys(%field_errors))); +# my $cobrand = Page::get_cobrand($q); +# my $cobrand_data = Cobrand::extra_update_data($cobrand, $q); +# my $id = dbh()->selectrow_array("select nextval('comment_id_seq');"); +# Utils::workaround_pg_bytea("insert into comment +# (id, problem_id, name, email, website, text, state, mark_fixed, photo, lang, cobrand, cobrand_data) +# values (?, ?, ?, ?, '', ?, 'unconfirmed', ?, ?, ?, ?, ?)", 7, +# $id, $input{id}, $input{name}, $input{rznvy}, $input{update}, +# $input{fixed} ? 't' : 'f', $image, $mySociety::Locale::lang, $cobrand, $cobrand_data); +# +# my %h = (); +# $h{update} = $input{update}; +# $h{name} = $input{name} ? $input{name} : _("Anonymous"); +# my $base = Page::base_url_with_lang($q, undef, 1); +# $h{url} = $base . '/C/' . mySociety::AuthToken::store('update', { id => $id, add_alert => $input{add_alert} } ); +# dbh()->commit(); +# +# my $out = Page::send_confirmation_email($q, $input{rznvy}, $input{name}, 'update', %h); +# return $out; +#} # sub submit_problem { # my $q = shift; |