diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 14 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Alert.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Council.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Location.pm | 43 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 3 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Questionnaire.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 32 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 15 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 13 |
13 files changed, 119 insertions, 33 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index ef299d224..b53b6ab06 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -7,6 +7,7 @@ BEGIN { extends 'Catalyst::Controller'; } use POSIX qw(strftime strcoll); use Digest::MD5 qw(md5_hex); use mySociety::EmailUtil qw(is_valid_email); +use if !$ENV{TRAVIS}, 'Image::Magick'; use FixMyStreet::SendReport; @@ -305,6 +306,10 @@ sub update_contacts : Private { $contact->note( $c->req->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') ); if ( $contact->in_storage ) { $c->stash->{updated} = _('Values updated'); @@ -341,7 +346,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 send_method send_comments suppress_alerts comment_user_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 devolved/; if ( $params{open311_id} ) { my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } ); @@ -353,6 +358,7 @@ sub update_contacts : Private { $conf->send_comments( $params{send_comments} || 0); $conf->suppress_alerts( $params{suppress_alerts} || 0); $conf->comment_user_id( $params{comment_user_id} || undef ); + $conf->can_be_devolved( $params{devolved} || 0 ); $conf->update(); @@ -367,6 +373,7 @@ sub update_contacts : Private { $conf->send_comments( $params{send_comments} || 0); $conf->suppress_alerts( $params{suppress_alerts} || 0); $conf->comment_user_id( $params{comment_user_id} || undef ); + $conf->can_be_devolved( $params{devolved} || 0 ); $conf->insert(); @@ -462,6 +469,9 @@ sub council_edit : Path('council_edit') : Args(2) { $c->stash->{history} = $history; + my @methods = map { $_ =~ s/FixMyStreet::SendReport:://; $_ } keys %{ FixMyStreet::SendReport->get_senders }; + $c->stash->{send_methods} = \@methods; + return 1; } @@ -652,7 +662,6 @@ sub report_edit : Path('report_edit') : Args(1) { || $flagged != $problem->flagged || $non_public != $problem->non_public ) { - warn "edited"; $edited = 1; } @@ -1281,7 +1290,6 @@ sub trim { sub _rotate_image { my ($photo, $direction) = @_; - use Image::Magick; my $image = Image::Magick->new; $image->BlobToImage($photo); my $err = $image->Rotate($direction); diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 4e5319a59..91ea61fbc 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -438,7 +438,7 @@ sub determine_location : Private { $c->detach('choose'); } - $c->go('index') if $c->stash->{location_error}; + $c->go('index'); } # truncate the lat,lon for nicer urls diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 3047b195c..f2bb23350 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -45,7 +45,7 @@ sub around_index : Path : Args(0) { || $c->forward('/location/determine_location_from_pc'); # Check to see if the spot is covered by a council - if not show an error. - return unless $c->forward('check_location_is_acceptable'); + return unless $c->cobrand->moniker eq 'fixmybarangay' || $c->forward('check_location_is_acceptable'); # If we have a partial - redirect to /report/new so that it can be # completed. @@ -204,6 +204,7 @@ sub display_location : Private { longitude => $short_longitude, clickable => 1, pins => \@pins, + area => $c->cobrand->areas_on_around, ); return 1; diff --git a/perllib/FixMyStreet/App/Controller/Council.pm b/perllib/FixMyStreet/App/Controller/Council.pm index a6ce533e4..cb9e78421 100644 --- a/perllib/FixMyStreet/App/Controller/Council.pm +++ b/perllib/FixMyStreet/App/Controller/Council.pm @@ -52,7 +52,6 @@ sub load_and_check_councils : Private { my $short_latitude = Utils::truncate_coordinate($latitude); my $short_longitude = Utils::truncate_coordinate($longitude); - # TODO: I think we want in_gb_locale around the MaPit line, needs testing my $all_councils; if ( $c->stash->{fetch_all_areas} ) { my %area_types = map { $_ => 1 } @$area_types; diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index e4266dc64..a5ba8ff07 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -96,7 +96,7 @@ sub index : Path : Args(0) { $c->stash->{council} = $council_detail; my $children = mySociety::MaPit::call('area/children', $council, - type => $mySociety::VotingArea::council_child_types, + type => $c->cobrand->area_types_children, ); $c->stash->{children} = $children; diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm index c3d754485..3e44cd748 100644 --- a/perllib/FixMyStreet/App/Controller/Location.pm +++ b/perllib/FixMyStreet/App/Controller/Location.pm @@ -64,6 +64,19 @@ sub determine_location_from_pc : Private { $pc ||= $c->req->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; + return $c->forward( 'check_location' ); + } + if ( $c->cobrand->country eq 'GB' && $pc =~ /^([A-Z])([A-Z])([\d\s]+)$/i ) { + if (my $convert = gridref_to_latlon( $1, $2, $3 )) { + $c->stash->{latitude} = $convert->{latitude}; + $c->stash->{longitude} = $convert->{longitude}; + return $c->forward( 'check_location' ); + } + } + my ( $latitude, $longitude, $error ) = FixMyStreet::Geocode::lookup( $pc, $c ); @@ -114,6 +127,36 @@ sub check_location : Private { return 1; } +# Utility function for if someone (rarely) enters a grid reference +sub gridref_to_latlon { + my ( $a, $b, $num ) = @_; + $a = ord(uc $a) - 65; $a-- if $a > 7; + $b = ord(uc $b) - 65; $b-- if $b > 7; + my $e = (($a-2)%5)*5 + $b%5; + my $n = 19 - int($a/5)*5 - int($b/5); + + $num =~ s/\s+//g; + my $l = length($num); + return if $l % 2 or $l > 10; + + $l /= 2; + $e .= substr($num, 0, $l); + $n .= substr($num, $l); + + if ( $l < 5 ) { + $e .= 5; + $n .= 5; + $e .= 0 x (4-$l); + $n .= 0 x (4-$l); + } + + my ( $lat, $lon ) = Utils::convert_en_to_latlon( $e, $n ); + return { + latitude => $lat, + longitude => $lon, + }; +} + =head1 AUTHOR Struan Donald diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index fc4c3fde7..fa4baf045 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -9,6 +9,7 @@ use Digest::SHA1 qw(sha1_hex); use File::Path; use File::Slurp; use Path::Class; +use if !$ENV{TRAVIS}, 'Image::Magick'; =head1 NAME @@ -116,7 +117,6 @@ sub no_photo : Private { # Shrinks a picture to the specified size, but keeping in proportion. sub _shrink { my ($photo, $size) = @_; - use Image::Magick; my $image = Image::Magick->new; $image->BlobToImage($photo); my $err = $image->Scale(geometry => "$size>"); @@ -130,7 +130,6 @@ sub _shrink { # Shrinks a picture to 90x60, cropping so that it is exactly that. sub _crop { my ($photo) = @_; - use Image::Magick; my $image = Image::Magick->new; $image->BlobToImage($photo); my $err = $image->Resize( geometry => "90x60^" ); diff --git a/perllib/FixMyStreet/App/Controller/Questionnaire.pm b/perllib/FixMyStreet/App/Controller/Questionnaire.pm index f0cc72e07..46d6350d7 100755 --- a/perllib/FixMyStreet/App/Controller/Questionnaire.pm +++ b/perllib/FixMyStreet/App/Controller/Questionnaire.pm @@ -157,6 +157,8 @@ sub submit_standard : Private { my $new_state = ''; $new_state = 'fixed - user' if $c->stash->{been_fixed} eq 'Yes' && FixMyStreet::DB::Result::Problem->open_states()->{$old_state}; + $new_state = 'fixed - user' if $c->stash->{been_fixed} eq 'Yes' && + FixMyStreet::DB::Result::Problem->closed_states()->{$old_state}; $new_state = 'confirmed' if $c->stash->{been_fixed} eq 'No' && FixMyStreet::DB::Result::Problem->fixed_states()->{$old_state}; diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index cda569860..a7e1e8a3a 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -56,6 +56,23 @@ sub display : Path('') : Args(1) { $c->forward( 'format_problem_for_display' ); } +sub support : Path('support') : Args(0) { + my ( $self, $c ) = @_; + + my $id = $c->req->param('id'); + + my $uri = + $id + ? $c->uri_for( '/report', $id ) + : $c->uri_for('/'); + + if ( $id && $c->cobrand->can_support_problems && $c->user && $c->user->from_council ) { + $c->forward( 'load_problem_or_display_error', [ $id ] ); + $c->stash->{problem}->update( { interest_count => \'interest_count +1' } ); + } + $c->res->redirect( $uri ); +} + sub load_problem_or_display_error : Private { my ( $self, $c, $id ) = @_; diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 2318ee9e1..dedd447ee 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -6,7 +6,6 @@ BEGIN { extends 'Catalyst::Controller'; } use FixMyStreet::Geocode; use Encode; -use Image::Magick; use List::MoreUtils qw(uniq); use POSIX 'strcoll'; use HTML::Entities; @@ -14,7 +13,6 @@ use mySociety::MaPit; use Path::Class; use Utils; use mySociety::EmailUtil; -use mySociety::TempFiles; use JSON; =head1 NAME @@ -709,22 +707,23 @@ 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($_) } + ( 'email', 'name', 'phone', 'password_register', 'fms_extra_title' ); + + my $user_title = Utils::trim_text( $params{fms_extra_title} ); + # The user is already signed in if ( $c->user_exists ) { my $user = $c->user->obj; - 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} ) ); + $user->title( $user_title ) if $user_title; $report->user( $user ); $report->name( $user->name ); return 1; } - # 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', 'fms_extra_title' ); - # cleanup the email address my $email = $params{email} ? lc $params{email} : ''; $email =~ s{\s+}{}g; @@ -752,7 +751,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->user->title( $user_title ) if $user_title; $report->name( Utils::trim_text( $params{name} ) ); return 1; @@ -1010,6 +1009,13 @@ sub save_user_and_report : Private { # Set unknown to DB unknown $report->council( undef ) if $report->council 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') ); + $report->external_source( $c->config->{MESSAGE_MANAGER_URL} ) ; + } + # save the report; $report->in_storage ? $report->update : $report->insert(); @@ -1080,7 +1086,13 @@ sub redirect_or_confirm_creation : Private { if ( $report->confirmed ) { # Subscribe problem reporter to email updates $c->forward( 'create_reporter_alert' ); - my $report_uri = $c->cobrand->base_url_for_report( $report ) . $report->url; + my $report_uri; + + if ( $c->cobrand->moniker eq 'fixmybarangay' && $c->user->from_council && $c->stash->{external_source_id}) { + $report_uri = $c->uri_for( '/report', $report->id, undef, { external_source_id => $c->stash->{external_source_id} } ); + } 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); $c->res->redirect($report_uri); $c->detach; diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index c49123a90..da4cc33ca 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -76,6 +76,10 @@ sub update_problem : Private { $problem->state('confirmed'); } + if ( $c->cobrand->can_support_problems && $c->user && $c->user->from_council && $c->req->param('external_source_id') ) { + $problem->interest_count( \'interest_count + 1' ); + } + $problem->lastupdate( \'ms_current_timestamp()' ); $problem->update; @@ -348,6 +352,7 @@ 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->res->redirect($report_uri); $c->detach; diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index dd725be19..7087e846b 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -6,7 +6,6 @@ use File::Slurp; use List::MoreUtils qw(zip); use POSIX qw(strcoll); use mySociety::MaPit; -use mySociety::VotingArea; BEGIN { extends 'Catalyst::Controller'; } @@ -71,7 +70,7 @@ sub index : Path : Args(0) { if ($@) { $c->stash->{message} = _("There was a problem showing the All Reports page. Please try again later."); if ($c->config->{STAGING_SITE}) { - $c->stash->{message} .= '</p><p>Perhaps the bin/update-all-reports script needs running.</p><p>' + $c->stash->{message} .= '</p><p>Perhaps the bin/update-all-reports script needs running. Use: bin/cron-wrapper bin/update-all-reports</p><p>' . sprintf(_('The error was: %s'), $@); } $c->stash->{template} = 'errors/generic.html'; @@ -135,7 +134,7 @@ sub ward : Path : Args(2) { # List of wards unless ($c->stash->{ward}) { my $children = mySociety::MaPit::call('area/children', [ $c->stash->{council}->{id} ], - type => $mySociety::VotingArea::council_child_types, + type => $c->cobrand->area_types_children, ); foreach (values %$children) { $_->{url} = $c->uri_for( $c->stash->{council_url} @@ -170,13 +169,6 @@ sub rss_ward : Regex('^rss/(reports|area)$') : Args(2) { $url .= '/' . $c->cobrand->short_name( $c->stash->{ward} ) if $c->stash->{ward}; $c->stash->{qs} = "/$url"; - my @params; - push @params, $c->stash->{council}->{id} if $rss eq 'reports'; - push @params, $c->stash->{ward} - ? $c->stash->{ward}->{id} - : $c->stash->{council}->{id}; - $c->stash->{db_params} = [ @params ]; - if ( $rss eq 'area' && $c->stash->{ward} ) { # All problems within a particular ward $c->stash->{type} = 'area_problems'; @@ -258,7 +250,6 @@ sub council_check : Private { This action checks the ward name from a URI exists and is part of the right parent, already found with council_check. It either stores the ward Area if okay, or redirects to the council page if bad. -This is currently only used in the UK, hence the use of mySociety::VotingArea. =cut @@ -272,7 +263,7 @@ sub ward_check : Private { my $council = $c->stash->{council}; my $qw = mySociety::MaPit::call('areas', $ward, - type => $mySociety::VotingArea::council_child_types, + type => $c->cobrand->area_types_children, min_generation => $c->cobrand->area_min_generation ); foreach my $area (sort { $a->{name} cmp $b->{name} } values %$qw) { diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index fe4b652ed..baaa3b927 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -106,10 +106,19 @@ sub local_problems_pc_distance : Path('pc') : Args(2) { } -sub local_problems : LocalRegex('^(n|l)/([\d.-]+)[,/]([\d.-]+)(?:/(\d+))?$') { +sub local_problems_dist : LocalRegex('^(n|l)/([\d.-]+)[,/]([\d.-]+)/(\d+)$') { my ( $self, $c ) = @_; + $c->forward( 'local_problems', $c->req->captures ); +} + +sub local_problems_no_dist : LocalRegex('^(n|l)/([\d.-]+)[,/]([\d.-]+)$') { + my ( $self, $c ) = @_; + $c->forward( 'local_problems', $c->req->captures ); +} + +sub local_problems : Private { + my ( $self, $c, $type, $a, $b, $d ) = @_; - my ( $type, $a, $b, $d) = @{ $c->req->captures }; $c->forward( 'get_query_parameters', [ $d ] ); $c->detach( 'redirect_lat_lon', [ $a, $b ] ) |