diff options
Diffstat (limited to 'perllib/FixMyStreet/App')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 27 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Alert.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Contact.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 152 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/My.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 91 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Questionnaire.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 30 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 125 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 39 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Root.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Tokens.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Model/EmailSend.pm | 2 |
14 files changed, 376 insertions, 115 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 198acade6..998cb83a8 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -8,6 +8,8 @@ use POSIX qw(strftime strcoll); use Digest::MD5 qw(md5_hex); use mySociety::EmailUtil qw(is_valid_email); +use FixMyStreet::SendReport; + =head1 NAME FixMyStreet::App::Controller::Admin- Catalyst Controller @@ -338,7 +340,7 @@ sub update_contacts : Private { } elsif ( $posted eq 'open311' ) { $c->forward('check_token'); - my %params = map { $_ => $c->req->param($_) } qw/open311_id endpoint jurisdiction api_key area_id/; + my %params = map { $_ => $c->req->param($_) || '' } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments suppress_alerts comment_user_id/; if ( $params{open311_id} ) { my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } ); @@ -346,6 +348,10 @@ sub update_contacts : Private { $conf->endpoint( $params{endpoint} ); $conf->jurisdiction( $params{jurisdiction} ); $conf->api_key( $params{api_key} ); + $conf->send_method( $params{send_method} ); + $conf->send_comments( $params{send_comments} || 0); + $conf->suppress_alerts( $params{suppress_alerts} || 0); + $conf->comment_user_id( $params{comment_user_id} || undef ); $conf->update(); @@ -356,6 +362,10 @@ sub update_contacts : Private { $conf->endpoint( $params{endpoint} ); $conf->jurisdiction( $params{jurisdiction} ); $conf->api_key( $params{api_key} ); + $conf->send_method( $params{send_method} ); + $conf->send_comments( $params{send_comments} || 0); + $conf->suppress_alerts( $params{suppress_alerts} || 0); + $conf->comment_user_id( $params{comment_user_id} || undef ); $conf->insert(); @@ -378,6 +388,9 @@ sub display_contacts : Private { $c->stash->{contacts} = $contacts; + my @methods = map { $_ =~ s/FixMyStreet::SendReport:://; $_ } keys %{ FixMyStreet::SendReport->get_senders }; + $c->stash->{send_methods} = \@methods; + my $open311 = $c->model('DB::Open311Conf')->search( { area_id => $area_id } ); @@ -492,7 +505,7 @@ sub search_reports : Path('search_reports') { 'me.id' => $search_n, 'user.email' => { ilike => $like_search }, 'me.name' => { ilike => $like_search }, - title => { ilike => $like_search }, + 'me.title' => { ilike => $like_search }, detail => { ilike => $like_search }, council => { like => $like_search }, cobrand_data => { like => $like_search }, @@ -571,8 +584,7 @@ sub report_edit : Path('report_edit') : Args(1) { } )->first; - $c->detach( '/page_error_404_not_found', - [ _('The requested URL was not found on this server.') ] ) + $c->detach( '/page_error_404_not_found' ) unless $problem; $c->stash->{problem} = $problem; @@ -734,8 +746,7 @@ sub update_edit : Path('update_edit') : Args(1) { } )->first; - $c->detach( '/page_error_404_not_found', - [ _('The requested URL was not found on this server.') ] ) + $c->detach( '/page_error_404_not_found' ) unless $update; $c->forward('get_token'); @@ -1068,7 +1079,7 @@ sub check_token : Private { my ( $self, $c ) = @_; if ( !$c->req->param('token') || $c->req->param('token' ) ne $c->stash->{token} ) { - $c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] ); + $c->detach( '/page_error_404_not_found' ); } return 1; @@ -1238,7 +1249,7 @@ sub check_page_allowed : Private { $page ||= 'summary'; if ( !grep { $_ eq $page } keys %{ $c->stash->{allowed_pages} } ) { - $c->detach( '/page_error_404_not_found', [ _('The requested URL was not found on this server.') ] ); + $c->detach( '/page_error_404_not_found' ); } return 1; diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 2698c6ac0..6e9ae819c 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -191,7 +191,11 @@ sub create_alert : Private { $alert->insert(); } - $alert->confirm() if $c->user && $c->user->id == $alert->user->id; + if ( $c->user && $c->user->id == $alert->user->id ) { + $alert->confirm(); + } else { + $alert->confirmed(0); + } $c->stash->{alert} = $alert; } @@ -470,6 +474,7 @@ sub add_recent_photos : Private { { $c->stash->{photos} = $c->cobrand->recent_photos( + 'alert', $num_photos, $c->stash->{latitude}, $c->stash->{longitude}, @@ -477,7 +482,7 @@ sub add_recent_photos : Private { ); } else { - $c->stash->{photos} = $c->cobrand->recent_photos($num_photos); + $c->stash->{photos} = $c->cobrand->recent_photos('alert', $num_photos); } return 1; diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index fc6df20c3..f2bb23350 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -186,10 +186,11 @@ sub display_location : Private { @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 : $_; + my $colour = $c->cobrand->pin_colour( $p, 'around' ); { latitude => $p->latitude, longitude => $p->longitude, - colour => 'yellow', # $p->is_fixed ? 'green' : 'red', + colour => $colour, id => $p->id, title => $p->title, } diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm index f28d37989..91580f05a 100644 --- a/perllib/FixMyStreet/App/Controller/Contact.pm +++ b/perllib/FixMyStreet/App/Controller/Contact.pm @@ -183,7 +183,7 @@ generally required to stash sub setup_request : Private { my ( $self, $c ) = @_; - $c->stash->{contact_email} = $c->cobrand->contact_email; + $c->stash->{contact_email} = $c->cobrand->contact_email( 'contact' ); $c->stash->{contact_email} =~ s/\@/@/; for my $param (qw/em subject message/) { @@ -205,7 +205,7 @@ Sends the email sub send_email : Private { my ( $self, $c ) = @_; - my $recipient = $c->cobrand->contact_email(); + my $recipient = $c->cobrand->contact_email( 'contact' ); my $recipient_name = $c->cobrand->contact_name(); $c->stash->{host} = $c->req->header('HOST'); diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm new file mode 100644 index 000000000..0273e0eda --- /dev/null +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -0,0 +1,152 @@ +package FixMyStreet::App::Controller::Dashboard; +use Moose; +use namespace::autoclean; + +use DateTime; + +BEGIN { extends 'Catalyst::Controller'; } + +=head1 NAME + +FixMyStreet::App::Controller::Dashboard - Catalyst Controller + +=head1 DESCRIPTION + +Catalyst Controller. + +=head1 METHODS + +=cut + +=head2 check_page_allowed + +Checks if we can view this page, and if not redirect to 404. + +=cut + +sub check_page_allowed : Private { + my ( $self, $c ) = @_; + + $c->detach( '/auth/redirect' ) unless $c->user_exists; + + $c->detach( '/page_error_404_not_found' ) + unless $c->user_exists && $c->user->from_council; + + return $c->user->from_council; +} + +=head2 index + +Show the dashboard table. + +=cut + +sub index : Path : Args(0) { + my ( $self, $c ) = @_; + + my $council = $c->forward('check_page_allowed'); + + # Set up the data for the dropdowns + + my $children = mySociety::MaPit::call('area/children', $council, + type => $mySociety::VotingArea::council_child_types, + ); + $c->stash->{children} = $children; + + # XXX Hmm, this is probably the best way to go + $c->stash->{all_councils} = { $council => { id => $council } }; + $c->forward( '/report/new/setup_categories_and_councils' ); + + # 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->{q_state} = $c->req->param('state'); + + my %where = ( + council => $council, # XXX This will break in a two tier council. Restriction needs looking at... + 'problem.state' => [ FixMyStreet::DB::Result::Problem->visible_states() ], + ); + $where{areas} = { 'like', '%,' . $c->stash->{ward} . ',%' } + if $c->stash->{ward}; + $where{category} = $c->stash->{category} + if $c->stash->{category}; + if ( $c->stash->{q_state} eq 'fixed' ) { + $where{'problem.state'} = [ FixMyStreet::DB::Result::Problem->fixed_states() ]; + } elsif ( $c->stash->{q_state} ) { + $where{'problem.state'} = $c->stash->{q_state} + } + + my %counts; + my $t = DateTime->today; + + $counts{wtd} = $c->forward( 'updates_search', [ { + %where, + 'me.confirmed' => { '>=', $t->subtract( days => $t->dow - 1 ) + } } ] ); + + $counts{week} = $c->forward( 'updates_search', [ { + %where, + 'me.confirmed' => { '>=', DateTime->now->subtract( weeks => 1 ) + } } ] ); + + $counts{weeks} = $c->forward( 'updates_search', [ { + %where, + 'me.confirmed' => { '>=', DateTime->now->subtract( weeks => 4 ) + } } ] ); + + $counts{ytd} = $c->forward( 'updates_search', [ { + %where, + 'me.confirmed' => { '>=', DateTime->today->set( day => 1, month => 1 ) + } } ] ); + + $c->stash->{problems} = \%counts; +} + +sub updates_search : Private { + my ( $self, $c, $params ) = @_; + + my $comments = $c->model('DB::Comment')->search( + $params, + { + group_by => [ 'problem_state' ], + select => [ 'problem_state', { count => 'me.id' } ], + as => [ qw/state state_count/ ], + join => 'problem' + } + ); + + my %counts = + map { ($_->state||'-') => $_->get_column('state_count') } $comments->all; + %counts = + map { $_ => $counts{$_} || 0 } + ('confirmed', 'investigating', 'in progress', 'closed', 'fixed - council', + 'fixed - user', 'fixed', 'unconfirmed', 'hidden', + 'partial', 'planned'); + + $counts{fixed_user} = $c->model('DB::Comment')->search( + { %$params, mark_fixed => 1 }, { join => 'problem' } + )->count; + + $params->{state} = $params->{'problem.state'}; + delete $params->{'problem.state'}; + $counts{total} = $c->cobrand->problems->search( $params )->count; + + return \%counts; +} + +=head1 AUTHOR + +Matthew Somerville + +=head1 LICENSE + +Copyright (c) 2012 UK Citizens Online Democracy. All rights reserved. +Licensed under the Affero GPL. + +=cut + +__PACKAGE__->meta->make_immutable; + +1; + diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm index 3de83b265..c00264315 100644 --- a/perllib/FixMyStreet/App/Controller/My.pm +++ b/perllib/FixMyStreet/App/Controller/My.pm @@ -48,7 +48,7 @@ sub my : Path : Args(0) { push @$pins, { latitude => $problem->latitude, longitude => $problem->longitude, - colour => $problem->is_fixed ? 'green' : 'red', + colour => $c->cobrand->pin_colour( $problem, 'my' ), id => $problem->id, title => $problem->title, }; diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index 5d5832b08..a6717fc33 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -5,6 +5,7 @@ use namespace::autoclean; BEGIN {extends 'Catalyst::Controller'; } use DateTime::Format::HTTP; +use Digest::SHA1 qw(sha1_hex); use Path::Class; =head1 NAME @@ -136,6 +137,96 @@ sub _crop { return $blobs[0]; } +=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; + $ct =~ s/x-citrix-//; # Thanks, Citrix + # Had a report of a JPEG from an Android 2.1 coming through as a byte stream + unless ( $ct eq 'image/jpeg' || $ct eq 'image/pjpeg' || $ct eq 'application/octet-stream' ) { + $c->log->info('Bad photo tried to upload, type=' . $ct); + $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 2>&1`; + die _("Please upload a JPEG image only"."\n") if $out =~ /Not JPEG:/; + 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; +} + + =head1 AUTHOR Struan Donald diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index 6ed7ddd9d..6aa4f7604 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -244,7 +244,7 @@ sub process_questionnaire : Private { push @errors, _('Please provide some explanation as to why you\'re reopening this report') if $c->stash->{been_fixed} eq 'No' && $c->stash->{problem}->is_fixed() && !$c->stash->{update}; - $c->forward('/report/new/process_photo'); + $c->forward('/photo/process_photo'); push @errors, $c->stash->{photo_error} if $c->stash->{photo_error}; @@ -294,7 +294,7 @@ sub display : Private { pins => [ { latitude => $problem->latitude, longitude => $problem->longitude, - colour => $problem->is_fixed() ? 'green' : 'red', + colour => $c->cobrand->pin_colour( $problem, 'questionnaire' ), } ], ); } diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index afe180c29..cca625bd5 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -153,6 +153,36 @@ sub generate_map_tags : Private { return 1; } +sub delete :Local :Args(1) { + my ( $self, $c, $id ) = @_; + + $c->forward( 'load_problem_or_display_error', [ $id ] ); + my $p = $c->stash->{problem}; + + my $uri = $c->uri_for( '/report', $id ); + + return $c->res->redirect($uri) unless $c->user_exists; + + my $council = $c->user->obj->from_council; + return $c->res->redirect($uri) unless $council; + + my %councils = map { $_ => 1 } @{$p->councils}; + return $c->res->redirect($uri) unless $councils{$council}; + + $p->state('hidden'); + $p->lastupdate( \'ms_current_timestamp()' ); + $p->update; + + $c->model('DB::AdminLog')->create( { + admin_user => $c->user->email, + object_type => 'problem', + action => 'state_change', + object_id => $id, + } ); + + return $c->res->redirect($uri); +} + __PACKAGE__->meta->make_immutable; 1; 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'); diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 15444f556..5b0dad170 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -23,7 +23,7 @@ sub report_update : Path : Args(0) { $c->forward( '/report/load_problem_or_display_error', [ $c->req->param('id') ] ); $c->forward('process_update'); $c->forward('process_user'); - $c->forward('/report/new/process_photo'); + $c->forward('/photo/process_photo'); $c->forward('check_for_errors') or $c->go( '/report/display', [ $c->req->param('id') ] ); @@ -104,13 +104,18 @@ sub process_user : Private { my $user = $c->user->obj; my $name = scalar $c->req->param('name'); $user->name( Utils::trim_text( $name ) ) if $name; + my $title = scalar $c->req->param('fms_extra_title'); + if ( $title ) { + $c->log->debug( 'user exists and title is ' . $title ); + $user->title( Utils::trim_text( $title ) ); + } $update->user( $user ); return 1; } # Extract all the params to a hash to make them easier to work with my %params = map { $_ => scalar $c->req->param($_) } - ( 'rznvy', 'name', 'password_register' ); + ( 'rznvy', 'name', 'password_register', 'fms_extra_title' ); # cleanup the email address my $email = $params{rznvy} ? lc $params{rznvy} : ''; @@ -136,6 +141,8 @@ sub process_user : Private { if $params{name}; $update->user->password( Utils::trim_text( $params{password_register} ) ) if $params{password_register}; + $update->user->title( Utils::trim_text( $params{fms_extra_title} ) ) + if $params{fms_extra_title}; return 1; } @@ -153,6 +160,15 @@ 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 ) ); + + $c->stash->{first_name} = $first_name; + $c->stash->{last_name} = $last_name; + } + my %params = map { $_ => scalar $c->req->param($_) } ( 'update', 'name', 'fixed', 'state', 'reopen' ); @@ -185,6 +201,24 @@ sub process_update : Private { $update->problem_state( $params{state} ); } + if ( $c->req->param('fms_extra_title') ) { + my %extras = (); + $extras{title} = $c->req->param('fms_extra_title'); + $extras{email_alerts_required} = $c->req->param('add_alert'); + $update->extra( \%extras ); + + $c->stash->{fms_extra_title} = $c->req->param('fms_extra_title'); + } + + if ( $c->stash->{ first_name } && $c->stash->{ last_name } ) { + my $extra = $update->extra || {}; + $extra->{first_name} = $c->stash->{ first_name }; + $extra->{last_name} = $c->stash->{ last_name }; + $update->extra( $extra ); + } + + $c->log->debug( 'name is ' . $c->req->param('name') ); + $c->stash->{update} = $update; $c->stash->{add_alert} = $c->req->param('add_alert'); @@ -268,6 +302,7 @@ sub save_update : Private { } elsif ( $c->user && $c->user->id == $update->user->id ) { # Logged in and same user, so can confirm update straight away + $c->log->debug( 'user exists' ); $update->user->update; $update->confirm; } else { diff --git a/perllib/FixMyStreet/App/Controller/Root.pm b/perllib/FixMyStreet/App/Controller/Root.pm index 9cdf0b523..7f7d7f5fd 100644 --- a/perllib/FixMyStreet/App/Controller/Root.pm +++ b/perllib/FixMyStreet/App/Controller/Root.pm @@ -68,7 +68,7 @@ Forward to the standard 404 error page sub default : Path { my ( $self, $c ) = @_; - $c->detach('/page_error_404_not_found'); + $c->detach('/page_error_404_not_found', []); } =head2 page_error_404_not_found, page_error_410_gone diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm index b974f94e6..1434838f2 100644 --- a/perllib/FixMyStreet/App/Controller/Tokens.pm +++ b/perllib/FixMyStreet/App/Controller/Tokens.pm @@ -71,6 +71,7 @@ sub confirm_problem : Path('/P') { $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}; + $problem->user->title( $data->{title} ) if $data->{title}; $problem->user->update; } $c->authenticate( { email => $problem->user->email }, 'no_password' ); diff --git a/perllib/FixMyStreet/App/Model/EmailSend.pm b/perllib/FixMyStreet/App/Model/EmailSend.pm index 73086c65f..761856bde 100644 --- a/perllib/FixMyStreet/App/Model/EmailSend.pm +++ b/perllib/FixMyStreet/App/Model/EmailSend.pm @@ -35,7 +35,7 @@ elsif ( my $smtp_host = FixMyStreet->config('SMTP_SMARTHOST') ) { # Email::Send::SMTP $args = { - mailer => 'SMTP', + mailer => 'FixMyStreet::EmailSend', mailer_args => [ Host => $smtp_host ], }; } |