diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
22 files changed, 600 insertions, 419 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index de13a76de..6145a6eb0 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -246,19 +246,16 @@ sub bodies : Path('bodies') : Args(0) { $c->stash->{edit_activity} = $edit_activity; - my $posted = $c->req->param('posted') || ''; + my $posted = $c->get_param('posted') || ''; if ( $posted eq 'body' ) { $c->forward('check_for_super_user'); $c->forward('check_token'); my $params = $c->forward('body_params'); my $body = $c->model('DB::Body')->create( $params ); - my $area_ids = $c->req->params->{area_ids}; - if ($area_ids) { - $area_ids = [ $area_ids ] unless ref $area_ids; - foreach (@$area_ids) { - $c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } ); - } + my @area_ids = $c->get_param_list('area_ids'); + foreach (@area_ids) { + $c->model('DB::BodyArea')->create( { body => $body, area_id => $_ } ); } $c->stash->{updated} = _('New body added'); @@ -266,9 +263,6 @@ sub bodies : Path('bodies') : Args(0) { $c->forward( 'fetch_all_bodies' ); - # XXX For fixmystreet.com, need to exclude bodies that are covering London. - # But soon, this means just don't have bodies covering London. - my $contacts = $c->model('DB::Contact')->search( undef, { @@ -317,7 +311,7 @@ sub body : Path('body') : Args(1) { $c->forward( 'fetch_all_bodies' ); $c->forward( 'body_form_dropdowns' ); - if ( $c->req->param('posted') ) { + if ( $c->get_param('posted') ) { $c->log->debug( 'posted' ); $c->forward('update_contacts'); } @@ -337,7 +331,7 @@ sub check_for_super_user : Private { sub update_contacts : Private { my ( $self, $c ) = @_; - my $posted = $c->req->param('posted'); + my $posted = $c->get_param('posted'); my $editor = $c->forward('get_user'); if ( $posted eq 'new' ) { @@ -345,11 +339,11 @@ sub update_contacts : Private { my %errors; - my $category = $self->trim( $c->req->param( 'category' ) ); + my $category = $self->trim( $c->get_param('category') ); $errors{category} = _("Please choose a category") unless $category; - my $email = $self->trim( $c->req->param( 'email' ) ); - $errors{email} = _('Please enter a valid email') unless is_valid_email($email); - $errors{note} = _('Please enter a message') unless $c->req->param('note'); + my $email = $self->trim( $c->get_param('email') ); + $errors{email} = _('Please enter a valid email') unless is_valid_email($email) || $email eq 'REFUSED'; + $errors{note} = _('Please enter a message') unless $c->get_param('note'); $category = 'Empty property' if $c->cobrand->moniker eq 'emptyhomes'; @@ -361,16 +355,16 @@ sub update_contacts : Private { ); $contact->email( $email ); - $contact->confirmed( $c->req->param('confirmed') ? 1 : 0 ); - $contact->deleted( $c->req->param('deleted') ? 1 : 0 ); - $contact->non_public( $c->req->param('non_public') ? 1 : 0 ); - $contact->note( $c->req->param('note') ); + $contact->confirmed( $c->get_param('confirmed') ? 1 : 0 ); + $contact->deleted( $c->get_param('deleted') ? 1 : 0 ); + $contact->non_public( $c->get_param('non_public') ? 1 : 0 ); + $contact->note( $c->get_param('note') ); $contact->whenedited( \'ms_current_timestamp()' ); $contact->editor( $editor ); - $contact->endpoint( $c->req->param('endpoint') ); - $contact->jurisdiction( $c->req->param('jurisdiction') ); - $contact->api_key( $c->req->param('api_key') ); - $contact->send_method( $c->req->param('send_method') ); + $contact->endpoint( $c->get_param('endpoint') ); + $contact->jurisdiction( $c->get_param('jurisdiction') ); + $contact->api_key( $c->get_param('api_key') ); + $contact->send_method( $c->get_param('send_method') ); if ( %errors ) { $c->stash->{updated} = _('Please correct the errors below'); @@ -389,7 +383,7 @@ sub update_contacts : Private { } elsif ( $posted eq 'update' ) { $c->forward('check_token'); - my @categories = $c->req->param('confirmed'); + my @categories = $c->get_param_list('confirmed'); my $contacts = $c->model('DB::Contact')->search( { @@ -416,13 +410,10 @@ sub update_contacts : Private { $c->stash->{body}->update( $params ); my @current = $c->stash->{body}->body_areas->all; my %current = map { $_->area_id => 1 } @current; - my $area_ids = $c->req->params->{area_ids}; - if ($area_ids) { - $area_ids = [ $area_ids ] unless ref $area_ids; - foreach (@$area_ids) { - $c->model('DB::BodyArea')->find_or_create( { body => $c->stash->{body}, area_id => $_ } ); - delete $current{$_}; - } + my @area_ids = $c->get_param_list('area_ids'); + foreach (@area_ids) { + $c->model('DB::BodyArea')->find_or_create( { body => $c->stash->{body}, area_id => $_ } ); + delete $current{$_}; } # Remove any others $c->stash->{body}->body_areas->search( { area_id => [ keys %current ] } )->delete; @@ -434,7 +425,7 @@ sub update_contacts : Private { sub body_params : Private { my ( $self, $c ) = @_; - my @fields = qw/name endpoint jurisdiction api_key send_method send_comments suppress_alerts send_extended_statuses comment_user_id can_be_devolved parent deleted/; + my @fields = qw/name endpoint jurisdiction api_key send_method external_url/; my %defaults = map { $_ => '' } @fields; %defaults = ( %defaults, send_comments => 0, @@ -445,7 +436,7 @@ sub body_params : Private { parent => undef, deleted => 0, ); - my %params = map { $_ => $c->req->param($_) || $defaults{$_} } @fields; + my %params = map { $_ => $c->get_param($_) || $defaults{$_} } keys %defaults; return \%params; } @@ -456,7 +447,7 @@ sub display_contacts : Private { $c->stash->{contacts} = $contacts; $c->stash->{live_contacts} = $contacts->search({ deleted => 0 }); - if ( $c->req->param('text') && $c->req->param('text') == 1 ) { + if ( $c->get_param('text') && $c->get_param('text') == 1 ) { $c->stash->{template} = 'admin/council_contacts.txt'; $c->res->content_type('text/plain; charset=utf-8'); return 1; @@ -535,16 +526,16 @@ sub reports : Path('reports') { } } - my $order = $c->req->params->{o} || 'created'; - my $dir = defined $c->req->params->{d} ? $c->req->params->{d} : 1; + my $order = $c->get_param('o') || 'created'; + my $dir = defined $c->get_param('d') ? $c->get_param('d') : 1; $c->stash->{order} = $order; $c->stash->{dir} = $dir; $order .= ' desc' if $dir; - my $p_page = $c->req->params->{p} || 1; - my $u_page = $c->req->params->{u} || 1; + my $p_page = $c->get_param('p') || 1; + my $u_page = $c->get_param('u') || 1; - if (my $search = $c->req->param('search')) { + if (my $search = $c->get_param('search')) { $c->stash->{searched} = $search; my $site_restriction = $c->cobrand->site_restriction; @@ -687,7 +678,7 @@ sub report_edit : Path('report_edit') : Args(1) { ); } - if ( $c->req->param('rotate_photo') ) { + if ( $c->get_param('rotate_photo') ) { $c->forward('rotate_photo'); return 1; } @@ -704,7 +695,7 @@ sub report_edit : Path('report_edit') : Args(1) { ->search( { problem_id => $problem->id }, { order_by => 'created' } ) ->all ]; - if ( $c->req->param('resend') ) { + if ( $c->get_param('resend') ) { $c->forward('check_token'); $problem->whensent(undef); @@ -714,24 +705,31 @@ sub report_edit : Path('report_edit') : Args(1) { $c->forward( 'log_edit', [ $id, 'problem', 'resend' ] ); } - elsif ( $c->req->param('flaguser') ) { + elsif ( $c->get_param('mark_sent') ) { + $c->forward('check_token'); + $problem->whensent(\'ms_current_timestamp()'); + $problem->update(); + $c->stash->{status_message} = '<p><em>' . _('That problem has been marked as sent.') . '</em></p>'; + $c->forward( 'log_edit', [ $id, 'problem', 'marked sent' ] ); + } + elsif ( $c->get_param('flaguser') ) { $c->forward('flag_user'); $c->stash->{problem}->discard_changes; } - elsif ( $c->req->param('removeuserflag') ) { + elsif ( $c->get_param('removeuserflag') ) { $c->forward('remove_user_flag'); $c->stash->{problem}->discard_changes; } - elsif ( $c->req->param('banuser') ) { + elsif ( $c->get_param('banuser') ) { $c->forward('ban_user'); } - elsif ( $c->req->param('submit') ) { + elsif ( $c->get_param('submit') ) { $c->forward('check_token'); my $done = 0; my $edited = 0; - my $new_state = $c->req->param('state'); + my $new_state = $c->get_param('state'); my $old_state = $problem->state; if ( $new_state eq 'confirmed' && $problem->state eq 'unconfirmed' @@ -744,35 +742,35 @@ sub report_edit : Path('report_edit') : Args(1) { $done = 1; } - my $flagged = $c->req->param('flagged') ? 1 : 0; - my $non_public = $c->req->param('non_public') ? 1 : 0; + my $flagged = $c->get_param('flagged') ? 1 : 0; + my $non_public = $c->get_param('non_public') ? 1 : 0; # do this here so before we update the values in problem - if ( $c->req->param('anonymous') ne $problem->anonymous - || $c->req->param('name') ne $problem->name - || $c->req->param('email') ne $problem->user->email - || $c->req->param('title') ne $problem->title - || $c->req->param('detail') ne $problem->detail - || ($c->req->param('body') && $c->req->param('body') ne $problem->bodies_str) + if ( $c->get_param('anonymous') ne $problem->anonymous + || $c->get_param('name') ne $problem->name + || $c->get_param('email') ne $problem->user->email + || $c->get_param('title') ne $problem->title + || $c->get_param('detail') ne $problem->detail + || ($c->get_param('body') && $c->get_param('body') ne $problem->bodies_str) || $flagged != $problem->flagged || $non_public != $problem->non_public ) { $edited = 1; } - $problem->anonymous( $c->req->param('anonymous') ); - $problem->title( $c->req->param('title') ); - $problem->detail( $c->req->param('detail') ); + $problem->anonymous( $c->get_param('anonymous') ); + $problem->title( $c->get_param('title') ); + $problem->detail( $c->get_param('detail') ); $problem->state( $new_state ); - $problem->name( $c->req->param('name') ); - $problem->bodies_str( $c->req->param('body') ) if $c->req->param('body'); + $problem->name( $c->get_param('name') ); + $problem->bodies_str( $c->get_param('body') ) if $c->get_param('body'); $problem->flagged( $flagged ); $problem->non_public( $non_public ); - if ( $c->req->param('email') ne $problem->user->email ) { + if ( $c->get_param('email') ne $problem->user->email ) { my $user = $c->model('DB::User')->find_or_create( - { email => $c->req->param('email') } + { email => $c->get_param('email') } ); $user->insert unless $user->in_storage; @@ -780,11 +778,11 @@ sub report_edit : Path('report_edit') : Args(1) { } # Deal with photos - if ( $c->req->param('remove_photo') ) { + if ( $c->get_param('remove_photo') ) { $problem->photo(undef); } - if ( $c->req->param('remove_photo') || $new_state eq 'hidden' ) { + if ( $c->get_param('remove_photo') || $new_state eq 'hidden' ) { unlink glob FixMyStreet->path_to( 'web', 'photo', $problem->id . '.*' ); } @@ -821,7 +819,7 @@ sub report_edit : Path('report_edit') : Args(1) { sub users: Path('users') : Args(0) { my ( $self, $c ) = @_; - if (my $search = $c->req->param('search')) { + if (my $search = $c->get_param('search')) { $c->stash->{searched} = $search; my $isearch = '%' . $search . '%'; @@ -893,52 +891,52 @@ sub update_edit : Path('update_edit') : Args(1) { $c->forward('check_email_for_abuse', [ $update->user->email ] ); - if ( $c->req->param('banuser') ) { + if ( $c->get_param('banuser') ) { $c->forward('ban_user'); } - elsif ( $c->req->param('flaguser') ) { + elsif ( $c->get_param('flaguser') ) { $c->forward('flag_user'); $c->stash->{update}->discard_changes; } - elsif ( $c->req->param('removeuserflag') ) { + elsif ( $c->get_param('removeuserflag') ) { $c->forward('remove_user_flag'); $c->stash->{update}->discard_changes; } - elsif ( $c->req->param('submit') ) { + elsif ( $c->get_param('submit') ) { $c->forward('check_token'); my $old_state = $update->state; - my $new_state = $c->req->param('state'); + my $new_state = $c->get_param('state'); my $edited = 0; # $update->name can be null which makes ne unhappy my $name = $update->name || ''; - if ( $c->req->param('name') ne $name - || $c->req->param('email') ne $update->user->email - || $c->req->param('anonymous') ne $update->anonymous - || $c->req->param('text') ne $update->text ){ + if ( $c->get_param('name') ne $name + || $c->get_param('email') ne $update->user->email + || $c->get_param('anonymous') ne $update->anonymous + || $c->get_param('text') ne $update->text ) { $edited = 1; } - if ( $c->req->param('remove_photo') ) { + if ( $c->get_param('remove_photo') ) { $update->photo(undef); } - if ( $c->req->param('remove_photo') || $new_state eq 'hidden' ) { + if ( $c->get_param('remove_photo') || $new_state eq 'hidden' ) { unlink glob FixMyStreet->path_to( 'web', 'photo', 'c', $update->id . '.*' ); } - $update->name( $c->req->param('name') || '' ); - $update->text( $c->req->param('text') ); - $update->anonymous( $c->req->param('anonymous') ); + $update->name( $c->get_param('name') || '' ); + $update->text( $c->get_param('text') ); + $update->anonymous( $c->get_param('anonymous') ); $update->state( $new_state ); - if ( $c->req->param('email') ne $update->user->email ) { + if ( $c->get_param('email') ne $update->user->email ) { my $user = $c->model('DB::User') - ->find_or_create( { email => $c->req->param('email') } ); + ->find_or_create( { email => $c->get_param('email') } ); $user->insert unless $user->in_storage; $update->user($user); @@ -989,22 +987,22 @@ sub user_add : Path('user_edit') : Args(0) { $c->forward('get_token'); $c->forward('fetch_all_bodies'); - return 1 unless $c->req->param('submit'); + return 1 unless $c->get_param('submit'); $c->forward('check_token'); - if ( $c->cobrand->moniker eq 'zurich' and $c->req->param('email') eq '' ) { + if ( $c->cobrand->moniker eq 'zurich' and $c->get_param('email') eq '' ) { $c->stash->{field_errors}->{email} = _('Please enter a valid email'); return 1; } - return unless $c->req->param('name') && $c->req->param('email'); + return unless $c->get_param('name') && $c->get_param('email'); my $user = $c->model('DB::User')->find_or_create( { - name => $c->req->param('name'), - email => $c->req->param('email'), - from_body => $c->req->param('body') || undef, - flagged => $c->req->param('flagged') || 0, + name => $c->get_param('name'), + email => $c->get_param('email'), + from_body => $c->get_param('body') || undef, + flagged => $c->get_param('flagged') || 0, }, { key => 'users_email_key' } ); @@ -1028,23 +1026,23 @@ sub user_edit : Path('user_edit') : Args(1) { $c->forward('fetch_all_bodies'); - if ( $c->req->param('submit') ) { + if ( $c->get_param('submit') ) { $c->forward('check_token'); my $edited = 0; - if ( $user->email ne $c->req->param('email') || - $user->name ne $c->req->param('name' ) || - ($user->from_body && $user->from_body->id ne $c->req->param('body')) || - (!$user->from_body && $c->req->param('body')) + if ( $user->email ne $c->get_param('email') || + $user->name ne $c->get_param('name') || + ($user->from_body && $user->from_body->id ne $c->get_param('body')) || + (!$user->from_body && $c->get_param('body')) ) { $edited = 1; } - $user->name( $c->req->param('name') ); - $user->email( $c->req->param('email') ); - $user->from_body( $c->req->param('body') || undef ); - $user->flagged( $c->req->param('flagged') || 0 ); + $user->name( $c->get_param('name') ); + $user->email( $c->get_param('email') ); + $user->from_body( $c->get_param('body') || undef ); + $user->flagged( $c->get_param('flagged') || 0 ); if ( $c->cobrand->moniker eq 'zurich' and $user->email eq '' ) { $c->stash->{field_errors}->{email} = _('Please enter a valid email'); @@ -1100,16 +1098,16 @@ sub stats : Path('stats') : Args(0) { return $c->cobrand->admin_stats(); } - if ( $c->req->param('getcounts') ) { + if ( $c->get_param('getcounts') ) { my ( $start_date, $end_date, @errors ); my $parser = DateTime::Format::Strptime->new( pattern => '%d/%m/%Y' ); - $start_date = $parser-> parse_datetime ( $c->req->param('start_date') ); + $start_date = $parser-> parse_datetime ( $c->get_param('start_date') ); push @errors, _('Invalid start date') unless defined $start_date; - $end_date = $parser-> parse_datetime ( $c->req->param('end_date') ) ; + $end_date = $parser-> parse_datetime ( $c->get_param('end_date') ) ; push @errors, _('Invalid end date') unless defined $end_date; @@ -1117,21 +1115,21 @@ sub stats : Path('stats') : Args(0) { $c->stash->{start_date} = $start_date; $c->stash->{end_date} = $end_date; - $c->stash->{unconfirmed} = $c->req->param('unconfirmed') eq 'on' ? 1 : 0; + $c->stash->{unconfirmed} = $c->get_param('unconfirmed') eq 'on' ? 1 : 0; return 1 if @errors; - my $bymonth = $c->req->param('bymonth'); + my $bymonth = $c->get_param('bymonth'); $c->stash->{bymonth} = $bymonth; my ( %body, %dates ); - $body{bodies_str} = { like => $c->req->param('body') } - if $c->req->param('body'); + $body{bodies_str} = { like => $c->get_param('body') } + if $c->get_param('body'); - $c->stash->{selected_body} = $c->req->param('body'); + $c->stash->{selected_body} = $c->get_param('body'); my $field = 'confirmed'; - $field = 'created' if $c->req->param('unconfirmed'); + $field = 'created' if $c->get_param('unconfirmed'); my $one_day = DateTime::Duration->new( days => 1 ); @@ -1143,7 +1141,7 @@ sub stats : Path('stats') : Args(0) { order_by => [ 'state' ], ); - if ( $c->req->param('bymonth') ) { + if ( $c->get_param('bymonth') ) { %select = ( select => [ { extract => \"year from $field", -as => 'c_year' }, @@ -1252,7 +1250,7 @@ not then display 404 page sub check_token : Private { my ( $self, $c ) = @_; - if ( !$c->req->param('token') || $c->req->param('token' ) ne $c->stash->{token} ) { + if ( !$c->get_param('token') || $c->get_param('token') ne $c->stash->{token} ) { $c->detach( '/page_error_404_not_found' ); } @@ -1290,7 +1288,7 @@ accordingly sub ban_user : Private { my ( $self, $c ) = @_; - my $email = $c->req->param('email'); + my $email = $c->get_param('email'); return unless $email; @@ -1317,7 +1315,7 @@ Sets the flag on a user with the given email sub flag_user : Private { my ( $self, $c ) = @_; - my $email = $c->req->param('email'); + my $email = $c->get_param('email'); return unless $email; @@ -1345,7 +1343,7 @@ Remove the flag on a user with the given email sub remove_user_flag : Private { my ( $self, $c ) = @_; - my $email = $c->req->param('email'); + my $email = $c->get_param('email'); return unless $email; @@ -1390,7 +1388,7 @@ Rotate a photo 90 degrees left or right sub rotate_photo : Private { my ( $self, $c ) =@_; - my $direction = $c->req->param('rotate_photo'); + my $direction = $c->get_param('rotate_photo'); return unless $direction eq _('Rotate Left') or $direction eq _('Rotate Right'); my $photo = $c->stash->{problem}->photo; diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index e821b7467..6972bbc04 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -53,14 +53,14 @@ Target for subscribe form sub subscribe : Path('subscribe') : Args(0) { my ( $self, $c ) = @_; - $c->detach('rss') if $c->req->param('rss'); + $c->detach('rss') if $c->get_param('rss'); # if it exists then it's been submitted so we should # go to subscribe email and let it work out the next step $c->detach('subscribe_email') - if exists $c->req->params->{'rznvy'} || $c->req->params->{'alert'}; + if $c->get_param('rznvy') || $c->get_param('alert'); - $c->go('updates') if $c->req->params->{'id'}; + $c->go('updates') if $c->get_param('id'); # shouldn't get to here but if we have then do something sensible $c->go('index'); @@ -74,7 +74,7 @@ Redirects to relevant RSS feed sub rss : Private { my ( $self, $c ) = @_; - my $feed = $c->req->params->{feed}; + my $feed = $c->get_param('feed'); unless ($feed) { $c->stash->{errors} = [ _('Please select the feed you want') ]; @@ -114,9 +114,9 @@ sub subscribe_email : Private { $c->stash->{errors} = []; $c->forward('process_user'); - my $type = $c->req->param('type'); + my $type = $c->get_param('type'); push @{ $c->stash->{errors} }, _('Please select the type of alert you want') - if $type && $type eq 'local' && !$c->req->param('feed'); + if $type && $type eq 'local' && !$c->get_param('feed'); if (@{ $c->stash->{errors} }) { $c->go('updates') if $type && $type eq 'updates'; $c->go('list') if $type && $type eq 'local'; @@ -145,8 +145,8 @@ sub subscribe_email : Private { sub updates : Path('updates') : Args(0) { my ( $self, $c ) = @_; - $c->stash->{email} = $c->req->param('rznvy'); - $c->stash->{problem_id} = $c->req->param('id'); + $c->stash->{email} = $c->get_param('rznvy'); + $c->stash->{problem_id} = $c->get_param('id'); } =head2 confirm @@ -209,7 +209,7 @@ Set up the options in the stash required to create a problem update alert sub set_update_alert_options : Private { my ( $self, $c ) = @_; - my $report_id = $c->req->param('id'); + my $report_id = $c->get_param('id'); my $options = { user => $c->stash->{alert_user}, @@ -229,7 +229,7 @@ Set up the options in the stash required to create a local problems alert sub set_local_alert_options : Private { my ( $self, $c ) = @_; - my $feed = $c->req->param('feed'); + my $feed = $c->get_param('feed'); my ( $type, @params, $alert ); if ( $feed =~ /^area:(?:\d+:)?(\d+)/ ) { @@ -305,12 +305,12 @@ This will canonicalise and prettify the postcode and stick a pretty_pc and prett sub prettify_pc : Private { my ( $self, $c ) = @_; - my $pretty_pc = $c->req->params->{'pc'}; + my $pretty_pc = $c->get_param('pc'); - if ( mySociety::PostcodeUtil::is_valid_postcode( $c->req->params->{'pc'} ) ) + if ( mySociety::PostcodeUtil::is_valid_postcode( $c->get_param('pc') ) ) { $pretty_pc = mySociety::PostcodeUtil::canonicalise_postcode( - $c->req->params->{'pc'} ); + $c->get_param('pc') ); my $pretty_pc_text = $pretty_pc; $pretty_pc_text =~ s/ //g; $c->stash->{pretty_pc_text} = $pretty_pc_text; @@ -336,7 +336,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($_) } + my %params = map { $_ => $c->get_param($_) } ( 'rznvy' ); # , 'password_register' ); # cleanup the email address @@ -350,7 +350,7 @@ sub process_user : Private { $c->stash->{alert_user} = $alert_user; # # The user is trying to sign in. We only care about email from the params. -# if ( $c->req->param('submit_sign_in') ) { +# if ( $c->get_param('submit_sign_in') ) { # unless ( $c->forward( '/auth/sign_in', [ $email ] ) ) { # $c->stash->{field_errors}->{password} = _('There was a problem with your email/password combination. Please try again.'); # return 1; @@ -441,11 +441,6 @@ sub determine_location : Private { $c->go('index'); } - # truncate the lat,lon for nicer urls - ( $c->stash->{latitude}, $c->stash->{longitude} ) = - map { Utils::truncate_coordinate($_) } - ( $c->stash->{latitude}, $c->stash->{longitude} ); - my $dist = mySociety::Gaze::get_radius_containing_population( $c->stash->{latitude}, $c->stash->{longitude}, 200000 ); @@ -503,14 +498,14 @@ Setup the variables we need for the rest of the request sub setup_request : Private { my ( $self, $c ) = @_; - $c->stash->{rznvy} = $c->req->param('rznvy'); - $c->stash->{selected_feed} = $c->req->param('feed'); + $c->stash->{rznvy} = $c->get_param('rznvy'); + $c->stash->{selected_feed} = $c->get_param('feed'); if ( $c->user ) { $c->stash->{rznvy} ||= $c->user->email; } - $c->stash->{template} = 'alert/list-ajax.html' if $c->req->param('ajax'); + $c->stash->{template} = 'alert/list-ajax.html' if $c->get_param('ajax'); return 1; } diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 0e42b8a17..723684793 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -40,8 +40,10 @@ sub around_index : Path : Args(0) { # Try to create a location for whatever we have my $ret = $c->forward('/location/determine_location_from_coords') || $c->forward('/location/determine_location_from_pc'); - return unless $ret; - return $c->res->redirect('/') if $ret == -1 && !$partial_report; + unless ($ret) { + return $c->res->redirect('/') unless $c->get_param('pc') || $partial_report; + return; + } # Check to see if the spot is covered by a area - if not show an error. return unless $c->cobrand->moniker eq 'fixmybarangay' || $c->forward('check_location_is_acceptable'); @@ -76,13 +78,12 @@ Handle coord systems that are no longer in use. sub redirect_en_or_xy_to_latlon : Private { my ( $self, $c ) = @_; - my $req = $c->req; # check for x,y or e,n requests - my $x = $req->param('x'); - my $y = $req->param('y'); - my $e = $req->param('e'); - my $n = $req->param('n'); + my $x = $c->get_param('x'); + my $y = $c->get_param('y'); + my $e = $c->get_param('e'); + my $n = $c->get_param('n'); # lat and lon - fill in below if we need to my ( $lat, $lon ); @@ -116,7 +117,7 @@ token to stash and return report. Otherwise return false. sub load_partial : Private { my ( $self, $c ) = @_; - my $partial = scalar $c->req->param('partial') + my $partial = $c->get_param('partial') || return; # is it in the database @@ -158,21 +159,20 @@ sub display_location : Private { my $latitude = $c->stash->{latitude}; my $longitude = $c->stash->{longitude}; - # truncate the lat,lon for nicer rss urls, and strings for outputting - my $short_latitude = Utils::truncate_coordinate($latitude); - my $short_longitude = Utils::truncate_coordinate($longitude); - $c->stash->{short_latitude} = $short_latitude; - $c->stash->{short_longitude} = $short_longitude; - # Deal with pin hiding/age - my $all_pins = $c->req->param('all_pins') ? 1 : undef; + my $all_pins = $c->get_param('all_pins') ? 1 : undef; $c->stash->{all_pins} = $all_pins; my $interval = $all_pins ? undef : $c->cobrand->on_map_default_max_pin_age; + $c->forward( '/reports/stash_report_filter_status' ); + + # Check the category to filter by, if any, is valid + $c->forward('check_and_stash_category'); + # get the map features my ( $on_map_all, $on_map, $around_map, $distance ) = - FixMyStreet::Map::map_features( $c, $short_latitude, $short_longitude, - $interval ); + FixMyStreet::Map::map_features( $c, $latitude, $longitude, + $interval, $c->stash->{filter_category}, $c->stash->{filter_problem_states} ); # copy the found reports to the stash $c->stash->{on_map} = $on_map; @@ -181,7 +181,7 @@ sub display_location : Private { # create a list of all the pins my @pins; - unless ($c->req->param('no_pins') || $c->cobrand->moniker eq 'emptyhomes') { + unless ($c->get_param('no_pins') || $c->cobrand->moniker eq 'emptyhomes') { @pins = map { # Here we might have a DB::Problem or a DB::Nearby, we always want the problem. my $p = (ref $_ eq 'FixMyStreet::App::Model::DB::Nearby') ? $_->problem : $_; @@ -199,8 +199,8 @@ sub display_location : Private { $c->stash->{page} = 'around'; # So the map knows to make clickable pins, update on pan FixMyStreet::Map::display_map( $c, - latitude => $short_latitude, - longitude => $short_longitude, + latitude => $latitude, + longitude => $longitude, clickable => 1, pins => \@pins, area => $c->cobrand->areas_on_around, @@ -225,6 +225,45 @@ sub check_location_is_acceptable : Private { return $c->forward('/council/load_and_check_areas'); } +=head2 check_and_stash_category + +Check that the 'filter_category' query param is valid, if it's present. Stores +the validated string in the stash as filter_category. +Puts all the valid categories in filter_categories on the stash. + +=cut + +sub check_and_stash_category : Private { + my ( $self, $c ) = @_; + + my $all_areas = $c->stash->{all_areas}; + my @bodies = $c->model('DB::Body')->search( + { 'body_areas.area_id' => [ keys %$all_areas ], deleted => 0 }, + { join => 'body_areas' } + )->all; + my %bodies = map { $_->id => $_ } @bodies; + + my @contacts = $c->model('DB::Contact')->not_deleted->search( + { + body_id => [ keys %bodies ], + }, + { + columns => [ 'category' ], + order_by => [ 'category' ], + distinct => 1 + } + )->all; + my @categories = map { $_->category } @contacts; + $c->stash->{filter_categories} = \@categories; + + + my $category = $c->get_param('filter_category'); + my %categories_mapped = map { $_ => 1 } @categories; + if ( defined $category && $categories_mapped{$category} ) { + $c->stash->{filter_category} = $category; + } +} + =head2 /ajax Handle the ajax calls that the map makes when it is dragged. The info returned @@ -238,7 +277,7 @@ sub ajax : Path('/ajax') { $c->res->content_type('application/json; charset=utf-8'); - unless ( $c->req->param('bbox') ) { + unless ( $c->get_param('bbox') ) { $c->res->status(404); $c->res->body(''); return; @@ -248,7 +287,7 @@ sub ajax : Path('/ajax') { $c->res->header( 'Cache_Control' => 'max-age=0' ); # how far back should we go? - my $all_pins = $c->req->param('all_pins') ? 1 : undef; + my $all_pins = $c->get_param('all_pins') ? 1 : undef; my $interval = $all_pins ? undef : $c->cobrand->on_map_default_max_pin_age; # Need to be the class that can handle it @@ -280,7 +319,7 @@ sub ajax : Path('/ajax') { sub location_autocomplete : Path('/ajax/geocode') { my ( $self, $c ) = @_; $c->res->content_type('application/json; charset=utf-8'); - unless ( $c->req->param('term') ) { + unless ( $c->get_param('term') ) { $c->res->status(404); $c->res->body(''); return; @@ -288,26 +327,26 @@ sub location_autocomplete : Path('/ajax/geocode') { # we want the match even if there's no ambiguity, so recommendation doesn't # disappear when it's the last choice being offered in the autocomplete. $c->stash->{allow_single_geocode_match_strings} = 1; - return $self->_geocode( $c, $c->req->param('term') ); + return $self->_geocode( $c, $c->get_param('term') ); } sub location_lookup : Path('/ajax/lookup_location') { my ( $self, $c ) = @_; $c->res->content_type('application/json; charset=utf-8'); - unless ( $c->req->param('term') ) { + unless ( $c->get_param('term') ) { $c->res->status(404); $c->res->body(''); return; } - return $self->_geocode( $c, $c->req->param('term') ); + return $self->_geocode( $c, $c->get_param('term') ); } sub _geocode : Private { my ( $self, $c, $term ) = @_; my ( $lat, $long, $suggestions ) = - FixMyStreet::Geocode::lookup( $c->req->param('term'), $c ); + FixMyStreet::Geocode::lookup( $c->get_param('term'), $c ); my ($response, @addresses, @locations); @@ -317,7 +356,7 @@ sub _geocode : Private { if ( ref($suggestions) eq 'ARRAY' ) { foreach (@$suggestions) { push @addresses, decode_utf8($_->{address}); - push @locations, { address => decode_utf8($_->{address}), lat => $_->{latitude}, long => $_->{longitude} }; + push @locations, { address => decode_utf8($_->{address}), lat => $_->{latitude}, long => $_->{longitude} }; } $response = { suggestions => \@addresses, locations => \@locations }; } else { diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm index fad8941c5..63bf91ff5 100644 --- a/perllib/FixMyStreet/App/Controller/Auth.pm +++ b/perllib/FixMyStreet/App/Controller/Auth.pm @@ -28,22 +28,21 @@ Present the user with a sign in / create account page. sub general : Path : Args(0) { my ( $self, $c ) = @_; - my $req = $c->req; - $c->detach( 'redirect_on_signin', [ $req->param('r') ] ) - if $c->user && $req->param('r'); + $c->detach( 'redirect_on_signin', [ $c->get_param('r') ] ) + if $c->user && $c->get_param('r'); # all done unless we have a form posted to us - return unless $req->method eq 'POST'; + return unless $c->req->method eq 'POST'; # decide which action to take - my $has_password = $req->param('sign_in') || $req->param('password_sign_in'); - my $has_email = $req->param('email_sign_in') || $req->param('name') || $req->param('password_register'); + my $has_password = $c->get_param('sign_in') || $c->get_param('password_sign_in'); + my $has_email = $c->get_param('email_sign_in') || $c->get_param('name') || $c->get_param('password_register'); $c->detach('email_sign_in') if $has_email && !$has_password; $c->forward( 'sign_in' ) - && $c->detach( 'redirect_on_signin', [ $req->param('r') ] ); + && $c->detach( 'redirect_on_signin', [ $c->get_param('r') ] ); } @@ -56,9 +55,9 @@ Allow the user to sign in with a username and a password. sub sign_in : Private { my ( $self, $c, $email ) = @_; - $email ||= $c->req->param('email') || ''; - my $password = $c->req->param('password_sign_in') || ''; - my $remember_me = $c->req->param('remember_me') || 0; + $email ||= $c->get_param('email') || ''; + my $password = $c->get_param('password_sign_in') || ''; + my $remember_me = $c->get_param('remember_me') || 0; # Sign out just in case $c->logout(); @@ -95,7 +94,7 @@ sub email_sign_in : Private { my ( $self, $c ) = @_; # check that the email is valid - otherwise flag an error - my $raw_email = lc( $c->req->param('email') || '' ); + my $raw_email = lc( $c->get_param('email') || '' ); my $email_checker = Email::Valid->new( -mxcheck => 1, @@ -112,8 +111,8 @@ sub email_sign_in : Private { } my $user_params = {}; - $user_params->{password} = $c->req->param('password_register') - if $c->req->param('password_register'); + $user_params->{password} = $c->get_param('password_register') + if $c->get_param('password_register'); my $user = $c->model('DB::User')->new( $user_params ); my $token_obj = $c->model('DB::Token') # @@ -122,8 +121,8 @@ sub email_sign_in : Private { scope => 'email_sign_in', data => { email => $good_email, - r => $c->req->param('r'), - name => $c->req->param('name'), + r => $c->get_param('r'), + name => $c->get_param('name'), password => $user->password, } } @@ -156,6 +155,11 @@ sub token : Path('/M') : Args(1) { return; } + if ( $token_obj->created < DateTime->now->subtract( days => 1 ) ) { + $c->stash->{token_not_found} = 1; + return; + } + # Sign out in case we are another user $c->logout(); @@ -221,8 +225,8 @@ sub change_password : Local { return unless $c->req->method eq 'POST'; # get the passwords - my $new = $c->req->param('new_password') // ''; - my $confirm = $c->req->param('confirm') // ''; + my $new = $c->get_param('new_password') // ''; + my $confirm = $c->get_param('confirm') // ''; # check for errors my $password_error = diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm index f48518d77..912224649 100644 --- a/perllib/FixMyStreet/App/Controller/Contact.pm +++ b/perllib/FixMyStreet/App/Controller/Contact.pm @@ -41,6 +41,11 @@ Handle contact us form submission sub submit : Path('submit') : Args(0) { my ( $self, $c ) = @_; + if (my $testing = $c->get_param('_test_')) { + $c->stash->{success} = $c->get_param('success'); + return; + } + $c->res->redirect( '/contact' ) and return unless $c->req->method eq 'POST'; return @@ -61,9 +66,9 @@ generic contact request and set up things accordingly sub determine_contact_type : Private { my ( $self, $c ) = @_; - my $id = $c->req->param('id'); - my $update_id = $c->req->param('update_id'); - my $token = $c->req->param('m'); + my $id = $c->get_param('id'); + my $update_id = $c->get_param('update_id'); + my $token = $c->get_param('m'); $id = undef unless $id && $id =~ /^[1-9]\d*$/; $update_id = undef unless $update_id && $update_id =~ /^[1-9]\d*$/; @@ -111,12 +116,12 @@ sub validate : Private { foreach my $field ( keys %required ) { $field_errors{$field} = $required{$field} - unless $c->req->param($field) =~ /\S/; + unless $c->get_param($field) =~ /\S/; } unless ( $field_errors{em} ) { $field_errors{em} = _('Please enter a valid email address') - if !mySociety::EmailUtil::is_valid_email( $c->req->param('em') ); + if !mySociety::EmailUtil::is_valid_email( $c->get_param('em') ); } %field_errors = ( @@ -125,11 +130,11 @@ sub validate : Private { ); push @errors, _('Illegal ID') - if $c->req->param('id') && !$c->stash->{problem} - or $c->req->param('update_id') && !$c->stash->{update}; + if $c->get_param('id') && !$c->stash->{problem} + or $c->get_param('update_id') && !$c->stash->{update}; push @errors, _('There was a problem showing this page. Please try again later.') - if $c->req->params->{message} && $c->req->params->{message} =~ /\[url=|<a/; + if $c->get_param('message') && $c->get_param('message') =~ /\[url=|<a/; unshift @errors, _('There were problems with your report. Please see below.') @@ -206,11 +211,11 @@ sub setup_request : Private { $c->stash->{contact_email} =~ s/\@/@/; for my $param (qw/em subject message/) { - $c->stash->{$param} = $c->req->param($param); + $c->stash->{$param} = $c->get_param($param); } # name is already used in the stash for the app class name - $c->stash->{form_name} = $c->req->param('name'); + $c->stash->{form_name} = $c->get_param('name'); return 1; } diff --git a/perllib/FixMyStreet/App/Controller/Council.pm b/perllib/FixMyStreet/App/Controller/Council.pm index 8a174c254..a5915aa46 100644 --- a/perllib/FixMyStreet/App/Controller/Council.pm +++ b/perllib/FixMyStreet/App/Controller/Council.pm @@ -49,9 +49,6 @@ sub load_and_check_areas : Private { $area_types = $c->cobrand->area_types; } - my $short_latitude = Utils::truncate_coordinate($latitude); - my $short_longitude = Utils::truncate_coordinate($longitude); - my $all_areas; my %params; @@ -62,7 +59,7 @@ sub load_and_check_areas : Private { my %area_types = map { $_ => 1 } @$area_types; $all_areas = mySociety::MaPit::call( 'point', - "4326/$short_longitude,$short_latitude", %params ); + "4326/$longitude,$latitude", %params ); $c->stash->{all_areas_mapit} = $all_areas; $all_areas = { map { $_ => $all_areas->{$_} } @@ -72,7 +69,7 @@ sub load_and_check_areas : Private { } else { $all_areas = mySociety::MaPit::call( 'point', - "4326/$short_longitude,$short_latitude", %params, + "4326/$longitude,$latitude", %params, type => $area_types ); } if ($all_areas->{error}) { diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 25c6e1923..c3aa35008 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -32,9 +32,9 @@ sub example : Local : Args(0) { #$c->forward( '/report/new/setup_categories_and_bodies' ); # See if we've had anything from the dropdowns - perhaps vary results if so - $c->stash->{ward} = $c->req->param('ward'); - $c->stash->{category} = $c->req->param('category'); - $c->stash->{q_state} = $c->req->param('state'); + $c->stash->{ward} = $c->get_param('ward'); + $c->stash->{category} = $c->get_param('category'); + $c->stash->{q_state} = $c->get_param('state'); eval { my $data = File::Slurp::read_file( @@ -108,8 +108,8 @@ sub index : Path : Args(0) { # See if we've had anything from the dropdowns - $c->stash->{ward} = $c->req->param('ward'); - $c->stash->{category} = $c->req->param('category'); + $c->stash->{ward} = $c->get_param('ward'); + $c->stash->{category} = $c->get_param('category'); my %where = ( bodies_str => $body->id, # XXX Does this break in a two tier council? Restriction needs looking at... @@ -128,7 +128,7 @@ sub index : Path : Args(0) { my $dtf = $c->model('DB')->storage->datetime_parser; my %counts; - my $now = DateTime->now( time_zone => 'local' ); + my $now = DateTime->now( time_zone => FixMyStreet->local_time_zone ); my $t = $now->clone->truncate( to => 'day' ); $counts{wtd} = $c->forward( 'updates_search', [ $dtf->format_datetime( $t->clone->subtract( days => $t->dow - 1 ) ) ] ); @@ -143,7 +143,7 @@ sub index : Path : Args(0) { # List of reports underneath summary table - $c->stash->{q_state} = $c->req->param('state') || ''; + $c->stash->{q_state} = $c->get_param('state') || ''; if ( $c->stash->{q_state} eq 'fixed' ) { $prob_where->{'me.state'} = [ FixMyStreet::DB::Result::Problem->fixed_states() ]; } elsif ( $c->stash->{q_state} ) { @@ -170,7 +170,7 @@ sub index : Path : Args(0) { } $c->stash->{lists} = \%problems; - if ( $c->req->params->{export} ) { + if ( $c->get_param('export') ) { $self->export_as_csv($c, $problems_rs, $body); } } diff --git a/perllib/FixMyStreet/App/Controller/JSON.pm b/perllib/FixMyStreet/App/Controller/JSON.pm index 17507a84b..959ead245 100644 --- a/perllib/FixMyStreet/App/Controller/JSON.pm +++ b/perllib/FixMyStreet/App/Controller/JSON.pm @@ -38,9 +38,9 @@ sub problems : Local { : ''; # gather the parameters - my $start_date = $c->req->param('start_date') || ''; - my $end_date = $c->req->param('end_date') || ''; - my $category = $c->req->param('category') || ''; + my $start_date = $c->get_param('start_date') || ''; + my $end_date = $c->get_param('end_date') || ''; + my $category = $c->get_param('category') || ''; my $yyyy_mm_dd = qr{^\d{4}-\d\d-\d\d$}; if ( $start_date !~ $yyyy_mm_dd diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm index 8a68b2b3d..ff90d3d60 100644 --- a/perllib/FixMyStreet/App/Controller/Location.pm +++ b/perllib/FixMyStreet/App/Controller/Location.pm @@ -6,6 +6,7 @@ BEGIN {extends 'Catalyst::Controller'; } use Encode; use FixMyStreet::Geocode; +use Utils; =head1 NAME @@ -28,15 +29,15 @@ Use latitude and longitude if provided in parameters. sub determine_location_from_coords : Private { my ( $self, $c ) = @_; - my $latitude = $c->req->param('latitude') || $c->req->param('lat'); - my $longitude = $c->req->param('longitude') || $c->req->param('lon'); + my $latitude = $c->get_param('latitude') || $c->get_param('lat'); + my $longitude = $c->get_param('longitude') || $c->get_param('lon'); if ( defined $latitude && defined $longitude ) { - $c->stash->{latitude} = $latitude; - $c->stash->{longitude} = $longitude; + ($c->stash->{latitude}, $c->stash->{longitude}) = + map { Utils::truncate_coordinate($_) } ($latitude, $longitude); # Also save the pc if there is one - if ( my $pc = $c->req->param('pc') ) { + if ( my $pc = $c->get_param('pc') ) { $c->stash->{pc} = $pc; } @@ -50,7 +51,7 @@ sub determine_location_from_coords : Private { User has searched for a location - try to find it for them. -Return -1 if nothing provided. +Return false if nothing provided. If one match is found returns true and lat/lng is set. @@ -64,18 +65,19 @@ sub determine_location_from_pc : Private { my ( $self, $c, $pc ) = @_; # check for something to search - $pc ||= $c->req->param('pc') || return -1; + $pc ||= $c->get_param('pc') || return; $c->stash->{pc} = $pc; # for template if ( $pc =~ /^(-?\d+(?:\.\d+)?)\s*,\s*(-?\d+(?:\.\d+)?)$/ ) { - $c->stash->{latitude} = $1; - $c->stash->{longitude} = $2; + ($c->stash->{latitude}, $c->stash->{longitude}) = + map { Utils::truncate_coordinate($_) } ($1, $2); return $c->forward( 'check_location' ); } if ( $c->cobrand->country eq 'GB' && $pc =~ /^([A-Z])([A-Z])([\d\s]{4,})$/i) { if (my $convert = gridref_to_latlon( $1, $2, $3 )) { - $c->stash->{latitude} = $convert->{latitude}; - $c->stash->{longitude} = $convert->{longitude}; + ($c->stash->{latitude}, $c->stash->{longitude}) = + map { Utils::truncate_coordinate($_) } + ($convert->{latitude}, $convert->{longitude}); return $c->forward( 'check_location' ); } } diff --git a/perllib/FixMyStreet/App/Controller/Moderate.pm b/perllib/FixMyStreet/App/Controller/Moderate.pm index ad293fbd7..08c4280a1 100644 --- a/perllib/FixMyStreet/App/Controller/Moderate.pm +++ b/perllib/FixMyStreet/App/Controller/Moderate.pm @@ -65,7 +65,7 @@ sub report : Chained('moderate') : PathPart('report') : CaptureArgs(1) { }); $c->stash->{problem} = $problem; $c->stash->{problem_original} = $original; - $c->stash->{moderation_reason} = $c->req->param('moderation_reason') // ''; + $c->stash->{moderation_reason} = $c->get_param('moderation_reason') // ''; } sub moderate_report : Chained('report') : PathPart('') : Args(0) { @@ -127,7 +127,7 @@ sub report_moderate_hide : Private { my $problem = $c->stash->{problem} or die; - if ($c->req->param('problem_hide')) { + if ($c->get_param('problem_hide')) { $problem->update({ state => 'hidden' }); @@ -145,9 +145,9 @@ sub report_moderate_title : Private { my $old_title = $problem->title; my $original_title = $original->title; - my $title = $c->req->param('problem_revert_title') ? + my $title = $c->get_param('problem_revert_title') ? $original_title - : $self->diff($original_title, $c->req->param('problem_title')); + : $self->diff($original_title, $c->get_param('problem_title')); if ($title ne $old_title) { $original->insert unless $original->in_storage; @@ -166,9 +166,9 @@ sub report_moderate_detail : Private { my $old_detail = $problem->detail; my $original_detail = $original->detail; - my $detail = $c->req->param('problem_revert_detail') ? + my $detail = $c->get_param('problem_revert_detail') ? $original_detail - : $self->diff($original_detail, $c->req->param('problem_detail')); + : $self->diff($original_detail, $c->get_param('problem_detail')); if ($detail ne $old_detail) { $original->insert unless $original->in_storage; @@ -184,7 +184,7 @@ sub report_moderate_anon : Private { my $problem = $c->stash->{problem} or die; my $original = $c->stash->{problem_original}; - my $show_user = $c->req->param('problem_show_name') ? 1 : 0; + my $show_user = $c->get_param('problem_show_name') ? 1 : 0; my $anonymous = $show_user ? 0 : 1; my $old_anonymous = $problem->anonymous ? 1 : 0; @@ -205,7 +205,7 @@ sub report_moderate_photo : Private { return unless $original->photo; - my $show_photo = $c->req->param('problem_show_photo') ? 1 : 0; + my $show_photo = $c->get_param('problem_show_photo') ? 1 : 0; my $old_show_photo = $problem->photo ? 1 : 0; if ($show_photo != $old_show_photo) { @@ -268,7 +268,7 @@ sub update_moderate_hide : Private { my $problem = $c->stash->{problem} or die; my $comment = $c->stash->{comment} or die; - if ($c->req->param('update_hide')) { + if ($c->get_param('update_hide')) { $comment->update({ state => 'hidden' }); $c->detach( 'update_moderate_audit', ['hide'] ); # break chain here. } @@ -284,9 +284,9 @@ sub update_moderate_detail : Private { my $old_detail = $comment->text; my $original_detail = $original->detail; - my $detail = $c->req->param('update_revert_detail') ? + my $detail = $c->get_param('update_revert_detail') ? $original_detail - : $self->diff($original_detail, $c->req->param('update_detail')); + : $self->diff($original_detail, $c->get_param('update_detail')); if ($detail ne $old_detail) { $original->insert unless $original->in_storage; @@ -303,7 +303,7 @@ sub update_moderate_anon : Private { my $comment = $c->stash->{comment} or die; my $original = $c->stash->{comment_original}; - my $show_user = $c->req->param('update_show_name') ? 1 : 0; + my $show_user = $c->get_param('update_show_name') ? 1 : 0; my $anonymous = $show_user ? 0 : 1; my $old_anonymous = $comment->anonymous ? 1 : 0; @@ -324,7 +324,7 @@ sub update_moderate_photo : Private { return unless $original->photo; - my $show_photo = $c->req->param('update_show_photo') ? 1 : 0; + my $show_photo = $c->get_param('update_show_photo') ? 1 : 0; my $old_show_photo = $comment->photo ? 1 : 0; if ($show_photo != $old_show_photo) { diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm index bbef1f8d8..83d5f7adb 100644 --- a/perllib/FixMyStreet/App/Controller/My.pm +++ b/perllib/FixMyStreet/App/Controller/My.pm @@ -25,20 +25,29 @@ sub my : Path : Args(0) { $c->detach( '/auth/redirect' ) unless $c->user; - my $p_page = $c->req->params->{p} || 1; - my $u_page = $c->req->params->{u} || 1; + my $p_page = $c->get_param('p') || 1; + my $u_page = $c->get_param('u') || 1; + + $c->forward( '/reports/stash_report_filter_status' ); my $pins = []; my $problems = {}; + my $states = $c->stash->{filter_problem_states}; my $params = { - state => [ FixMyStreet::DB::Result::Problem->visible_states() ], + state => [ keys %$states ], }; $params = { %{ $c->cobrand->problems_clause }, %$params } if $c->cobrand->problems_clause; + my $category = $c->get_param('filter_category'); + if ( $category ) { + $params->{category} = $category; + $c->stash->{filter_category} = $category; + } + my $rs = $c->user->problems->search( $params, { order_by => { -desc => 'confirmed' }, rows => 50 @@ -55,6 +64,7 @@ sub my : Path : Args(0) { }; my $state = $problem->is_fixed ? 'fixed' : $problem->is_closed ? 'closed' : 'confirmed'; push @{ $problems->{$state} }, $problem; + push @{ $problems->{all} }, $problem; } $c->stash->{problems_pager} = $rs->pager; $c->stash->{problems} = $problems; @@ -71,6 +81,14 @@ sub my : Path : Args(0) { $c->stash->{updates} = \@updates; $c->stash->{updates_pager} = $rs->pager; + my @categories = $c->user->problems->search( undef, { + columns => [ 'category' ], + distinct => 1, + order_by => [ 'category' ], + } )->all; + @categories = map { $_->category } @categories; + $c->stash->{filter_categories} = \@categories; + $c->stash->{page} = 'my'; FixMyStreet::Map::display_map( $c, diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm index f3841acef..96066ca93 100644 --- a/perllib/FixMyStreet/App/Controller/Open311.pm +++ b/perllib/FixMyStreet/App/Controller/Open311.pm @@ -155,9 +155,9 @@ sub get_discovery : Private { sub get_services : Private { my ( $self, $c ) = @_; - my $jurisdiction_id = $c->req->param('jurisdiction_id') || ''; - my $lat = $c->req->param('lat') || ''; - my $lon = $c->req->param('long') || ''; + my $jurisdiction_id = $c->get_param('jurisdiction_id') || ''; + my $lat = $c->get_param('lat') || ''; + my $lon = $c->get_param('long') || ''; # Look up categories for this council or councils my $categories = $c->model('DB::Contact')->not_deleted; @@ -252,7 +252,12 @@ sub output_requests : Private { 'interface_used' => [ $problem->service ], # Not in Open311 v2 }; - if ( $c->cobrand->moniker ne 'zurich' ) { # XXX + if ( $c->cobrand->moniker eq 'zurich' ) { + $request->{service_notice} = [ + $problem->get_extra_metadata('public_response') + ]; + } + else { # FIXME Not according to Open311 v2 $request->{agency_responsible} = $problem->bodies; } @@ -304,7 +309,7 @@ sub get_requests : Private { $c->forward( 'is_jurisdiction_id_ok' ); - my $max_requests = $c->req->param('max_requests') || 0; + my $max_requests = $c->get_param('max_requests') || 0; # Only provide access to the published reports my $states = FixMyStreet::DB::Result::Problem->visible_states(); @@ -322,7 +327,7 @@ sub get_requests : Private { has_photo => [ '=', 'photo' ], ); for my $param (keys %rules) { - my $value = $c->req->param($param); + my $value = $c->get_param($param); next unless $value; my $op = $rules{$param}[0]; my $key = $rules{$param}[1]; @@ -361,12 +366,12 @@ sub get_requests : Private { $criteria->{$key} = { $op, $value }; } - if ( $c->req->param('start_date') and $c->req->param('end_date') ) { - $criteria->{confirmed} = [ '-and' => { '>=', $c->req->param('start_date') }, { '<', $c->req->param('end_date') } ]; - } elsif ( $c->req->param('start_date') ) { - $criteria->{confirmed} = { '>=', $c->req->param('start_date') }; - } elsif ( $c->req->param('end_date') ) { - $criteria->{confirmed} = { '<', $c->req->param('end_date') }; + if ( $c->get_param('start_date') and $c->get_param('end_date') ) { + $criteria->{confirmed} = [ '-and' => { '>=', $c->get_param('start_date') }, { '<', $c->get_param('end_date') } ]; + } elsif ( $c->get_param('start_date') ) { + $criteria->{confirmed} = { '>=', $c->get_param('start_date') }; + } elsif ( $c->get_param('end_date') ) { + $criteria->{confirmed} = { '<', $c->get_param('end_date') }; } if ('rss' eq $c->stash->{format}) { @@ -436,7 +441,7 @@ sub format_output : Private { sub is_jurisdiction_id_ok : Private { my ( $self, $c ) = @_; - unless (my $jurisdiction_id = $c->req->param('jurisdiction_id')) { + unless (my $jurisdiction_id = $c->get_param('jurisdiction_id')) { $c->detach( 'error', [ _('Missing jurisdiction_id') ] ); } } diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 09afabecf..a2ec7d4c8 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -8,6 +8,7 @@ use DateTime::Format::HTTP; use Digest::SHA qw(sha1_hex); use File::Path; use File::Slurp; +use Image::Size; use Path::Class; use if !$ENV{TRAVIS}, 'Image::Magick'; @@ -181,7 +182,11 @@ sub process_photo_upload : Private { my $photo_blob = eval { my $filename = $upload->tempname; my $out = `jhead -se -autorot $filename 2>&1`; - die _("Please upload a JPEG image only"."\n") if $out =~ /Not JPEG:/; + unless (defined $out) { + my ($w, $h, $err) = Image::Size::imgsize($filename); + die _("Please upload a JPEG image only") . "\n" if !defined $w || $err ne 'JPG'; + } + die _("Please upload a JPEG image only") . "\n" if $out && $out =~ /Not JPEG:/; my $photo = $upload->slurp; return $photo; }; @@ -221,7 +226,7 @@ sub process_photo_cache : Private { my ( $self, $c ) = @_; # get the fileid and make sure it is just a hex number - my $fileid = $c->req->param('upload_fileid') || ''; + my $fileid = $c->get_param('upload_fileid') || ''; $fileid =~ s{[^0-9a-f]}{}gi; return unless $fileid; diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index 46d6350d7..f9a08e408 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -67,9 +67,16 @@ token), or the mini own-report one (when we'll have a problem ID). sub submit : Path('submit') { my ( $self, $c ) = @_; - if ( $c->req->params->{token} ) { + if (my $token = $c->get_param('token')) { + if ($token eq '_test_') { + $c->stash->{been_fixed} = $c->get_param('been_fixed'); + $c->stash->{new_state} = $c->get_param('new_state'); + $c->stash->{template} = 'questionnaire/completed.html'; + return; + } $c->forward('submit_standard'); - } elsif ( $c->req->params->{problem} ) { + } elsif (my $p = $c->get_param('problem')) { + $c->detach('creator_fixed') if $p eq '_test_'; $c->forward('submit_creator_fixed'); } else { $c->detach( '/page_error_404_not_found' ); @@ -96,8 +103,8 @@ sub submit_creator_fixed : Private { my @errors; - $c->stash->{reported} = $c->req->params->{reported}; - $c->stash->{problem_id} = $c->req->params->{problem}; + $c->stash->{reported} = $c->get_param('reported'); + $c->stash->{problem_id} = $c->get_param('problem'); # should only be able to get to here if we are logged and we have a # problem @@ -106,6 +113,7 @@ sub submit_creator_fixed : Private { } my $problem = $c->cobrand->problems->find( { id => $c->stash->{problem_id} } ); + $c->stash->{problem} = $problem; # you should not be able to answer questionnaires about problems # that you've not submitted @@ -148,7 +156,7 @@ sub submit_creator_fixed : Private { sub submit_standard : Private { my ( $self, $c ) = @_; - $c->forward( '/tokens/load_questionnaire', [ $c->req->params->{token} ] ); + $c->forward( '/tokens/load_questionnaire', [ $c->get_param('token') ] ); $c->forward( 'check_questionnaire' ); $c->forward( 'process_questionnaire' ); @@ -224,7 +232,7 @@ sub submit_standard : Private { sub process_questionnaire : Private { my ( $self, $c ) = @_; - map { $c->stash->{$_} = $c->req->params->{$_} || '' } qw(been_fixed reported another update); + map { $c->stash->{$_} = $c->get_param($_) || '' } qw(been_fixed reported another update); # EHA questionnaires done for you if ($c->cobrand->moniker eq 'emptyhomes') { @@ -279,10 +287,6 @@ sub display : Private { my $problem = $c->stash->{questionnaire}->problem; - ( $c->stash->{short_latitude}, $c->stash->{short_longitude} ) = - map { Utils::truncate_coordinate($_) } - ( $problem->latitude, $problem->longitude ); - $c->stash->{updates} = [ $c->model('DB::Comment')->search( { problem_id => $problem->id, state => 'confirmed' }, { order_by => 'confirmed' } diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 88a49f6c9..7b001ee4c 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -24,7 +24,7 @@ Redirect to homepage unless C<id> parameter in query, in which case redirect to sub index : Path('') : Args(0) { my ( $self, $c ) = @_; - my $id = $c->req->param('id'); + my $id = $c->get_param('id'); my $uri = $id @@ -78,7 +78,7 @@ sub _display : Private { sub support : Path('support') : Args(0) { my ( $self, $c ) = @_; - my $id = $c->req->param('id'); + my $id = $c->get_param('id'); my $uri = $id @@ -151,6 +151,10 @@ sub load_updates : Private { @combined = map { $_->[1] } sort { $a->[0] <=> $b->[0] } @combined; $c->stash->{updates} = \@combined; + if ($c->sessionid && $c->flash->{alert_to_reporter}) { + $c->stash->{alert_to_reporter} = 1; + } + return 1; } @@ -159,18 +163,15 @@ sub format_problem_for_display : Private { my $problem = $c->stash->{problem}; - ( $c->stash->{short_latitude}, $c->stash->{short_longitude} ) = + ( $c->stash->{latitude}, $c->stash->{longitude} ) = map { Utils::truncate_coordinate($_) } ( $problem->latitude, $problem->longitude ); - unless ( $c->req->param('submit_update') ) { + unless ( $c->get_param('submit_update') ) { $c->stash->{add_alert} = 1; } $c->stash->{extra_name_info} = $problem->bodies_str && $problem->bodies_str eq '2482' ? 1 : 0; - if ( $c->sessionid && $c->flash->{created_report} ) { - $c->stash->{created_report} = $c->flash->{created_report}; - } $c->forward('generate_map_tags'); diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index ed5be4e99..b540a1961 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -74,7 +74,6 @@ partial =cut -use constant COUNCIL_ID_BARNET => 2489; use constant COUNCIL_ID_BROMLEY => 2482; sub report_new : Path : Args(0) { @@ -220,14 +219,22 @@ sub category_extras_ajax : Path('category_extras') : Args(0) { return 1; } $c->forward('setup_categories_and_bodies'); + $c->forward('check_for_category'); + my $category = $c->stash->{category}; my $category_extra = ''; - if ( $c->stash->{category_extras}->{ $c->req->param('category') } && @{ $c->stash->{category_extras}->{ $c->req->param('category') } } >= 1 ) { + my $generate; + if ( $c->stash->{category_extras}->{$category} && @{ $c->stash->{category_extras}->{$category} } >= 1 ) { $c->stash->{report_meta} = {}; - $c->stash->{report} = { category => $c->req->param('category') }; - $c->stash->{category_extras} = { $c->req->param('category' ) => $c->stash->{category_extras}->{ $c->req->param('category') } }; - - $category_extra= $c->render_fragment( 'report/new/category_extras.html'); + $c->stash->{category_extras} = { $category => $c->stash->{category_extras}->{$category} }; + $generate = 1; + } + if ($c->stash->{unresponsive}->{$category}) { + $generate = 1; + } + if ($generate) { + $c->stash->{report} = { category => $category }; + $category_extra = $c->render_fragment( 'report/new/category_extras.html'); } my $body = JSON->new->utf8(1)->encode( @@ -257,7 +264,7 @@ sub report_import : Path('/import') { $c->res->content_type('text/plain; charset=utf-8'); my %input = - map { $_ => $c->req->param($_) || '' } ( + map { $_ => $c->get_param($_) || '' } ( 'service', 'subject', 'detail', 'name', 'email', 'phone', 'easting', 'northing', 'lat', 'lon', 'id', 'phone_id', ); @@ -408,7 +415,7 @@ sub initialize_report : Private { # create a new one. Stick it on the stash. my $report = undef; - if ( my $partial = scalar $c->req->param('partial') ) { + if ( my $partial = $c->get_param('partial') ) { for (1) { # use as pseudo flow control @@ -462,15 +469,15 @@ sub initialize_report : Private { } - if ( $c->req->param('first_name') && $c->req->param('last_name') ) { - $c->stash->{first_name} = $c->req->param('first_name'); - $c->stash->{last_name} = $c->req->param('last_name'); + if ( $c->get_param('first_name') && $c->get_param('last_name') ) { + $c->stash->{first_name} = $c->get_param('first_name'); + $c->stash->{last_name} = $c->get_param('last_name'); - $c->req->param( 'name', sprintf( '%s %s', $c->req->param('first_name'), $c->req->param('last_name') ) ); + $c->set_param('name', sprintf( '%s %s', $c->get_param('first_name'), $c->get_param('last_name') )); } # Capture whether the map was used - $report->used_map( $c->req->param('skipped') ? 0 : 1 ); + $report->used_map( $c->get_param('skipped') ? 0 : 1 ); $c->stash->{report} = $report; @@ -524,8 +531,8 @@ sub determine_location_from_tile_click : Private { # Extract the data needed my ( $pin_tile_x, $pin_tile_y ) = $x_key =~ m{$param_key_regex}; - my $pin_x = $c->req->param($x_key); - my $pin_y = $c->req->param($y_key); + my $pin_x = $c->get_param($x_key); + my $pin_y = $c->get_param($y_key); # return if they are both 0 - this happens when you submit the form by # hitting enter and not using the button. It also happens if you click @@ -540,8 +547,8 @@ sub determine_location_from_tile_click : Private { ); # store it on the stash - $c->stash->{latitude} = $latitude; - $c->stash->{longitude} = $longitude; + ($c->stash->{latitude}, $c->stash->{longitude}) = + map { Utils::truncate_coordinate($_) } ($latitude, $longitude); # set a flag so that the form is not considered submitted. This will prevent # errors showing on the fields. @@ -604,6 +611,11 @@ sub setup_categories_and_bodies : Private { my %category_extras = (); # extra fields to fill in for open311 my %non_public_categories = (); # categories for which the reports are not public + $c->stash->{unresponsive} = {}; + + if (keys %bodies == 1 && $first_body->send_method && $first_body->send_method eq 'Refused') { + $c->stash->{unresponsive}{ALL} = $first_body->id; + } # FIXME - implement in cobrand if ( $c->cobrand->moniker eq 'emptyhomes' ) { @@ -624,18 +636,6 @@ sub setup_categories_and_bodies : Private { _('Empty public building - school, hospital, etc.') ); - } elsif ($first_area->{id} != COUNCIL_ID_BROMLEY - && $first_area->{id} != COUNCIL_ID_BARNET - && $first_area->{type} eq 'LBO') { - - $bodies_to_list{ $first_body->id } = 1; - my @local_categories; - @local_categories = sort keys %{ Utils::london_categories() }; - @category_options = ( - _('-- Pick a category --'), - @local_categories - ); - } else { # keysort does not appear to obey locale so use strcoll (see i18n.t) @@ -649,8 +649,12 @@ sub setup_categories_and_bodies : Private { unless ( $seen{$contact->category} ) { push @category_options, $contact->category; - $category_extras{ $contact->category } = $contact->extra - if $contact->extra; + my $metas = $contact->get_extra_fields; + $category_extras{ $contact->category } = $metas + if scalar @$metas; + + $c->stash->{unresponsive}{$contact->category} = $contact->body_id + if $contact->email =~ /^REFUSED$/i; $non_public_categories{ $contact->category } = 1 if $contact->non_public; } @@ -664,6 +668,9 @@ sub setup_categories_and_bodies : Private { } } + $c->cobrand->munge_category_list(\@category_options, \@contacts, \%category_extras) + if $c->cobrand->can('munge_category_list'); + if ($c->cobrand->can('hidden_categories')) { my %hidden_categories = map { $_ => 1 } $c->cobrand->hidden_categories; @@ -703,7 +710,7 @@ on the presence of the C<submit_problem> parameter. sub check_form_submitted : Private { my ( $self, $c ) = @_; return if $c->stash->{force_form_not_submitted}; - return $c->req->param('submit_problem') || ''; + return $c->get_param('submit_problem') || ''; } =head2 process_user @@ -718,7 +725,7 @@ sub process_user : Private { my $report = $c->stash->{report}; # Extract all the params to a hash to make them easier to work with - my %params = map { $_ => scalar $c->req->param($_) } + my %params = map { $_ => $c->get_param($_) } ( 'email', 'name', 'phone', 'password_register', 'fms_extra_title' ); my $user_title = Utils::trim_text( $params{fms_extra_title} ); @@ -750,7 +757,7 @@ sub process_user : Private { unless $report->user; # The user is trying to sign in. We only care about email from the params. - if ( $c->req->param('submit_sign_in') || $c->req->param('password_sign_in') ) { + if ( $c->get_param('submit_sign_in') || $c->get_param('password_sign_in') ) { unless ( $c->forward( '/auth/sign_in' ) ) { $c->stash->{field_errors}->{password} = _('There was a problem with your email/password combination. If you cannot remember your password, or do not have one, please fill in the ‘sign in by email’ section of the form.'); return 1; @@ -788,7 +795,7 @@ sub process_report : Private { # Extract all the params to a hash to make them easier to work with my %params = # - map { $_ => scalar $c->req->param($_) } # + map { $_ => $c->get_param($_) } ( 'title', 'detail', 'pc', # 'detail_size', 'detail_depth', @@ -851,15 +858,6 @@ sub process_report : Private { $report->extra( \%extra ); } - } elsif ($first_area->{id} != COUNCIL_ID_BROMLEY - && $first_area->{id} != COUNCIL_ID_BARNET - && $first_area->{type} eq 'LBO') { - - unless ( Utils::london_categories()->{ $report->category } ) { - $c->stash->{field_errors}->{category} = _('Please choose a category'); - } - $report->bodies_str( $first_body->id ); - } elsif ( $report->category ) { # FIXME All contacts were fetched in setup_categories_and_bodies, @@ -880,28 +878,34 @@ sub process_report : Private { return 1; } - # construct the bodies string: - # 'x,x' - x are body IDs that have this category - # 'x,x|y' - x are body IDs that have this category, y body IDs with *no* contact - my $body_string = join( ',', map { $_->body_id } @contacts ); - $body_string .= - '|' . join( ',', map { $_->id } @{ $c->stash->{missing_details_bodies} } ) - if $body_string && @{ $c->stash->{missing_details_bodies} }; - $report->bodies_str($body_string); + if ($c->stash->{unresponsive}{$report->category} || $c->stash->{unresponsive}{ALL}) { + # Unresponsive, don't try and send a report. + $report->bodies_str(-1); + } else { + # construct the bodies string: + # 'x,x' - x are body IDs that have this category + # 'x,x|y' - x are body IDs that have this category, y body IDs with *no* contact + my $body_string = join( ',', map { $_->body_id } @contacts ); + $body_string .= + '|' . join( ',', map { $_->id } @{ $c->stash->{missing_details_bodies} } ) + if $body_string && @{ $c->stash->{missing_details_bodies} }; + $report->bodies_str($body_string); + } - my @extra = (); - my $metas = $contacts[0]->extra; + my @extra; + # NB: we are only checking extras for the *first* retrieved contact. + my $metas = $contacts[0]->get_extra_fields(); foreach my $field ( @$metas ) { if ( lc( $field->{required} ) eq 'true' ) { - unless ( $c->request->param( $field->{code} ) ) { + unless ( $c->get_param($field->{code}) ) { $c->stash->{field_errors}->{ $field->{code} } = _('This information is required'); } } push @extra, { name => $field->{code}, description => $field->{description}, - value => $c->request->param( $field->{code} ) || '', + value => $c->get_param($field->{code}) || '', }; } @@ -913,7 +917,7 @@ sub process_report : Private { if ( @extra ) { $c->stash->{report_meta} = { map { $_->{name} => $_ } @extra }; - $report->extra( \@extra ); + $report->set_extra_fields( @extra ); } } elsif ( @{ $c->stash->{bodies_to_list} } ) { @@ -964,7 +968,7 @@ sub check_for_errors : Private { # We only want to validate the phone number web requests (where the # service parameter is blank) because previous versions of the mobile # apps don't validate the presence of a phone number. - if ( ! $c->req->param('phone') and ! $c->req->param('service') ) { + if ( ! $c->get_param('phone') and ! $c->get_param('service') ) { $field_errors{phone} = _("This information is required"); } } @@ -974,7 +978,7 @@ sub check_for_errors : Private { # if they're got the login details wrong when signing in then # we don't care about the name field even though it's validated # by the user object - if ( $c->req->param('submit_sign_in') and $field_errors{password} ) { + if ( $c->get_param('submit_sign_in') and $field_errors{password} ) { delete $field_errors{name}; } @@ -1060,9 +1064,9 @@ sub save_user_and_report : Private { $report->bodies_str( undef ) if $report->bodies_str eq '-1'; # if there is a Message Manager message ID, pass it back to the client view - if ($c->cobrand->moniker eq 'fixmybarangay' && $c->req->param('external_source_id')=~/^\d+$/) { - $c->stash->{external_source_id} = $c->req->param('external_source_id'); - $report->external_source_id( $c->req->param('external_source_id') ); + if ($c->cobrand->moniker eq 'fixmybarangay' && $c->get_param('external_source_id') =~ /^\d+$/) { + $c->stash->{external_source_id} = $c->get_param('external_source_id'); + $report->external_source_id( $c->get_param('external_source_id') ); $report->external_source( $c->config->{MESSAGE_MANAGER_URL} ) ; } @@ -1090,10 +1094,6 @@ sub generate_map : Private { my $latitude = $c->stash->{latitude}; my $longitude = $c->stash->{longitude}; - ( $c->stash->{short_latitude}, $c->stash->{short_longitude} ) = - map { Utils::truncate_coordinate($_) } - ( $c->stash->{latitude}, $c->stash->{longitude} ); - # Don't do anything if the user skipped the map if ( $c->stash->{report}->used_map ) { $c->stash->{page} = 'new'; @@ -1116,7 +1116,7 @@ sub generate_map : Private { sub check_for_category : Private { my ( $self, $c ) = @_; - $c->stash->{category} = $c->req->param('category'); + $c->stash->{category} = $c->get_param('category'); return 1; } @@ -1136,23 +1136,10 @@ sub redirect_or_confirm_creation : Private { if ( $report->confirmed ) { # Subscribe problem reporter to email updates $c->forward( 'create_reporter_alert' ); - my $report_uri; - - if ( $c->cobrand->moniker eq 'fixmybarangay' && $c->user->from_body && $c->stash->{external_source_id}) { - $report_uri = $c->uri_for( '/report', $report->id, undef, { external_source_id => $c->stash->{external_source_id} } ); - } elsif ( $c->cobrand->never_confirm_reports && $report->non_public ) { - $c->log->info( 'cobrand was set to always confirm reports and report was non public, success page showed'); - $c->stash->{template} = 'report_created.html'; - return 1; - } else { - $report_uri = $c->cobrand->base_url_for_report( $report ) . $report->url; - } - $c->log->info($report->user->id . ' was logged in, redirecting to /report/' . $report->id); - if ( $c->sessionid ) { - $c->flash->{created_report} = 'loggedin'; - } - $c->res->redirect($report_uri); - $c->detach; + $c->log->info($report->user->id . ' was logged in, showing confirmation page for ' . $report->id); + $c->stash->{created_report} = 'loggedin'; + $c->stash->{template} = 'tokens/confirm_problem.html'; + return 1; } # otherwise create a confirm token and email it to them. @@ -1199,7 +1186,7 @@ sub redirect_to_around : Private { my ( $self, $c ) = @_; my $params = { - pc => ( $c->stash->{pc} || $c->req->param('pc') || '' ), + pc => ( $c->stash->{pc} || $c->get_param('pc') || '' ), lat => $c->stash->{latitude}, lon => $c->stash->{longitude}, }; diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index b97420238..17aec2113 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -20,12 +20,12 @@ Creates an update to a report sub report_update : Path : Args(0) { my ( $self, $c ) = @_; - $c->forward( '/report/load_problem_or_display_error', [ $c->req->param('id') ] ); + $c->forward( '/report/load_problem_or_display_error', [ $c->get_param('id') ] ); $c->forward('process_update'); $c->forward('process_user'); $c->forward('/photo/process_photo'); $c->forward('check_for_errors') - or $c->go( '/report/display', [ $c->req->param('id') ] ); + or $c->go( '/report/display', [ $c->get_param('id') ] ); $c->forward('save_update'); $c->forward('redirect_or_confirm_creation'); @@ -76,7 +76,7 @@ sub update_problem : Private { $problem->state('confirmed'); } - if ( $c->cobrand->can_support_problems && $c->user && $c->user->from_body && $c->req->param('external_source_id') ) { + if ( $c->cobrand->can_support_problems && $c->user && $c->user->from_body && $c->get_param('external_source_id') ) { $problem->interest_count( \'interest_count + 1' ); } @@ -106,9 +106,9 @@ sub process_user : Private { if ( $c->user_exists ) { my $user = $c->user->obj; - my $name = scalar $c->req->param('name'); + my $name = $c->get_param('name'); $user->name( Utils::trim_text( $name ) ) if $name; - my $title = scalar $c->req->param('fms_extra_title'); + my $title = $c->get_param('fms_extra_title'); if ( $title ) { $c->log->debug( 'user exists and title is ' . $title ); $user->title( Utils::trim_text( $title ) ); @@ -118,7 +118,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($_) } + my %params = map { $_ => $c->get_param($_) } ( 'rznvy', 'name', 'password_register', 'fms_extra_title' ); # cleanup the email address @@ -129,7 +129,7 @@ sub process_user : Private { unless $update->user; # The user is trying to sign in. We only care about email from the params. - if ( $c->req->param('submit_sign_in') || $c->req->param('password_sign_in') ) { + if ( $c->get_param('submit_sign_in') || $c->get_param('password_sign_in') ) { unless ( $c->forward( '/auth/sign_in', [ $email ] ) ) { $c->stash->{field_errors}->{password} = _('There was a problem with your email/password combination. If you cannot remember your password, or do not have one, please fill in the ‘sign in by email’ section of the form.'); return 1; @@ -164,23 +164,23 @@ want to move adding these elsewhere sub process_update : Private { my ( $self, $c ) = @_; - if ( $c->req->param('first_name' ) && $c->req->param('last_name' ) ) { - my $first_name = $c->req->param('first_name'); - my $last_name = $c->req->param('last_name'); - $c->req->param('name', sprintf( '%s %s', $first_name, $last_name ) ); + if ( $c->get_param('first_name') && $c->get_param('last_name') ) { + my $first_name = $c->get_param('first_name'); + my $last_name = $c->get_param('last_name'); + $c->set_param('name', sprintf( '%s %s', $first_name, $last_name )); $c->stash->{first_name} = $first_name; $c->stash->{last_name} = $last_name; } my %params = - map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed', 'state', 'reopen' ); + map { $_ => $c->get_param($_) } ( 'update', 'name', 'fixed', 'state', 'reopen' ); $params{update} = Utils::cleanup_text( $params{update}, { allow_multiline => 1 } ); my $name = Utils::trim_text( $params{name} ); - my $anonymous = $c->req->param('may_show_name') ? 0 : 1; + my $anonymous = $c->get_param('may_show_name') ? 0 : 1; $params{reopen} = 0 unless $c->user && $c->user->id == $c->stash->{problem}->user->id; @@ -225,10 +225,10 @@ sub process_update : Private { # TODO Use extra here as it is used on reports. $c->cobrand->process_extras( $c, $update->problem->bodies_str, \@extra ); - if ( $c->req->param('fms_extra_title') ) { + if ( $c->get_param('fms_extra_title') ) { my %extras = (); - $extras{title} = $c->req->param('fms_extra_title'); - $extras{email_alerts_requested} = $c->req->param('add_alert'); + $extras{title} = $c->get_param('fms_extra_title'); + $extras{email_alerts_requested} = $c->get_param('add_alert'); $update->extra( \%extras ); } @@ -239,10 +239,10 @@ sub process_update : Private { $update->extra( $extra ); } - $c->log->debug( 'name is ' . $c->req->param('name') ); + $c->log->debug( 'name is ' . $c->get_param('name') ); - $c->stash->{update} = $update; - $c->stash->{add_alert} = $c->req->param('add_alert'); + $c->stash->{update} = $update; + $c->stash->{add_alert} = $c->get_param('add_alert'); return 1; } @@ -259,11 +259,11 @@ sub check_for_errors : Private { my ( $self, $c ) = @_; # they have to be an authority user to update the state - if ( $c->req->param('state') ) { + if ( $c->get_param('state') ) { my $error = 0; $error = 1 unless $c->user && $c->user->belongs_to_body( $c->stash->{update}->problem->bodies_str ); - my $state = $c->req->param('state'); + my $state = $c->get_param('state'); $state = 'fixed - council' if $state eq 'fixed'; $error = 1 unless ( grep { $state eq $_ } ( FixMyStreet::DB::Result::Problem->council_states() ) ); @@ -376,11 +376,8 @@ sub redirect_or_confirm_creation : Private { if ( $update->confirmed ) { $c->forward( 'update_problem' ); $c->forward( 'signup_for_alerts' ); - - my $report_uri = $c->cobrand->base_url_for_report( $update->problem ) . $update->problem->url; - $c->flash->{comment_created} = 1; - $c->res->redirect($report_uri); - $c->detach; + $c->stash->{template} = 'tokens/confirm_update.html'; + return 1; } # otherwise create a confirm token and email it to them. @@ -391,7 +388,7 @@ sub redirect_or_confirm_creation : Private { data => { %$data, id => $update->id, - add_alert => ( $c->req->param('add_alert') ? 1 : 0 ), + add_alert => ( $c->get_param('add_alert') ? 1 : 0 ), } } ); @@ -423,8 +420,8 @@ happen before calling this. sub signup_for_alerts : Private { my ( $self, $c ) = @_; + my $update = $c->stash->{update}; if ( $c->stash->{add_alert} ) { - my $update = $c->stash->{update}; my $options = { user => $update->user, alert_type => 'new_updates', @@ -441,7 +438,7 @@ sub signup_for_alerts : Private { } $alert->confirm(); - } elsif ( $c->user && ( my $alert = $c->user->alert_for_problem($c->stash->{update}->problem_id) ) ) { + } elsif ( my $alert = $update->user->alert_for_problem($update->problem_id) ) { $alert->disable(); } diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 352c47da8..6b0d516a6 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -109,6 +109,7 @@ sub ward : Path : Args(2) { $c->forward( 'ward_check', [ $ward ] ) if $ward; $c->forward( 'check_canonical_url', [ $body ] ); + $c->forward( 'stash_report_filter_status' ); $c->forward( 'load_and_group_problems' ); my $body_short = $c->cobrand->short_name( $c->stash->{body} ); @@ -120,6 +121,15 @@ sub ward : Path : Args(2) { $c->stash->{stats} = $c->cobrand->get_report_stats(); + my @categories = $c->stash->{body}->contacts->search( undef, { + columns => [ 'category' ], + distinct => 1, + order_by => [ 'category' ], + } )->all; + @categories = map { $_->category } @categories; + $c->stash->{filter_categories} = \@categories; + $c->stash->{filter_category} = $c->get_param('filter_category'); + my $pins = $c->stash->{pins}; $c->stash->{page} = 'reports'; # So the map knows to make clickable pins @@ -373,13 +383,15 @@ sub check_canonical_url : Private { sub load_and_group_problems : Private { my ( $self, $c ) = @_; - my $page = $c->req->params->{p} || 1; - my $type = $c->req->params->{t} || 'all'; - my $category = $c->req->params->{c} || ''; + my $page = $c->get_param('p') || 1; + # NB: If 't' is specified, it will override 'status'. + my $type = $c->get_param('t') || 'all'; + my $category = $c->get_param('c') || $c->get_param('filter_category') || ''; + my $states = $c->stash->{filter_problem_states}; my $where = { non_public => 0, - state => [ FixMyStreet::DB::Result::Problem->visible_states() ] + state => [ keys %$states ] }; my $not_open = [ FixMyStreet::DB::Result::Problem::fixed_states(), FixMyStreet::DB::Result::Problem::closed_states() ]; @@ -430,7 +442,7 @@ sub load_and_group_problems : Private { my $problems = $c->cobrand->problems->search( $where, { - order_by => { -desc => 'lastupdate' }, + order_by => $c->cobrand->reports_ordering, rows => $c->cobrand->reports_per_page, } )->page( $page ); @@ -485,6 +497,26 @@ sub redirect_body : Private { $c->res->redirect( $c->uri_for($url, $c->req->params ) ); } +sub stash_report_filter_status : Private { + my ( $self, $c ) = @_; + + my $status = $c->get_param('status') || $c->cobrand->on_map_default_status; + if ( $status eq 'all' ) { + $c->stash->{filter_status} = 'all'; + $c->stash->{filter_problem_states} = FixMyStreet::DB::Result::Problem->visible_states(); + } elsif ( $status eq 'open' ) { + $c->stash->{filter_status} = 'open'; + $c->stash->{filter_problem_states} = FixMyStreet::DB::Result::Problem->open_states(); + } elsif ( $status eq 'fixed' ) { + $c->stash->{filter_status} = 'fixed'; + $c->stash->{filter_problem_states} = FixMyStreet::DB::Result::Problem->fixed_states(); + } else { + $c->stash->{filter_status} = $c->cobrand->on_map_default_status; + } + + return 1; +} + sub add_row { my ( $c, $problem, $body, $problems, $pins ) = @_; push @{$problems->{$body}}, $problem; diff --git a/perllib/FixMyStreet/App/Controller/Root.pm b/perllib/FixMyStreet/App/Controller/Root.pm index 769a147bf..16f4aa491 100644 --- a/perllib/FixMyStreet/App/Controller/Root.pm +++ b/perllib/FixMyStreet/App/Controller/Root.pm @@ -47,7 +47,7 @@ sub index : Path : Args(0) { my %old_params = (); foreach my $key (@old_param_keys) { - my $val = $c->req->param($key); + my $val = $c->get_param($key); next unless $val; $old_params{$key} = $val; } diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index cbeddce85..7aafc99ff 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -350,7 +350,7 @@ sub get_query_parameters : Private { $d = '' unless $d && $d =~ /^\d+$/; $c->stash->{distance} = $d; - my $state = $c->req->param('state') || 'all'; + my $state = $c->get_param('state') || 'all'; $state = 'all' unless $state =~ /^(all|open|fixed)$/; $c->stash->{state_qs} = "?state=$state" unless $state eq 'all'; diff --git a/perllib/FixMyStreet/App/Controller/Static.pm b/perllib/FixMyStreet/App/Controller/Static.pm index 8cd82b68e..d91a07fea 100755 --- a/perllib/FixMyStreet/App/Controller/Static.pm +++ b/perllib/FixMyStreet/App/Controller/Static.pm @@ -61,6 +61,25 @@ sub council : Global : Args(0) { my ( $self, $c ) = @_; } +sub unresponsive : Global : Args(0) { + my ( $self, $c ) = @_; + my $body = $c->stash->{body} = $c->model('DB::Body')->find({ id => $c->get_param('body') }) + or $c->detach( '/page_error_404_not_found' ); + + $c->stash->{category} = $c->get_param('category'); + + # If the whole body isn't set to refused, we need to check the contacts + if (!$body->send_method || $body->send_method ne 'Refused') { + my @contacts = $c->model('DB::Contact')->not_deleted->search( { body_id => $body->id } )->all; + my $any_unresponsive = 0; + foreach my $contact (@contacts) { + $any_unresponsive = 1 if $contact->email =~ /^REFUSED$/i; + } + + $c->detach( '/page_error_404_not_found' ) unless $any_unresponsive; + } +} + __PACKAGE__->meta->make_immutable; 1; diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm index 44cb2429d..21c269502 100644 --- a/perllib/FixMyStreet/App/Controller/Tokens.pm +++ b/perllib/FixMyStreet/App/Controller/Tokens.pm @@ -28,22 +28,32 @@ problem but are not logged in. sub confirm_problem : Path('/P') { my ( $self, $c, $token_code ) = @_; + if ($token_code eq '_test_') { + $c->stash->{report} = { + id => 123, + title => 'Title of Report', + bodies_str => 'True', + url => '/report/123', + }; + return; + } + my $auth_token = $c->forward( 'load_auth_token', [ $token_code, 'problem' ] ); # Load the problem my $data = $auth_token->data; - my $problem_id = ref $data ? $data->{id} : $data; + $data = { id => $data } unless ref $data; + + my $problem_id = $data->{id}; # Look at all problems, not just cobrand, in case am approving something we don't actually show my $problem = $c->model('DB::Problem')->find( { id => $problem_id } ) || $c->detach('token_error'); - $c->stash->{problem} = $problem; + $c->stash->{report} = $problem; - if ( $problem->state eq 'unconfirmed' && $auth_token->created < DateTime->now->subtract( months => 1 ) ) { - $c->stash->{template} = 'errors/generic.html'; - $c->stash->{message} = _("I'm afraid we couldn't validate that token, as the report was made too long ago."); - return; - } + $c->detach('token_too_old') + if $problem->state eq 'unconfirmed' + && $auth_token->created < DateTime->now->subtract( months => 1 ); # check that this email or domain are not the cause of abuse. If so hide it. if ( $problem->is_from_abuser ) { @@ -56,14 +66,12 @@ sub confirm_problem : Path('/P') { # For Zurich, email confirmation simply sets a flag, it does not change the # problem state, log in, or anything else if ($c->cobrand->moniker eq 'zurich') { - my $extra = { %{ $problem->extra || {} } }; - $extra->{email_confirmed} = 1; + $problem->set_extra_metadata( email_confirmed => 1 ); $problem->update( { - extra => $extra, confirmed => \'ms_current_timestamp()', } ); - if ( ref($data) && ( $data->{name} || $data->{password} ) ) { + if ( $data->{name} || $data->{password} ) { $problem->user->name( $data->{name} ) if $data->{name}; $problem->user->phone( $data->{phone} ) if $data->{phone}; $problem->user->update; @@ -72,22 +80,26 @@ sub confirm_problem : Path('/P') { return 1; } - # We have a problem - confirm it if needed! - my $old_state = $problem->state; + if ($problem->state ne 'unconfirmed') { + my $report_uri = $c->cobrand->base_url_for_report( $problem ) . $problem->url; + $c->res->redirect($report_uri); + return; + } + + # We have an unconfirmed problem $problem->update( { state => 'confirmed', confirmed => \'ms_current_timestamp()', lastupdate => \'ms_current_timestamp()', } - ) if $problem->state eq 'unconfirmed'; + ); # Subscribe problem reporter to email updates - $c->stash->{report} = $c->stash->{problem}; $c->forward( '/report/new/create_reporter_alert' ); # log the problem creation user in to the site - if ( ref($data) && ( $data->{name} || $data->{password} ) ) { + if ( $data->{name} || $data->{password} ) { $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}; @@ -97,11 +109,6 @@ sub confirm_problem : Path('/P') { $c->authenticate( { email => $problem->user->email }, 'no_password' ); $c->set_session_cookie_expire(0); - if ( FixMyStreet::DB::Result::Problem->visible_states()->{$old_state} ) { - my $report_uri = $c->cobrand->base_url_for_report( $problem ) . $problem->url; - $c->res->redirect($report_uri); - } - $c->stash->{created_report} = 'fromemail'; return 1; } @@ -135,23 +142,34 @@ alert but are not logged in. sub confirm_alert : Path('/A') { my ( $self, $c, $token_code ) = @_; + if ($token_code eq '_test_') { + $c->stash->{confirm_type} = $c->get_param('confirm_type'); + return; + } + my $auth_token = $c->forward( 'load_auth_token', [ $token_code, 'alert' ] ); - # Load the problem + # Load the alert my $alert_id = $auth_token->data->{id}; $c->stash->{confirm_type} = $auth_token->data->{type}; my $alert = $c->model('DB::Alert')->find( { id => $alert_id } ) || $c->detach('token_error'); $c->stash->{alert} = $alert; + $c->detach('token_too_old') + if $c->stash->{confirm_type} ne 'unsubscribe' + && $auth_token->created < DateTime->now->subtract( months => 1 ); + # check that this email or domain are not the cause of abuse. If so hide it. if ( $alert->is_from_abuser ) { $c->stash->{template} = 'tokens/abuse.html'; return; } - $c->authenticate( { email => $alert->user->email }, 'no_password' ); - $c->set_session_cookie_expire(0); + if (!$alert->confirmed && $c->stash->{confirm_type} ne 'unsubscribe') { + $c->authenticate( { email => $alert->user->email }, 'no_password' ); + $c->set_session_cookie_expire(0); + } $c->forward('/alert/confirm'); @@ -170,10 +188,20 @@ update but are not logged in. sub confirm_update : Path('/C') { my ( $self, $c, $token_code ) = @_; + if ($token_code eq '_test_') { + $c->stash->{problem} = { + id => 123, + title => 'Title of Report', + bodies_str => 'True', + url => '/report/123', + }; + return; + } + my $auth_token = $c->forward( 'load_auth_token', [ $token_code, 'comment' ] ); - # Load the problem + # Load the update my $data = $auth_token->data; my $comment_id = $data->{id}; $c->stash->{add_alert} = $data->{add_alert}; @@ -182,26 +210,32 @@ sub confirm_update : Path('/C') { || $c->detach('token_error'); $c->stash->{update} = $comment; + $c->detach('token_too_old') + if $comment->state ne 'confirmed' + && $auth_token->created < DateTime->now->subtract( months => 1 ); + # check that this email or domain are not the cause of abuse. If so hide it. if ( $comment->is_from_abuser ) { $c->stash->{template} = 'tokens/abuse.html'; return; } + if ( $comment->state ne 'unconfirmed' ) { + my $report_uri = $c->cobrand->base_url_for_report( $comment->problem ) . $comment->problem->url; + $c->res->redirect($report_uri); + return; + } + if ( $data->{name} || $data->{password} ) { $comment->user->name( $data->{name} ) if $data->{name}; $comment->user->password( $data->{password}, 1 ) if $data->{password}; $comment->user->update; } + $c->authenticate( { email => $comment->user->email }, 'no_password' ); $c->set_session_cookie_expire(0); - if ( $comment->confirmed ) { - my $report_uri = $c->cobrand->base_url_for_report( $comment->problem ) . $comment->problem->url; - $c->res->redirect($report_uri); - } else { - $c->forward('/report/update/confirm'); - } + $c->forward('/report/update/confirm'); return 1; } @@ -212,6 +246,7 @@ sub load_questionnaire : Private { my $auth_token = $c->forward( 'load_auth_token', [ $token_code, 'questionnaire' ] ); $c->stash->{id} = $auth_token->data; $c->stash->{token} = $token_code; + $c->stash->{token_obj} = $auth_token; my $questionnaire = $c->model('DB::Questionnaire')->find( { id => $c->stash->{id} }, @@ -225,11 +260,43 @@ sub questionnaire : Path('/Q') : Args(1) { my ( $self, $c, $token_code ) = @_; $c->forward( 'load_questionnaire', [ $token_code ] ); - $c->authenticate( { email => $c->stash->{questionnaire}->problem->user->email }, 'no_password' ); - $c->set_session_cookie_expire(0); + $c->detach('token_too_old') if $c->stash->{token_obj}->created < DateTime->now->subtract( months => 1 ); + + my $questionnaire = $c->stash->{questionnaire}; + if (!$questionnaire->whenanswered) { + $c->authenticate( { email => $questionnaire->problem->user->email }, 'no_password' ); + $c->set_session_cookie_expire(0); + } $c->forward( '/questionnaire/show' ); } +=head2 alert_to_reporter + + /R/([0-9A-Za-z]{16,18}).*$ + +A link in an update alert to a problem reporter - show the "reopen report" +tickbox but don't log the person in. + +=cut + +sub alert_to_reporter : Path('/R') { + my ( $self, $c, $token_code ) = @_; + + my $auth_token = + $c->forward( 'load_auth_token', [ $token_code, 'alert_to_reporter' ] ); + my $data = $auth_token->data; + + my $problem_id = $data->{id}; + my $problem = $c->model('DB::Problem')->find( { id => $problem_id } ) + || $c->detach('token_error'); + + $c->detach('token_too_old') if $auth_token->created < DateTime->now->subtract( months => 1 ); + + $c->flash->{alert_to_reporter} = 1; + my $report_uri = $c->cobrand->base_url_for_report( $problem ) . $problem->url; + $c->res->redirect($report_uri); +} + =head2 load_auth_token my $auth_token = @@ -276,6 +343,12 @@ sub token_error : Private { $c->stash->{template} = 'tokens/error.html'; } +sub token_too_old : Private { + my ( $self, $c ) = @_; + $c->stash->{token_not_found} = 1; + $c->stash->{template} = 'auth/token.html'; +} + __PACKAGE__->meta->make_immutable; 1; |