diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report/New.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 125 |
1 files changed, 30 insertions, 95 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 6d22a0556..37ff1ae76 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -5,7 +5,6 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } use FixMyStreet::Geocode; -use Digest::SHA1 qw(sha1_hex); use Encode; use Image::Magick; use List::MoreUtils qw(uniq); @@ -99,7 +98,7 @@ sub report_new : Path : Args(0) { return unless $c->forward('check_form_submitted'); $c->forward('process_user'); $c->forward('process_report'); - $c->forward('process_photo'); + $c->forward('/photo/process_photo'); return unless $c->forward('check_for_errors'); $c->forward('save_user_and_report'); $c->forward('redirect_or_confirm_creation'); @@ -126,12 +125,16 @@ sub report_form_ajax : Path('ajax') : Args(0) { my $category = $c->render_fragment( 'report/new/category.html'); my $councils_text = $c->render_fragment( 'report/new/councils_text.html'); my $has_open311 = keys %{ $c->stash->{category_extras} }; + my $extra_name_info = $c->stash->{extra_name_info} + ? $c->render_fragment('report/new/extra_name.html') + : ''; my $body = JSON->new->utf8(1)->encode( { councils_text => $councils_text, category => $category, has_open311 => $has_open311, + extra_name_info => $extra_name_info, } ); @@ -156,7 +159,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) { $c->forward('setup_categories_and_councils'); my $category_extra = ''; - if ( $c->stash->{category_extras}->{ $c->req->param('category') } ) { + if ( $c->stash->{category_extras}->{ $c->req->param('category') } && @{ $c->stash->{category_extras}->{ $c->req->param('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') } }; @@ -211,7 +214,7 @@ sub report_import : Path('/import') { } # handle the photo upload - $c->forward( 'process_photo_upload' ); + $c->forward( '/photo/process_photo_upload' ); my $fileid = $c->stash->{upload_fileid}; if ( my $error = $c->stash->{photo_error} ) { push @errors, $error; @@ -396,6 +399,13 @@ 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'); + + $c->req->param( 'name', sprintf( '%s %s', $c->req->param('first_name'), $c->req->param('last_name') ) ); + } + # Capture whether the map was used $report->used_map( $c->req->param('skipped') ? 0 : 1 ); @@ -544,7 +554,7 @@ sub setup_categories_and_councils : Private { ); $category_label = _('Property type:'); - } elsif ($first_council->{type} eq 'LBO') { + } elsif ($first_council->{id} != 2482 && $first_council->{type} eq 'LBO') { $area_ids_to_list{ $first_council->{id} } = 1; my @local_categories; @@ -557,7 +567,7 @@ sub setup_categories_and_councils : Private { _('-- Pick a category --'), @local_categories ); - $category_label = _('Category:'); + $category_label = _('Category'); } else { @@ -587,7 +597,7 @@ sub setup_categories_and_councils : Private { if (@category_options) { @category_options = ( _('-- Pick a category --'), @category_options, _('Other') ); - $category_label = _('Category:'); + $category_label = _('Category'); } } @@ -597,6 +607,7 @@ sub setup_categories_and_councils : Private { $c->stash->{category_options} = \@category_options; $c->stash->{category_extras} = \%category_extras; $c->stash->{category_extras_json} = encode_json \%category_extras; + $c->stash->{extra_name_info} = $first_council->{id} == 2482 ? 1 : 0; my @missing_details_councils = grep { !$area_ids_to_list{$_} } # @@ -639,9 +650,10 @@ sub process_user : Private { # The user is already signed in if ( $c->user_exists ) { my $user = $c->user->obj; - my %params = map { $_ => scalar $c->req->param($_) } ( 'name', 'phone' ); + my %params = map { $_ => scalar $c->req->param($_) } ( 'name', 'phone', 'fms_extra_title' ); $user->name( Utils::trim_text( $params{name} ) ) if $params{name}; $user->phone( Utils::trim_text( $params{phone} ) ); + $user->title( Utils::trim_text( $params{fms_extra_title} ) ); $report->user( $user ); $report->name( $user->name ); return 1; @@ -649,7 +661,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($_) } - ( 'email', 'name', 'phone', 'password_register' ); + ( 'email', 'name', 'phone', 'password_register', 'fms_extra_title' ); # cleanup the email address my $email = $params{email} ? lc $params{email} : ''; @@ -677,6 +689,7 @@ sub process_user : Private { $report->user->phone( Utils::trim_text( $params{phone} ) ); $report->user->password( Utils::trim_text( $params{password_register} ) ) if $params{password_register}; + $report->user->title( Utils::trim_text( $params{fms_extra_title} ) ); $report->name( Utils::trim_text( $params{name} ) ); return 1; @@ -748,7 +761,7 @@ sub process_report : Private { } $report->council( $first_council->{id} ); - } elsif ( $first_council->{type} eq 'LBO') { + } elsif ( $first_council->{id} != 2482 && $first_council->{type} eq 'LBO') { unless ( Utils::london_categories()->{ $report->category } ) { $c->stash->{field_errors}->{category} = _('Please choose a category'); @@ -800,6 +813,8 @@ sub process_report : Private { }; } + $c->cobrand->process_extras( $c, \@contacts, \@extra ); + if ( @extra ) { $c->stash->{report_meta} = \@extra; $report->extra( \@extra ); @@ -828,91 +843,6 @@ sub process_report : Private { return 1; } -=head2 process_photo - -Handle the photo - either checking and storing it after an upload or retrieving -it from the cache. - -Store any error message onto 'photo_error' in stash. -=cut - -sub process_photo : Private { - my ( $self, $c ) = @_; - - return - $c->forward('process_photo_upload') - || $c->forward('process_photo_cache') - || 1; # always return true -} - -sub process_photo_upload : Private { - my ( $self, $c ) = @_; - - # check for upload or return - my $upload = $c->req->upload('photo') - || return; - - # check that the photo is a jpeg - my $ct = $upload->type; - unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' ) { - $c->stash->{photo_error} = _('Please upload a JPEG image only'); - return; - } - - # get the photo into a variable - my $photo_blob = eval { - my $filename = $upload->tempname; - my $out = `jhead -se -autorot $filename`; - my $photo = $upload->slurp; - return $photo; - }; - if ( my $error = $@ ) { - my $format = _( -"That image doesn't appear to have uploaded correctly (%s), please try again." - ); - $c->stash->{photo_error} = sprintf( $format, $error ); - return; - } - - # we have an image we can use - save it to the upload dir for storage - my $cache_dir = dir( $c->config->{UPLOAD_DIR} ); - $cache_dir->mkpath; - unless ( -d $cache_dir && -w $cache_dir ) { - warn "Can't find/write to photo cache directory '$cache_dir'"; - return; - } - - my $fileid = sha1_hex($photo_blob); - $upload->copy_to( file($cache_dir, $fileid . '.jpeg') ); - - # stick the hash on the stash, so don't have to reupload in case of error - $c->stash->{upload_fileid} = $fileid; - - return 1; -} - -=head2 process_photo_cache - -Look for the upload_fileid parameter and check it matches a file on disk. If it -does return true and put fileid on stash, otherwise false. - -=cut - -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') || ''; - $fileid =~ s{[^0-9a-f]}{}gi; - return unless $fileid; - - my $file = file( $c->config->{UPLOAD_DIR}, "$fileid.jpeg" ); - return unless -e $file; - - $c->stash->{upload_fileid} = $fileid; - return 1; -} - =head2 check_for_errors Examine the user and the report for errors. If found put them on stash and @@ -931,6 +861,8 @@ sub check_for_errors : Private { %{ $c->stash->{report}->check_for_errors }, ); + # FIXME: need to check for required bromley fields here + # 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 @@ -972,10 +904,12 @@ sub save_user_and_report : Private { name => $report->user->name, phone => $report->user->phone, password => $report->user->password, + title => $report->user->title, }; $report->user->name( undef ); $report->user->phone( undef ); $report->user->password( '', 1 ); + $report->user->title( undef ); $report->user->insert(); $c->log->info($report->user->id . ' created for this report'); } @@ -991,6 +925,7 @@ sub save_user_and_report : Private { name => $report->user->name, phone => $report->user->phone, password => $report->user->password, + title => $report->user->title, }; $report->user->discard_changes(); $c->log->info($report->user->id . ' exists, but is not logged in for this report'); |