From c40da27da59b74c32db0a50a2a03473ec4cdba2c Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 18 May 2011 15:48:00 +0100 Subject: initial problem update reporting. only does basic validation so far --- .../FixMyStreet/App/Controller/Report/Update.pm | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 perllib/FixMyStreet/App/Controller/Report/Update.pm (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm new file mode 100644 index 000000000..58eaaf0f2 --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -0,0 +1,110 @@ +package FixMyStreet::App::Controller::Report::Update; + +use Moose; +use namespace::autoclean; +BEGIN { extends 'Catalyst::Controller'; } + +=head1 NAME + +FixMyStreet::App::Controller::Report::Update + +=head1 DESCRIPTION + +Creates an update to a report + +=cut + +sub report_update : Path : Args(0) { + my ( $self, $c ) = @_; + +# 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; +# } +# +# 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('', ); +# 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; + + $c->forward( 'setup_page' ); + $c->forward( 'validate' ) || $c->forward( '/report/display', [ $c->req->param( 'id' ) ] ); + + # just go back to the report page for now + $c->go( '/report/display', [ $c->req->param( 'id' ) ] ); + return 1; +} + +sub setup_page : Private { + my ( $self, $c ) = @_; + + $c->stash->{problem} = $c->model( 'DB::Problem' )->find( + { id => $c->req->param('id') } + ); +} + +sub validate : Private { + my ( $self, $c ) = @_; + + my %field_errors = (); + + if ( $c->req->param( 'update' ) !~ /\S/ ) { + $field_errors{update} = _('Please enter a message'); + } + + if ($c->req->param('rznvy') !~ /\S/) { + $field_errors{email} = _('Please enter your email'); + } elsif (!mySociety::EmailUtil::is_valid_email($c->req->param('rznvy'))) { + $field_errors{email} = _('Please enter a valid email'); + } + + if ( scalar keys %field_errors ) { + $c->stash->{field_errors} = \%field_errors; + return; + } + + return 1; +} + + +__PACKAGE__->meta->make_immutable; + +1; -- cgit v1.2.3 From 611f0fc992503b9332ea1e5bb0f5df55d031d8ac Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 18 May 2011 17:31:31 +0100 Subject: redo validation and storage to be more in line with code in report/new --- .../FixMyStreet/App/Controller/Report/Update.pm | 130 +++++++++++++++++---- 1 file changed, 110 insertions(+), 20 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 58eaaf0f2..ece72f3ee 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -65,45 +65,135 @@ sub report_update : Path : Args(0) { # my $out = Page::send_confirmation_email($q, $input{rznvy}, $input{name}, 'update', %h); # return $out; - $c->forward( 'setup_page' ); - $c->forward( 'validate' ) || $c->forward( '/report/display', [ $c->req->param( 'id' ) ] ); + $c->forward('setup_page') + && $c->forward('process_user') + && $c->forward('process_update') + && $c->forward('check_for_errors') + or $c->go( '/report/display', [ $c->req->param('id') ] ); + + $c->forward('save_update'); # just go back to the report page for now - $c->go( '/report/display', [ $c->req->param( 'id' ) ] ); + $c->go( '/report/display', [ $c->req->param('id') ] ); return 1; } sub setup_page : Private { my ( $self, $c ) = @_; - $c->stash->{problem} = $c->model( 'DB::Problem' )->find( - { id => $c->req->param('id') } - ); + my $problem = + $c->model('DB::Problem')->find( { id => $c->req->param('id') } ); + + return unless $problem; + + $c->stash->{problem} = $problem; + + return 1; } -sub validate : Private { +=head2 process_user + +Load user from the database or prepare a new one. + +=cut + +sub process_user : Private { my ( $self, $c ) = @_; - my %field_errors = (); + # FIXME - If user already logged in use them regardless - if ( $c->req->param( 'update' ) !~ /\S/ ) { - $field_errors{update} = _('Please enter a message'); - } + # Extract all the params to a hash to make them easier to work with + my %params = # + map { $_ => scalar $c->req->param($_) } # + ( 'rznvy', 'name' ); - if ($c->req->param('rznvy') !~ /\S/) { - $field_errors{email} = _('Please enter your email'); - } elsif (!mySociety::EmailUtil::is_valid_email($c->req->param('rznvy'))) { - $field_errors{email} = _('Please enter a valid email'); - } + # cleanup the email address + my $email = $params{rznvy} ? lc $params{rznvy} : ''; + $email =~ s{\s+}{}g; - if ( scalar keys %field_errors ) { - $c->stash->{field_errors} = \%field_errors; - return; - } + my $update_user = $c->model('DB::User')->find_or_new( { email => $email } ); + + # set the user's name if they don't have one + $update_user->name( _trim_text( $params{name} ) ) + unless $update_user->name; + + $c->stash->{update_user} = $update_user; + + return 1; +} + +sub process_update : Private { + my ( $self, $c ) = @_; + + my %params = # + map { $_ => scalar $c->req->param($_) } ( 'update', 'name' ); + + my $update = $c->model('DB::Comment')->new( + { + text => $params{update}, + name => _trim_text( $params{name} ), + problem => $c->stash->{problem}, + user => $c->stash->{update_user} + } + ); + + $c->stash->{update} = $update; return 1; } +sub _trim_text { + my $input = shift; + for ($input) { + last unless $_; + s{\s+}{ }g; # all whitespace to single space + s{^ }{}; # trim leading + s{ $}{}; # trim trailing + } + return $input; +} + +=head2 check_for_errors + +Examine the user and the report for errors. If found put them on stash and +return false. + +=cut + +sub check_for_errors : Private { + my ( $self, $c ) = @_; + + # let the model check for errors + my %field_errors = ( + %{ $c->stash->{update_user}->check_for_errors }, + %{ $c->stash->{update}->check_for_errors }, + ); + + $c->log->debug( join ', ', keys %field_errors ); + + # all good if no errors + return 1 unless scalar keys %field_errors; + + $c->stash->{field_errors} = \%field_errors; + + return; +} + +sub save_update : Private { + my ( $self, $c ) = @_; + + if ( $c->stash->{update_user}->in_storage ) { + $c->stash->{update_user}->update_user; + } else { + $c->stash->{update_user}->insert; + } + + if ( $c->stash->{update}->in_storage ) { + $c->stash->{update}->update; + } else { + $c->stash->{update}->insert; + } +} __PACKAGE__->meta->make_immutable; -- cgit v1.2.3 From 7172772a3a75d18917bd3747786839323d3d0fbf Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 18 May 2011 17:35:04 +0100 Subject: documentation --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index ece72f3ee..629408401 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -122,6 +122,16 @@ sub process_user : Private { return 1; } +=head2 process_update + +Take the submitted params and create a new update item. Does not save +anything to the database. + +NB: relies on their being a probem and update_user in the stash. May +want to move adding these elsewhere + +=cut + sub process_update : Private { my ( $self, $c ) = @_; @@ -179,6 +189,12 @@ sub check_for_errors : Private { return; } +=head2 save_update + +Save the update and the user as appropriate. + +=cut + sub save_update : Private { my ( $self, $c ) = @_; -- cgit v1.2.3 From 2e361587044731fc6101f0978aaa0dad3fdc2b93 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 19 May 2011 13:07:21 +0100 Subject: save and confirm update or email for confirmation as appropriate --- .../FixMyStreet/App/Controller/Report/Update.pm | 62 +++++++++++++++++----- 1 file changed, 50 insertions(+), 12 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 629408401..bac3c5b17 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -72,9 +72,8 @@ sub report_update : Path : Args(0) { or $c->go( '/report/display', [ $c->req->param('id') ] ); $c->forward('save_update'); + $c->forward('redirect_or_confirm_creation'); - # just go back to the report page for now - $c->go( '/report/display', [ $c->req->param('id') ] ); return 1; } @@ -136,14 +135,18 @@ sub process_update : Private { my ( $self, $c ) = @_; my %params = # - map { $_ => scalar $c->req->param($_) } ( 'update', 'name' ); + map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed' ); + use Data::Dumper; + $c->log->debug( 'params: ' . Dumper( %params ) ); my $update = $c->model('DB::Comment')->new( { text => $params{update}, name => _trim_text( $params{name} ), problem => $c->stash->{problem}, - user => $c->stash->{update_user} + user => $c->stash->{update_user}, + state => 'unconfirmed', + mark_fixed => $params{fixed} ? 't' : 'f', } ); @@ -179,7 +182,8 @@ sub check_for_errors : Private { %{ $c->stash->{update}->check_for_errors }, ); - $c->log->debug( join ', ', keys %field_errors ); + # we don't care if there are errors with this... + delete $field_errors{name}; # all good if no errors return 1 unless scalar keys %field_errors; @@ -198,19 +202,53 @@ Save the update and the user as appropriate. sub save_update : Private { my ( $self, $c ) = @_; - if ( $c->stash->{update_user}->in_storage ) { - $c->stash->{update_user}->update_user; - } else { - $c->stash->{update_user}->insert; + my $user = $c->stash->{update_user}; + my $update = $c->stash->{update}; + + if ( !$user->in_storage ) { + $user->insert; + } elsif ( $c->user && $c->user->id == $user->id ) { + $user->update; + $update->confirm; } - if ( $c->stash->{update}->in_storage ) { - $c->stash->{update}->update; + if ( $update->in_storage ) { + $update->update; } else { - $c->stash->{update}->insert; + $update->insert; } } +=head2 redirect_or_confirm_creation + +Now that the update has been created either redirect the user to problem page if it +has been confirmed or email them a token if it has not been. + +=cut + +sub redirect_or_confirm_creation : Private { + my ( $self, $c ) = @_; + my $update = $c->stash->{update}; + + # If confirmed send the user straight there. + if ( $update->confirmed ) { + my $report_uri = $c->uri_for( '/report', $update->problem_id ); + $c->res->redirect($report_uri); + $c->detach; + } + + # otherwise create a confirm token and email it to them. + my $token = + $c->model("DB::Token") + ->create( { scope => 'comment', data => $update->id } ); + $c->stash->{token_url} = $c->uri_for_email( '/C', $token->token ); + $c->send_email( 'update-confirm.txt', { to => $update->user->email } ); + + # tell user that they've been sent an email + $c->stash->{template} = 'email_sent.html'; + $c->stash->{email_type} = 'update'; +} + __PACKAGE__->meta->make_immutable; 1; -- cgit v1.2.3 From b362778c0204eeca8919ad2a2d1f20cd308a20e5 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 19 May 2011 15:13:04 +0100 Subject: upload and display update photos --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index bac3c5b17..691a4ecc9 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -4,6 +4,8 @@ use Moose; use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } +use Path::Class; + =head1 NAME FixMyStreet::App::Controller::Report::Update @@ -68,6 +70,7 @@ sub report_update : Path : Args(0) { $c->forward('setup_page') && $c->forward('process_user') && $c->forward('process_update') + && $c->forward('/report/new/process_photo') && $c->forward('check_for_errors') or $c->go( '/report/display', [ $c->req->param('id') ] ); @@ -212,6 +215,14 @@ sub save_update : Private { $update->confirm; } + # If there was a photo add that too + if ( my $fileid = $c->stash->{upload_fileid} ) { + my $file = file( $c->config->{UPLOAD_CACHE}, "$fileid.jpg" ); + my $blob = $file->slurp; + $file->remove; + $update->photo($blob); + } + if ( $update->in_storage ) { $update->update; } else { -- cgit v1.2.3 From 1463288a3282ec5d0f195e2ed44253b78f5b915b Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 19 May 2011 17:07:24 +0100 Subject: create token for comment confirmation correctly --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 691a4ecc9..d9136698d 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -249,15 +249,23 @@ sub redirect_or_confirm_creation : Private { } # otherwise create a confirm token and email it to them. - my $token = - $c->model("DB::Token") - ->create( { scope => 'comment', data => $update->id } ); + my $token = $c->model("DB::Token")->create( + { + scope => 'comment', + data => { + id => $update->id, + add_alert => ( $c->req->param('add_alert') ? 1 : 0 ), + } + } + ); $c->stash->{token_url} = $c->uri_for_email( '/C', $token->token ); $c->send_email( 'update-confirm.txt', { to => $update->user->email } ); # tell user that they've been sent an email $c->stash->{template} = 'email_sent.html'; $c->stash->{email_type} = 'update'; + + return 1; } __PACKAGE__->meta->make_immutable; -- cgit v1.2.3 From 2c3160b0fb07d9412925a3d57f4017c998de835e Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 19 May 2011 17:11:37 +0100 Subject: sign up logged in users for alerts as appropriate --- .../FixMyStreet/App/Controller/Report/Update.pm | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index d9136698d..e1e90bb93 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -228,6 +228,8 @@ sub save_update : Private { } else { $update->insert; } + + return 1; } =head2 redirect_or_confirm_creation @@ -243,6 +245,7 @@ sub redirect_or_confirm_creation : Private { # If confirmed send the user straight there. if ( $update->confirmed ) { + $c->forward( 'signup_for_alerts' ); my $report_uri = $c->uri_for( '/report', $update->problem_id ); $c->res->redirect($report_uri); $c->detach; @@ -268,6 +271,32 @@ sub redirect_or_confirm_creation : Private { return 1; } +=head2 signup_for_alerts + +If the user has selected to be signed up for alerts then create a +new_updates alert. + +NB: this does not check if they are a registered user so that should +happen before calling this. + +=cut + +sub signup_for_alerts : Private { + my ( $self, $c ) = @_; + + if ( $c->req->param( 'add_alert' ) ) { + my $alert = $c->model( 'DB::Alert' )->find_or_create( + user => $c->stash->{update_user}, + alert_type => 'new_updates', + parameter => $c->stash->{problem}->id + ); + + $alert->update; + } + + return 1; +} + __PACKAGE__->meta->make_immutable; 1; -- cgit v1.2.3 From 1924271f0a93edb6cfc16d3ee3087939e89a65a9 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 19 May 2011 18:00:39 +0100 Subject: display error if bad photo upload --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index e1e90bb93..61ca28184 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -189,7 +189,10 @@ sub check_for_errors : Private { delete $field_errors{name}; # all good if no errors - return 1 unless scalar keys %field_errors; + return 1 + unless ( scalar keys %field_errors + || scalar @{ $c->stash->{errors} } + || $c->stash->{photo_error} ); $c->stash->{field_errors} = \%field_errors; -- cgit v1.2.3 From f0265de6d0d2ed9326c6871c7bd38822c6598289 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 19 May 2011 18:25:27 +0100 Subject: save cobrand etc for update --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 61ca28184..4611e9129 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -140,16 +140,17 @@ sub process_update : Private { my %params = # map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed' ); - use Data::Dumper; - $c->log->debug( 'params: ' . Dumper( %params ) ); my $update = $c->model('DB::Comment')->new( { - text => $params{update}, - name => _trim_text( $params{name} ), - problem => $c->stash->{problem}, - user => $c->stash->{update_user}, - state => 'unconfirmed', - mark_fixed => $params{fixed} ? 't' : 'f', + text => $params{update}, + name => _trim_text( $params{name} ), + problem => $c->stash->{problem}, + user => $c->stash->{update_user}, + state => 'unconfirmed', + mark_fixed => $params{fixed} ? 't' : 'f', + cobrand => $c->cobrand->moniker, + cobrand_data => $c->cobrand->extra_update_data, + lang => $c->stash->{lang}, } ); -- cgit v1.2.3 From f0e1ae8ad567b5360577f0e18237fa00056e4073 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 19 May 2011 18:36:24 +0100 Subject: fix stupid mistakes --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 4611e9129..105bf9993 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -150,7 +150,7 @@ sub process_update : Private { mark_fixed => $params{fixed} ? 't' : 'f', cobrand => $c->cobrand->moniker, cobrand_data => $c->cobrand->extra_update_data, - lang => $c->stash->{lang}, + lang => $c->stash->{lang_code}, } ); @@ -192,7 +192,7 @@ sub check_for_errors : Private { # all good if no errors return 1 unless ( scalar keys %field_errors - || scalar @{ $c->stash->{errors} } + || ( $c->stash->{errors} && scalar @{ $c->stash->{errors} } ) || $c->stash->{photo_error} ); $c->stash->{field_errors} = \%field_errors; -- cgit v1.2.3 From c81d9ee2c13b5430be1beb4210d10e1cbb31c194 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 20 May 2011 10:42:47 +0100 Subject: move trim_text and cleanup_text to Utils --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 105bf9993..31478df29 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -5,6 +5,7 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } use Path::Class; +use Utils; =head1 NAME @@ -116,7 +117,7 @@ sub process_user : Private { my $update_user = $c->model('DB::User')->find_or_new( { email => $email } ); # set the user's name if they don't have one - $update_user->name( _trim_text( $params{name} ) ) + $update_user->name( Utils::trim_text( $params{name} ) ) unless $update_user->name; $c->stash->{update_user} = $update_user; @@ -140,10 +141,13 @@ sub process_update : Private { my %params = # map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed' ); + $params{update} = + Utils::cleanup_text( $params{update}, { allow_multiline => 1 } ); + my $update = $c->model('DB::Comment')->new( { text => $params{update}, - name => _trim_text( $params{name} ), + name => Utils::trim_text( $params{name} ), problem => $c->stash->{problem}, user => $c->stash->{update_user}, state => 'unconfirmed', @@ -159,16 +163,6 @@ sub process_update : Private { return 1; } -sub _trim_text { - my $input = shift; - for ($input) { - last unless $_; - s{\s+}{ }g; # all whitespace to single space - s{^ }{}; # trim leading - s{ $}{}; # trim trailing - } - return $input; -} =head2 check_for_errors -- cgit v1.2.3 From 060d44181d69b45596f205aef158c7696fc13322 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 20 May 2011 10:45:28 +0100 Subject: bit of documentation and tidy up --- .../FixMyStreet/App/Controller/Report/Update.pm | 74 +++++----------------- 1 file changed, 16 insertions(+), 58 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 31478df29..999bd08ff 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -20,54 +20,6 @@ Creates an update to a report sub report_update : Path : Args(0) { my ( $self, $c ) = @_; -# 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; -# } -# -# 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('', ); -# 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; - $c->forward('setup_page') && $c->forward('process_user') && $c->forward('process_update') @@ -75,12 +27,16 @@ sub report_update : Path : Args(0) { && $c->forward('check_for_errors') or $c->go( '/report/display', [ $c->req->param('id') ] ); - $c->forward('save_update'); - $c->forward('redirect_or_confirm_creation'); - - return 1; + return $c->forward('save_update') + && $c->forward('redirect_or_confirm_creation'); } +=head2 setup_page + +Setup things we need for later. + +=cut + sub setup_page : Private { my ( $self, $c ) = @_; @@ -130,7 +86,7 @@ sub process_user : Private { Take the submitted params and create a new update item. Does not save anything to the database. -NB: relies on their being a probem and update_user in the stash. May +NB: relies on their being a problem and update_user in the stash. May want to move adding these elsewhere =cut @@ -138,7 +94,7 @@ want to move adding these elsewhere sub process_update : Private { my ( $self, $c ) = @_; - my %params = # + my %params = map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed' ); $params{update} = @@ -203,14 +159,15 @@ Save the update and the user as appropriate. sub save_update : Private { my ( $self, $c ) = @_; - my $user = $c->stash->{update_user}; + my $user = $c->stash->{update_user}; my $update = $c->stash->{update}; if ( !$user->in_storage ) { $user->insert; - } elsif ( $c->user && $c->user->id == $user->id ) { + } + elsif ( $c->user && $c->user->id == $user->id ) { $user->update; - $update->confirm; + $update->confirm; } # If there was a photo add that too @@ -223,7 +180,8 @@ sub save_update : Private { if ( $update->in_storage ) { $update->update; - } else { + } + else { $update->insert; } -- cgit v1.2.3 From 0a2075c106083b6b3b7c8b37b04df9b155aed1fb Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 20 May 2011 12:00:24 +0100 Subject: display problems with update error message --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 999bd08ff..38a7a3909 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -147,6 +147,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; } -- cgit v1.2.3 From b994038f7d169ac6a3bf270c8a371fa7d285e4b2 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 20 May 2011 12:29:33 +0100 Subject: anonymous cannot be null --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 38a7a3909..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' ), } ); -- cgit v1.2.3 From fb2eae201d01d285ac2b21fd32c2ff35a6f7aae5 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 20 May 2011 17:17:12 +0100 Subject: update confirmation from tokens --- .../FixMyStreet/App/Controller/Report/Update.pm | 59 +++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 1100cf17b..91f05c32f 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -31,6 +31,59 @@ sub report_update : Path : Args(0) { && $c->forward('redirect_or_confirm_creation'); } +sub confirm : Private { + my ( $self, $c ) = @_; + + $c->stash->{update}->confirm; + $c->stash->{update}->update; + + $c->forward('update_problem'); + $c->forward('signup_for_alerts'); + + return 1; +} + +sub update_problem : Private { + my ( $self, $c ) = @_; + + my $update = $c->stash->{update}; + my $problem = $c->stash->{problem} || $update->problem; + + if ( $update->mark_fixed ) { + $problem->state( 'fixed' ); + + if ( $update->user->id == $problem->user->id ) { + $problem->send_questionnaire( 'f' ); + } else { + $c->forward( 'ask_questionnaire' ); + } + } + + $problem->lastupdate( \'ms_current_timestamp()' ); + $problem->update; + + $c->stash->{problem} = $problem; + + + return 1; +} + +sub ask_questionnaire : Private { + my ( $self, $c ) = @_; + + # FIXME send out questionnaire token here + + return 1; +} + +sub display_confirmation : Private { + my ( $self, $c ) = @_; + + $c->stash->{template} = 'tokens/confirm_update.html'; + + return 1; +} + =head2 setup_page Setup things we need for later. @@ -118,6 +171,7 @@ sub process_update : Private { ); $c->stash->{update} = $update; + $c->stash->{add_alert} = $c->req->param('add_alert'); return 1; } @@ -209,6 +263,7 @@ sub redirect_or_confirm_creation : Private { # If confirmed send the user straight there. if ( $update->confirmed ) { $c->forward( 'signup_for_alerts' ); + $c->forward( 'update_problem' ); my $report_uri = $c->uri_for( '/report', $update->problem_id ); $c->res->redirect($report_uri); $c->detach; @@ -247,9 +302,9 @@ happen before calling this. sub signup_for_alerts : Private { my ( $self, $c ) = @_; - if ( $c->req->param( 'add_alert' ) ) { + if ( $c->stash->{add_alert} ) { my $alert = $c->model( 'DB::Alert' )->find_or_create( - user => $c->stash->{update_user}, + user => $c->stash->{update}->user, alert_type => 'new_updates', parameter => $c->stash->{problem}->id ); -- cgit v1.2.3 From e58b6ceae179dcf576ba394209417c9e12fadb54 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 23 May 2011 11:37:58 +0100 Subject: Fix bug causing updates to always mark reports as fixed --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 91f05c32f..6ad6ffaa5 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -49,7 +49,7 @@ sub update_problem : Private { my $update = $c->stash->{update}; my $problem = $c->stash->{problem} || $update->problem; - if ( $update->mark_fixed ) { + if ( $update->mark_fixed eq 't' ) { $problem->state( 'fixed' ); if ( $update->user->id == $problem->user->id ) { -- cgit v1.2.3 From 9b12f95ffb23f7a1e45f47c0bf860ed348ddbf39 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 23 May 2011 11:39:05 +0100 Subject: Add a may show name publicly checkbox to updates form --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 6ad6ffaa5..234b0021c 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -155,6 +155,10 @@ sub process_update : Private { my $name = Utils::trim_text( $params{ name } ); + my $anonymous = 't'; + + $anonymous = 'f' if ( $name && $c->req->param('may_show_name' ) ); + my $update = $c->model('DB::Comment')->new( { text => $params{update}, @@ -166,12 +170,13 @@ sub process_update : Private { cobrand => $c->cobrand->moniker, cobrand_data => $c->cobrand->extra_update_data, lang => $c->stash->{lang_code}, - anonymous => ( $name ? 'f': 't' ), + anonymous => $anonymous, } ); $c->stash->{update} = $update; $c->stash->{add_alert} = $c->req->param('add_alert'); + $c->stash->{may_show_name} = ' checked' if $c->req->param('may_show_name'); return 1; } -- cgit v1.2.3 From ebba62505cf7e9d3b9ef4ea6aa97cd62eda6c2d7 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 23 May 2011 12:58:15 +0100 Subject: tests for correctly normalising fields and resulting bugfixes --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 234b0021c..3d575f6a5 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -130,6 +130,7 @@ sub process_user : Private { unless $update_user->name; $c->stash->{update_user} = $update_user; + $c->stash->{email} = $update_user->email; return 1; } @@ -153,11 +154,11 @@ sub process_update : Private { $params{update} = Utils::cleanup_text( $params{update}, { allow_multiline => 1 } ); - my $name = Utils::trim_text( $params{ name } ); + my $name = Utils::trim_text( $params{name} ); my $anonymous = 't'; - $anonymous = 'f' if ( $name && $c->req->param('may_show_name' ) ); + $anonymous = 'f' if ( $name && $c->req->param('may_show_name') ); my $update = $c->model('DB::Comment')->new( { @@ -174,8 +175,9 @@ sub process_update : Private { } ); - $c->stash->{update} = $update; - $c->stash->{add_alert} = $c->req->param('add_alert'); + $c->stash->{update} = $update; + $c->stash->{update_text} = $update->text; + $c->stash->{add_alert} = $c->req->param('add_alert'); $c->stash->{may_show_name} = ' checked' if $c->req->param('may_show_name'); return 1; -- cgit v1.2.3 From 02de04c365b8d7e8323e556b6258c1c92ba672e6 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Tue, 24 May 2011 17:41:48 +0100 Subject: if the person who created the problem is marking it as fixed show them a questionnaire directly ( no submission yet ) --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 3d575f6a5..350024315 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -46,6 +46,8 @@ sub confirm : Private { sub update_problem : Private { my ( $self, $c ) = @_; + my $display_questionnaire = 0; + my $update = $c->stash->{update}; my $problem = $c->stash->{problem} || $update->problem; @@ -54,8 +56,7 @@ sub update_problem : Private { if ( $update->user->id == $problem->user->id ) { $problem->send_questionnaire( 'f' ); - } else { - $c->forward( 'ask_questionnaire' ); + $display_questionnaire = 1; } } @@ -64,14 +65,9 @@ sub update_problem : Private { $c->stash->{problem} = $problem; - - return 1; -} - -sub ask_questionnaire : Private { - my ( $self, $c ) = @_; - - # FIXME send out questionnaire token here + if ( $display_questionnaire ) { + $c->detach('/questionnaire/creator_fixed'); + } return 1; } -- cgit v1.2.3 From ef849541cbe7b200db1bd4af6cdc67e3061d1486 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 25 May 2011 11:51:44 +0100 Subject: don't ask questionnaire if they've ever answered before --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 350024315..1bc15f1f3 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -52,11 +52,16 @@ sub update_problem : Private { my $problem = $c->stash->{problem} || $update->problem; if ( $update->mark_fixed eq 't' ) { - $problem->state( 'fixed' ); + $problem->state('fixed'); if ( $update->user->id == $problem->user->id ) { - $problem->send_questionnaire( 'f' ); - $display_questionnaire = 1; + $problem->send_questionnaire('f'); + + if ( $c->cobrand->ask_ever_reported + && !$problem->user->answered_ever_reported ) + { + $display_questionnaire = 1; + } } } @@ -65,7 +70,7 @@ sub update_problem : Private { $c->stash->{problem} = $problem; - if ( $display_questionnaire ) { + if ($display_questionnaire) { $c->detach('/questionnaire/creator_fixed'); } -- cgit v1.2.3 From 6a679dbe9f0d7021f176ca23106a74bc2475539e Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 25 May 2011 16:43:28 +0100 Subject: submission for questionnaire when problem owner marks it fixed --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') 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'); -- cgit v1.2.3 From f7a711c5b544d876928ba572f46912e09eff9b83 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Thu, 26 May 2011 15:52:49 +0100 Subject: consistency in how we set/check booleans from the database --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 8af3cd2a2..be0f8dc16 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -51,11 +51,11 @@ sub update_problem : Private { my $update = $c->stash->{update}; my $problem = $c->stash->{problem} || $update->problem; - if ( $update->mark_fixed eq 't' ) { + if ( $update->mark_fixed ) { $problem->state('fixed'); if ( $update->user->id == $problem->user->id ) { - $problem->send_questionnaire('f'); + $problem->send_questionnaire(0); if ( $c->cobrand->ask_ever_reported && !$problem->user->answered_ever_reported ) @@ -157,9 +157,9 @@ sub process_update : Private { my $name = Utils::trim_text( $params{name} ); - my $anonymous = 't'; + my $anonymous = 1; - $anonymous = 'f' if ( $name && $c->req->param('may_show_name') ); + $anonymous = 0 if ( $name && $c->req->param('may_show_name') ); my $update = $c->model('DB::Comment')->new( { @@ -168,7 +168,7 @@ sub process_update : Private { problem => $c->stash->{problem}, user => $c->stash->{update_user}, state => 'unconfirmed', - mark_fixed => $params{fixed} ? 't' : 'f', + mark_fixed => $params{fixed} ? 1 : 0, cobrand => $c->cobrand->moniker, cobrand_data => $c->cobrand->extra_update_data, lang => $c->stash->{lang_code}, -- cgit v1.2.3 From f90e024af0cdc65d3c7671684eb096cc4d537917 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Fri, 27 May 2011 12:22:41 +0100 Subject: stop immediately if we do not have the problem id --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index be0f8dc16..e8bb0f70d 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -20,6 +20,10 @@ Creates an update to a report sub report_update : Path : Args(0) { my ( $self, $c ) = @_; + # if there's no id then we should just stop now + $c->detach( '/page_error_404_not_found', [ _('Unknown problem ID') ] ) + unless $c->req->param('id'); + $c->forward('setup_page') && $c->forward('process_user') && $c->forward('process_update') -- cgit v1.2.3 From ec851116d3a1b697996810eff8b2701de78ff621 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 1 Jun 2011 16:13:02 +0100 Subject: use the update from the stash as that should always be there --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index e8bb0f70d..a0c332b40 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -318,7 +318,7 @@ sub signup_for_alerts : Private { my $alert = $c->model( 'DB::Alert' )->find_or_create( user => $c->stash->{update}->user, alert_type => 'new_updates', - parameter => $c->stash->{problem}->id + parameter => $c->stash->{update}->problem_id, ); $alert->update; -- cgit v1.2.3 From a2d9fe2659a1723824c58d7e3d663d1725bcab56 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Wed, 1 Jun 2011 17:28:37 +0100 Subject: mark new_updates alerts as confirmed when they are created --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index a0c332b40..eadf2beea 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -315,10 +315,11 @@ sub signup_for_alerts : Private { my ( $self, $c ) = @_; if ( $c->stash->{add_alert} ) { - my $alert = $c->model( 'DB::Alert' )->find_or_create( - user => $c->stash->{update}->user, + my $alert = $c->model('DB::Alert')->find_or_create( + user => $c->stash->{update}->user, alert_type => 'new_updates', - parameter => $c->stash->{update}->problem_id, + parameter => $c->stash->{update}->problem_id, + confirmed => 1, ); $alert->update; -- cgit v1.2.3 From b019beb393534919c249fa16e7ab07ac63fa52c5 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Fri, 3 Jun 2011 22:18:05 +0100 Subject: Fix bug whereby lat/lon were being stored the wrong way round in local alerts. --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index eadf2beea..a1120470b 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -315,12 +315,15 @@ sub signup_for_alerts : Private { my ( $self, $c ) = @_; if ( $c->stash->{add_alert} ) { + my $update = $c->stash->{update}; my $alert = $c->model('DB::Alert')->find_or_create( - user => $c->stash->{update}->user, - alert_type => 'new_updates', - parameter => $c->stash->{update}->problem_id, - confirmed => 1, - ); + user => $update->user, + alert_type => 'new_updates', + parameter => $update->problem_id, + cobrand => $update->cobrand, + cobrand_data => $update->cobrand_data, + lang => $update->lang, + )->confirm(); $alert->update; } -- cgit v1.2.3 From 29c1e2780bca1a348d5d6a9531c967b84110f7be Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 6 Jun 2011 10:13:55 +0100 Subject: confirm does not return alert object so do not assign to alert --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index a1120470b..8de909738 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -323,7 +323,9 @@ sub signup_for_alerts : Private { cobrand => $update->cobrand, cobrand_data => $update->cobrand_data, lang => $update->lang, - )->confirm(); + ); + + $alert->confirm(); $alert->update; } -- cgit v1.2.3 From cd0ff4b083042c7d9a14d369326c5247893416c5 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Mon, 6 Jun 2011 11:08:27 +0100 Subject: Complete report update display migration. --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 2 -- 1 file changed, 2 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 8de909738..e0a7033b9 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -326,8 +326,6 @@ sub signup_for_alerts : Private { ); $alert->confirm(); - - $alert->update; } return 1; -- cgit v1.2.3 From 988fa9695dc0446887a30d6489786ab1323363c4 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Tue, 7 Jun 2011 16:28:47 +0100 Subject: Improve email headers in emails sent. --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index e0a7033b9..fe512d03c 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -292,7 +292,11 @@ sub redirect_or_confirm_creation : Private { } ); $c->stash->{token_url} = $c->uri_for_email( '/C', $token->token ); - $c->send_email( 'update-confirm.txt', { to => $update->user->email } ); + $c->send_email( 'update-confirm.txt', { + to => $update->name + ? [ [ $update->user->email, $update->name ] ] + : $update->user->email, + } ); # tell user that they've been sent an email $c->stash->{template} = 'email_sent.html'; -- cgit v1.2.3 From 500190d03fcbfd8993f46b61bca9e12a7339dbc2 Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 8 Jun 2011 13:51:17 +0100 Subject: Switch to using c->cobrand->problems to return all problems for a cobrand (so on Barnet only return Barnet problems). --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index fe512d03c..2ca9245ad 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -99,7 +99,7 @@ sub setup_page : Private { my ( $self, $c ) = @_; my $problem = - $c->model('DB::Problem')->find( { id => $c->req->param('id') } ); + $c->cobrand->problems->find( { id => $c->req->param('id') } ); return unless $problem; -- cgit v1.2.3 From 5d60e828ccd46a805e9463d14f388188efef9f4e Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 9 Jun 2011 11:22:54 +0100 Subject: Centralise problem report loading, 404/410 checking. --- perllib/FixMyStreet/App/Controller/Report/Update.pm | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'perllib/FixMyStreet/App/Controller/Report/Update.pm') diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 2ca9245ad..2f1d88d08 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -24,7 +24,7 @@ sub report_update : Path : Args(0) { $c->detach( '/page_error_404_not_found', [ _('Unknown problem ID') ] ) unless $c->req->param('id'); - $c->forward('setup_page') + $c->forward( '/report/load_problem_or_display_error', [ $c->req->param('id') ] ) && $c->forward('process_user') && $c->forward('process_update') && $c->forward('/report/new/process_photo') @@ -89,25 +89,6 @@ sub display_confirmation : Private { return 1; } -=head2 setup_page - -Setup things we need for later. - -=cut - -sub setup_page : Private { - my ( $self, $c ) = @_; - - my $problem = - $c->cobrand->problems->find( { id => $c->req->param('id') } ); - - return unless $problem; - - $c->stash->{problem} = $problem; - - return 1; -} - =head2 process_user Load user from the database or prepare a new one. -- cgit v1.2.3