diff options
author | Marius Halden <marius.h@lden.org> | 2015-08-26 13:43:10 +0200 |
---|---|---|
committer | Marius Halden <marius.h@lden.org> | 2015-08-26 13:43:10 +0200 |
commit | cc0acdd34052e79f3df368ac1f524de31df19a1b (patch) | |
tree | 505f561b5f16c5b78f07514e8c2b2bdc18fef51d /perllib/FixMyStreet/App/Controller/Report | |
parent | 1c5c685d0b0904e7ddc6e764e58e8fae08632d1d (diff) | |
parent | 6b84622fb7d58531baa7943abdcc7620999c34ee (diff) |
Merge tag 'v1.6.1' into fiksgatami-dev
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 157 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 55 |
2 files changed, 98 insertions, 114 deletions
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(); } |