aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller/Report/New.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report/New.pm')
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm122
1 files changed, 66 insertions, 56 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 9194f5318..687e54fbe 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -89,7 +89,7 @@ sub report_new : Path : Args(0) {
# create a problem from the submitted details
$c->stash->{template} = "report/new/fill_in_details.html";
- $c->forward('setup_categories_and_councils');
+ $c->forward('setup_categories_and_bodies');
$c->forward('generate_map');
$c->forward('check_for_category');
@@ -119,7 +119,7 @@ sub report_new_ajax : Path('mobile') : Args(0) {
return 1;
}
- $c->forward('setup_categories_and_councils');
+ $c->forward('setup_categories_and_bodies');
$c->forward('process_user');
$c->forward('process_report');
$c->forward('/photo/process_photo');
@@ -147,7 +147,7 @@ sub report_new_ajax : Path('mobile') : Args(0) {
} else {
$c->stash->{token_url} = $c->uri_for_email( '/P', $token->token );
$c->send_email( 'problem-confirm.txt', {
- to => [ [ $report->user->email, $report->name ] ],
+ to => [ $report->name ? [ $report->user->email, $report->name ] : $report->user->email ],
} );
$c->stash->{ json_response } = { success => 1 };
}
@@ -180,7 +180,7 @@ sub report_form_ajax : Path('ajax') : Args(0) {
return;
}
- $c->forward('setup_categories_and_councils');
+ $c->forward('setup_categories_and_bodies');
# render templates to get the html
my $category = $c->render_fragment( 'report/new/category.html');
@@ -216,7 +216,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) {
$c->res->body($body);
return 1;
}
- $c->forward('setup_categories_and_councils');
+ $c->forward('setup_categories_and_bodies');
my $category_extra = '';
if ( $c->stash->{category_extras}->{ $c->req->param('category') } && @{ $c->stash->{category_extras}->{ $c->req->param('category') } } >= 1 ) {
@@ -569,27 +569,34 @@ sub determine_location_from_report : Private {
return;
}
-=head2 setup_categories_and_councils
+=head2 setup_categories_and_bodies
-Look up categories for this council or councils
+Look up categories for the relevant body or bodies.
=cut
-sub setup_categories_and_councils : Private {
+sub setup_categories_and_bodies : Private {
my ( $self, $c ) = @_;
- my $all_councils = $c->stash->{all_councils};
- my $first_council = ( values %$all_councils )[0];
+ my $all_areas = $c->stash->{all_areas};
+ my $first_area = ( values %$all_areas )[0];
+
+ my @bodies = $c->model('DB::Body')->search(
+ { 'body_areas.area_id' => [ keys %$all_areas ] },
+ { join => 'body_areas' }
+ )->all;
+ my %bodies = map { $_->id => $_ } @bodies;
+ my $first_body = ( values %bodies )[0];
my @contacts #
= $c #
->model('DB::Contact') #
->not_deleted #
- ->search( { area_id => [ keys %$all_councils ] } ) #
+ ->search( { body_id => [ keys %bodies ] } )
->all;
# variables to populate
- my %area_ids_to_list = (); # Areas with categories assigned
+ my %bodies_to_list = (); # Bodies with categories assigned
my @category_options = (); # categories to show
my $category_label = undef; # what to call them
my %category_extras = (); # extra fields to fill in for open311
@@ -599,9 +606,9 @@ sub setup_categories_and_councils : Private {
# FIXME - implement in cobrand
if ( $c->cobrand->moniker eq 'emptyhomes' ) {
- # add all areas found to the list
+ # add all bodies found to the list
foreach (@contacts) {
- $area_ids_to_list{ $_->area_id } = 1;
+ $bodies_to_list{ $_->body_id } = 1;
}
# set our own categories
@@ -616,11 +623,11 @@ sub setup_categories_and_councils : Private {
);
$category_label = _('Property type:');
- } elsif ($first_council->{id} != COUNCIL_ID_BROMLEY && $first_council->{type} eq 'LBO') {
+ } elsif ($first_area->{id} != COUNCIL_ID_BROMLEY && $first_area->{type} eq 'LBO') {
- $area_ids_to_list{ $first_council->{id} } = 1;
+ $bodies_to_list{ $first_body->id } = 1;
my @local_categories;
- if ($first_council->{id} == COUNCIL_ID_BARNET) {
+ if ($first_area->{id} == COUNCIL_ID_BARNET) {
@local_categories = sort keys %{ Utils::barnet_categories() }
} else {
@local_categories = sort keys %{ Utils::london_categories() }
@@ -639,7 +646,7 @@ sub setup_categories_and_councils : Private {
my %seen;
foreach my $contact (@contacts) {
- $area_ids_to_list{ $contact->area_id } = 1;
+ $bodies_to_list{ $contact->body_id } = 1;
unless ( $seen{$contact->category} ) {
push @category_options, $contact->category;
@@ -661,24 +668,21 @@ sub setup_categories_and_councils : Private {
}
# put results onto stash for display
- $c->stash->{area_ids_to_list} = [ keys %area_ids_to_list ];
+ $c->stash->{bodies} = \%bodies;
+ $c->stash->{all_body_names} = [ map { $_->name } values %bodies ];
+ $c->stash->{bodies_to_list} = [ keys %bodies_to_list ];
$c->stash->{category_label} = $category_label;
$c->stash->{category_options} = \@category_options;
$c->stash->{category_extras} = \%category_extras;
$c->stash->{non_public_categories} = \%non_public_categories;
$c->stash->{category_extras_json} = encode_json \%category_extras;
- $c->stash->{extra_name_info} = $first_council->{id} == COUNCIL_ID_BROMLEY ? 1 : 0;
-
- my @missing_details_councils =
- grep { !$area_ids_to_list{$_} } #
- keys %$all_councils;
+ $c->stash->{extra_name_info} = $first_area->{id} == COUNCIL_ID_BROMLEY ? 1 : 0;
- my @missing_details_council_names =
- map { $all_councils->{$_}->{name} } #
- @missing_details_councils;
+ my @missing_details_bodies = grep { !$bodies_to_list{$_->id} } values %bodies;
+ my @missing_details_body_names = map { $_->name } @missing_details_bodies;
- $c->stash->{missing_details_councils} = \@missing_details_councils;
- $c->stash->{missing_details_council_names} = \@missing_details_council_names;
+ $c->stash->{missing_details_bodies} = \@missing_details_bodies;
+ $c->stash->{missing_details_body_names} = \@missing_details_body_names;
}
=head2 check_form_submitted
@@ -820,60 +824,62 @@ sub process_report : Private {
$report->subcategory( $params{subcategory} );
- my $areas = $c->stash->{all_areas};
+ my $areas = $c->stash->{all_areas_mapit};
$report->areas( ',' . join( ',', sort keys %$areas ) . ',' );
# From earlier in the process.
- my $councils = $c->stash->{all_councils};
- my $first_council = ( values %$councils )[0];
+ $areas = $c->stash->{all_areas};
+ my $bodies = $c->stash->{bodies};
+ my $first_area = ( values %$areas )[0];
+ my $first_body = ( values %$bodies )[0];
if ( $c->cobrand->moniker eq 'emptyhomes' ) {
- $councils = join( ',', @{ $c->stash->{area_ids_to_list} } ) || -1;
- $report->council( $councils );
+ $bodies = join( ',', @{ $c->stash->{bodies_to_list} } ) || -1;
+ $report->bodies_str( $bodies );
- } elsif ( $first_council->{id} == COUNCIL_ID_BARNET ) {
+ } elsif ( $first_area->{id} == COUNCIL_ID_BARNET ) {
unless ( exists Utils::barnet_categories()->{ $report->category } ) {
$c->stash->{field_errors}->{category} = _('Please choose a category');
}
- $report->council( $first_council->{id} );
+ $report->bodies_str( $first_body->id );
- } elsif ( $first_council->{id} != COUNCIL_ID_BROMLEY && $first_council->{type} eq 'LBO') {
+ } elsif ( $first_area->{id} != COUNCIL_ID_BROMLEY && $first_area->{type} eq 'LBO') {
unless ( Utils::london_categories()->{ $report->category } ) {
$c->stash->{field_errors}->{category} = _('Please choose a category');
}
- $report->council( $first_council->{id} );
+ $report->bodies_str( $first_body->id );
} elsif ( $report->category ) {
- # FIXME All contacts were fetched in setup_categories_and_councils,
+ # FIXME All contacts were fetched in setup_categories_and_bodies,
# so can this DB call also be avoided?
my @contacts = $c-> #
model('DB::Contact') #
->not_deleted #
->search(
{
- area_id => [ keys %$councils ],
+ body_id => [ keys %$bodies ],
category => $report->category
}
)->all;
unless ( @contacts ) {
$c->stash->{field_errors}->{category} = _('Please choose a category');
- $report->council( -1 );
+ $report->bodies_str( -1 );
return 1;
}
- # construct the council string:
- # 'x,x' - x are council IDs that have this category
- # 'x,x|y,y' - x are council IDs that have this category, y council IDs with *no* contact
- my $council_string = join( ',', map { $_->area_id } @contacts );
- $council_string .=
- '|' . join( ',', @{ $c->stash->{missing_details_councils} } )
- if $council_string && @{ $c->stash->{missing_details_councils} };
- $report->council($council_string);
+ # 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;
@@ -895,13 +901,13 @@ sub process_report : Private {
$report->non_public( 1 );
}
- $c->cobrand->process_extras( $c, $contacts[0]->area_id, \@extra );
+ $c->cobrand->process_extras( $c, $contacts[0]->body_id, \@extra );
if ( @extra ) {
$c->stash->{report_meta} = { map { $_->{name} => $_ } @extra };
$report->extra( \@extra );
}
- } elsif ( @{ $c->stash->{area_ids_to_list} } ) {
+ } elsif ( @{ $c->stash->{bodies_to_list} } ) {
# There was an area with categories, but we've not been given one. Bail.
$c->stash->{field_errors}->{category} = _('Please choose a category');
@@ -910,7 +916,7 @@ sub process_report : Private {
# If we're here, we've been submitted somewhere
# where we have no contact information at all.
- $report->council( -1 );
+ $report->bodies_str( -1 );
}
@@ -944,6 +950,8 @@ sub check_for_errors : Private {
if ( $c->cobrand->moniker eq 'zurich' ) {
delete $field_errors{title};
delete $field_errors{name};
+ my $report = $c->stash->{report};
+ $report->title( Utils::cleanup_text( substr($report->detail, 0, 25) ) );
}
# FIXME: need to check for required bromley fields here
@@ -1006,8 +1014,10 @@ sub save_user_and_report : Private {
$c->log->info($report->user->id . ' created for this report');
}
elsif ( $c->user && $report->user->id == $c->user->id ) {
+ # Logged in and matches, so instantly confirm (except Zurich, with no confirmation)
$report->user->update();
- $report->confirm;
+ $report->confirm
+ unless $c->cobrand->moniker eq 'zurich';
$c->log->info($report->user->id . ' is logged in for this report');
}
else {
@@ -1032,7 +1042,7 @@ sub save_user_and_report : Private {
$report->category( _('Other') ) unless $report->category;
# Set unknown to DB unknown
- $report->council( undef ) if $report->council eq '-1';
+ $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+$/) {
@@ -1113,7 +1123,7 @@ sub redirect_or_confirm_creation : Private {
$c->forward( 'create_reporter_alert' );
my $report_uri;
- if ( $c->cobrand->moniker eq 'fixmybarangay' && $c->user->from_council && $c->stash->{external_source_id}) {
+ 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');
@@ -1138,7 +1148,7 @@ sub redirect_or_confirm_creation : Private {
} );
$c->stash->{token_url} = $c->uri_for_email( '/P', $token->token );
$c->send_email( 'problem-confirm.txt', {
- to => [ [ $report->user->email, $report->name ] ],
+ to => [ $report->name ? [ $report->user->email, $report->name ] : $report->user->email ],
} );
# tell user that they've been sent an email