diff options
Diffstat (limited to 'perllib/FixMyStreet/App')
18 files changed, 265 insertions, 91 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 54d744ccd..e14c7dc66 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; @@ -32,6 +33,11 @@ sub begin : Private { my ( $self, $c ) = @_; $c->uri_disposition('relative'); + + if ( $c->cobrand->moniker eq 'seesomething' ) { + $c->detach( '/auth/redirect' ) unless $c->user_exists; + $c->detach( '/auth/redirect' ) unless $c->user->from_council; + } } sub summary : Path( 'summary' ) : Args(0) { @@ -299,9 +305,14 @@ sub update_contacts : Private { $contact->email( $email ); $contact->confirmed( $c->req->param('confirmed') ? 1 : 0 ); $contact->deleted( $c->req->param('deleted') ? 1 : 0 ); + $contact->non_public( $c->req->param('non_public') ? 1 : 0 ); $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'); @@ -338,7 +349,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 extended_statuses comment_user_id/; + my %params = map { $_ => $c->req->param($_) || '' } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments suppress_alerts extended_statuses comment_user_id devolved/; if ( $params{open311_id} ) { my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } ); @@ -350,6 +361,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->send_extended_statuses( $params{extended_statuses} || 0 ); $conf->update(); @@ -365,6 +377,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->send_extended_statuses( $params{extended_statuses} || 0 ); $conf->insert(); @@ -461,6 +474,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; } @@ -640,6 +656,7 @@ sub report_edit : Path('report_edit') : Args(1) { } my $flagged = $c->req->param('flagged') ? 1 : 0; + my $non_public = $c->req->param('non_public') ? 1 : 0; # do this here so before we update the values in problem if ( $c->req->param('anonymous') ne $problem->anonymous @@ -647,7 +664,8 @@ sub report_edit : Path('report_edit') : Args(1) { || $c->req->param('email') ne $problem->user->email || $c->req->param('title') ne $problem->title || $c->req->param('detail') ne $problem->detail - || $flagged != $problem->flagged ) + || $flagged != $problem->flagged + || $non_public != $problem->non_public ) { $edited = 1; } @@ -658,6 +676,7 @@ sub report_edit : Path('report_edit') : Args(1) { $problem->state( $c->req->param('state') ); $problem->name( $c->req->param('name') ); $problem->flagged( $flagged ); + $problem->non_public( $non_public ); if ( $c->req->param('email') ne $problem->user->email ) { my $user = $c->model('DB::User')->find_or_create( @@ -725,8 +744,24 @@ sub search_users: Path('search_users') : Args(0) { ] } ); + my @users = $users->all; + my %email2user = map { $_->email => $_ } @users; + $c->stash->{users} = [ @users ]; + + my $emails = $c->model('DB::Abuse')->search( + { + email => { ilike => $isearch } + } + ); + foreach my $email ($emails->all) { + # Slight abuse of the boolean flagged value + if ($email2user{$email->email}) { + $email2user{$email->email}->flagged( 2 ); + } else { + push @{$c->stash->{users}}, { email => $email->email, flagged => 2 }; + } + } - $c->stash->{users} = [ $users->all ]; } return 1; @@ -833,26 +868,6 @@ sub update_edit : Path('update_edit') : Args(1) { return 1; } -sub search_abuse : Path('search_abuse') : Args(0) { - my ( $self, $c ) = @_; - - $c->forward('check_page_allowed'); - - my $search = $c->req->param('search'); - - if ($search) { - my $emails = $c->model('DB::Abuse')->search( - { - email => { ilike => "\%$search\%" } - } - ); - - $c->stash->{emails} = [ $emails->all ]; - } - - return 1; -} - sub user_edit : Path('user_edit') : Args(1) { my ( $self, $c, $id ) = @_; @@ -917,6 +932,10 @@ sub stats : Path('stats') : Args(0) { $c->forward('set_up_council_details'); + if ( $c->cobrand->moniker eq 'seesomething' ) { + return $c->cobrand->admin_stats(); + } + if ( $c->req->param('getcounts') ) { my ( $start_date, $end_date, @errors ); @@ -1019,13 +1038,12 @@ sub set_allowed_pages : Private { if( !$pages ) { $pages = { 'summary' => [_('Summary'), 0], - 'council_list' => [_('Council contacts'), 1], - 'search_reports' => [_('Search Reports'), 2], + 'council_list' => [_('Bodies'), 1], + 'search_reports' => [_('Reports'), 2], 'timeline' => [_('Timeline'), 3], - 'questionnaire' => [_('Survey Results'), 4], - 'search_users' => [_('Search Users'), 5], - 'search_abuse' => [_('Search Abuse'), 5], - 'list_flagged' => [_('List Flagged'), 6], + 'questionnaire' => [_('Survey'), 4], + 'search_users' => [_('Users'), 5], + 'list_flagged' => [_('Flagged'), 6], 'stats' => [_('Stats'), 6], 'user_edit' => [undef, undef], 'council_contacts' => [undef, undef], @@ -1276,7 +1294,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/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm index 926a3f2a5..04360301e 100644 --- a/perllib/FixMyStreet/App/Controller/Contact.pm +++ b/perllib/FixMyStreet/App/Controller/Contact.pm @@ -113,6 +113,9 @@ sub validate : Private { or $c->req->param('update_id') && $c->req->param('update_id') !~ /^[1-9]\d*$/; + push @errors, _('There was a problem showing this page. Please try again later.') + if $c->req->params->{message} && $c->req->params->{message} =~ /\[url=/; + unshift @errors, _('There were problems with your report. Please see below.') if scalar keys %field_errors; @@ -184,7 +187,7 @@ generally required to stash sub setup_request : Private { my ( $self, $c ) = @_; - $c->stash->{contact_email} = $c->cobrand->contact_email( 'contact' ); + $c->stash->{contact_email} = $c->cobrand->contact_email; $c->stash->{contact_email} =~ s/\@/@/; for my $param (qw/em subject message/) { @@ -206,7 +209,7 @@ Sends the email sub send_email : Private { my ( $self, $c ) = @_; - my $recipient = $c->cobrand->contact_email( 'contact' ); + my $recipient = $c->cobrand->contact_email; my $recipient_name = $c->cobrand->contact_name(); $c->stash->{host} = $c->req->header('HOST'); 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 b52e682a5..17fd8b867 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/JS.pm b/perllib/FixMyStreet/App/Controller/JS.pm index ae2f06605..d7847af75 100755 --- a/perllib/FixMyStreet/App/Controller/JS.pm +++ b/perllib/FixMyStreet/App/Controller/JS.pm @@ -24,6 +24,8 @@ sub validation_strings : LocalRegex('^validation_strings\.(.*?)\.js$') : Args(0) $c->res->content_type( 'application/javascript' ); } +sub validation_rules : Path('validation_rules.js') : Args(0) { } + __PACKAGE__->meta->make_immutable; 1; diff --git a/perllib/FixMyStreet/App/Controller/Location.pm b/perllib/FixMyStreet/App/Controller/Location.pm index c3d754485..fd3fadd9f 100644 --- a/perllib/FixMyStreet/App/Controller/Location.pm +++ b/perllib/FixMyStreet/App/Controller/Location.pm @@ -5,6 +5,7 @@ use namespace::autoclean; BEGIN {extends 'Catalyst::Controller'; } use Encode; +use FixMyStreet::Geocode; =head1 NAME @@ -64,6 +65,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]{4,})$/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 +128,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/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm index 040b0d3e6..3382c0cea 100644 --- a/perllib/FixMyStreet/App/Controller/Open311.pm +++ b/perllib/FixMyStreet/App/Controller/Open311.pm @@ -100,7 +100,7 @@ sub error : Private { sub get_discovery : Private { my ( $self, $c ) = @_; - my $contact_email = $c->config->{CONTACT_EMAIL}; + my $contact_email = $c->cobrand->contact_email; my $prod_url = 'http://www.fiksgatami.no/open311'; my $test_url = 'http://fiksgatami-dev.nuug.no/open311'; my $prod_changeset = '2011-04-08T00:00:00Z'; 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 d36ba32fe..ef966a8a8 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 ) = @_; @@ -74,6 +91,13 @@ sub load_problem_or_display_error : Private { '/page_error_410_gone', [ _('That report has been removed from FixMyStreet.') ] # ); + } elsif ( $problem->non_public ) { + if ( !$c->user || $c->user->id != $problem->user->id ) { + $c->detach( + '/page_error_403_access_denied', + [ sprintf(_('That report cannot be viewed on %s.'), $c->cobrand->site_title) ] # + ); + } } $c->stash->{problem} = $problem; diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index ede0cd219..9194f5318 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -4,9 +4,7 @@ use Moose; use namespace::autoclean; 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 +12,6 @@ use mySociety::MaPit; use Path::Class; use Utils; use mySociety::EmailUtil; -use mySociety::TempFiles; use JSON; =head1 NAME @@ -197,6 +194,7 @@ sub report_form_ajax : Path('ajax') : Args(0) { councils_text => $councils_text, category => $category, extra_name_info => $extra_name_info, + categories => $c->stash->{category_options}, } ); @@ -595,6 +593,8 @@ sub setup_categories_and_councils : Private { my @category_options = (); # categories to show my $category_label = undef; # what to call them my %category_extras = (); # extra fields to fill in for open311 + my %non_public_categories = + (); # categories for which the reports are not public # FIXME - implement in cobrand if ( $c->cobrand->moniker eq 'emptyhomes' ) { @@ -646,6 +646,8 @@ sub setup_categories_and_councils : Private { $category_extras{ $contact->category } = $contact->extra if $contact->extra; + + $non_public_categories{ $contact->category } = 1 if $contact->non_public; } $seen{$contact->category} = 1; } @@ -663,6 +665,7 @@ sub setup_categories_and_councils : Private { $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; @@ -704,22 +707,31 @@ 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} ); + + if ( $c->cobrand->allow_anonymous_reports ) { + my $anon_details = $c->cobrand->anonymous_account; + + for my $key ( qw( email name ) ) { + $params{ $key } ||= $anon_details->{ $key }; + } + } + # 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; @@ -747,7 +759,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; @@ -773,7 +785,9 @@ sub process_report : Private { 'detail_offensive', 'may_show_name', # 'category', # + 'subcategory', # 'partial', # + 'service', # ); # load the report @@ -798,9 +812,14 @@ sub process_report : Private { } $report->detail( $detail ); + # mobile device type + $report->service( $params{service} ) if $params{service}; + # set these straight from the params $report->category( _ $params{category} ) if $params{category}; + $report->subcategory( $params{subcategory} ); + my $areas = $c->stash->{all_areas}; $report->areas( ',' . join( ',', sort keys %$areas ) . ',' ); @@ -872,10 +891,14 @@ sub process_report : Private { }; } + if ( $c->stash->{non_public_categories}->{ $report->category } ) { + $report->non_public( 1 ); + } + $c->cobrand->process_extras( $c, $contacts[0]->area_id, \@extra ); if ( @extra ) { - $c->stash->{report_meta} = \@extra; + $c->stash->{report_meta} = { map { $_->{name} => $_ } @extra }; $report->extra( \@extra ); } } elsif ( @{ $c->stash->{area_ids_to_list} } ) { @@ -914,11 +937,14 @@ sub check_for_errors : Private { # let the model check for errors $c->stash->{field_errors} ||= {}; - my %field_errors = ( - %{ $c->stash->{field_errors} }, - %{ $c->stash->{report}->user->check_for_errors }, - %{ $c->stash->{report}->check_for_errors }, - ); + my %field_errors = $c->cobrand->report_check_for_errors( $c ); + + # Zurich, we don't care about title or name + # There is no title, and name is optional + if ( $c->cobrand->moniker eq 'zurich' ) { + delete $field_errors{title}; + delete $field_errors{name}; + } # FIXME: need to check for required bromley fields here @@ -956,7 +982,14 @@ sub save_user_and_report : Private { my $report = $c->stash->{report}; # Save or update the user if appropriate - if ( !$report->user->in_storage ) { + if ( $c->cobrand->never_confirm_reports ) { + if ( $report->user->in_storage() ) { + $report->user->update(); + } else { + $report->user->insert(); + } + $report->confirm(); + } elsif ( !$report->user->in_storage ) { # User does not exist. # Store changes in token for when token is validated. $c->stash->{token_data} = { @@ -1001,6 +1034,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(); @@ -1071,7 +1111,17 @@ 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} } ); + } 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); $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 3fc8bfee8..5e0d9f388 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; @@ -364,6 +368,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 37766db44..ec41dc17f 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'; @@ -84,13 +83,13 @@ sub index : Path : Args(0) { =head2 index -Show the summary page for a particular council. +Show the summary page for a particular body. =cut -sub council : Path : Args(1) { - my ( $self, $c, $council ) = @_; - $c->detach( 'ward', [ $council ] ); +sub body : Path : Args(1) { + my ( $self, $c, $body ) = @_; + $c->detach( 'ward', [ $body ] ); } =head2 index @@ -102,7 +101,7 @@ Show the summary page for a particular ward. sub ward : Path : Args(2) { my ( $self, $c, $council, $ward ) = @_; - $c->forward( 'council_check', [ $council ] ); + $c->forward( 'body_check', [ $council ] ); $c->forward( 'ward_check', [ $ward ] ) if $ward; $c->forward( 'load_parent' ); @@ -133,9 +132,10 @@ sub ward : Path : Args(2) { $c->cobrand->tweak_all_reports_map( $c ); # List of wards - unless ($c->stash->{ward}) { + # Ignore external_body special council thing + unless ($c->stash->{ward} || !$c->stash->{council}->{id}) { 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} @@ -146,9 +146,9 @@ sub ward : Path : Args(2) { } } -sub rss_council : Regex('^rss/(reports|area)$') : Args(1) { - my ( $self, $c, $council ) = @_; - $c->detach( 'rss_ward', [ $council ] ); +sub rss_body : Regex('^rss/(reports|area)$') : Args(1) { + my ( $self, $c, $body ) = @_; + $c->detach( 'rss_ward', [ $body ] ); } sub rss_ward : Regex('^rss/(reports|area)$') : Args(2) { @@ -158,8 +158,8 @@ sub rss_ward : Regex('^rss/(reports|area)$') : Args(2) { $c->stash->{rss} = 1; - $c->forward( 'council_check', [ $council ] ); - $c->forward( 'ward_check', [ $ward ] ) if $ward; + $c->forward( 'body_check', [ $council ] ); + $c->forward( 'ward_check', [ $ward ] ) if $ward; if ($rss eq 'area' && $c->stash->{council}{type} ne 'DIS' && $c->stash->{council}{type} ne 'CTY') { # Two possibilites are the same for one-tier councils, so redirect one to the other @@ -170,13 +170,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'; @@ -203,15 +196,15 @@ sub rss_ward : Regex('^rss/(reports|area)$') : Args(2) { $c->forward( '/rss/output' ); } -=head2 council_check +=head2 body_check -This action checks the council name (or code) given in a URI exists, is valid -and so on. If it is, it stores the Area in the stash, otherwise it redirects -to the all reports page. +This action checks the council or external_body name (or code) given in a URI +exists, is valid and so on. If it is, it stores the area or body in the stash, +otherwise it redirects to the all reports page. =cut -sub council_check : Private { +sub body_check : Private { my ( $self, $c, $q_council ) = @_; $q_council =~ s/\+/ /g; @@ -219,7 +212,7 @@ sub council_check : Private { # Check cobrand specific incantations - e.g. ONS codes for UK, # Oslo/ kommunes sharing a name in Norway - return if $c->cobrand->reports_council_check( $c, $q_council ); + return if $c->cobrand->reports_body_check( $c, $q_council ); # If we're passed an ID number (don't think this is used anywhere, it # certainly shouldn't be), just look that up on MaPit and redirect @@ -230,12 +223,22 @@ sub council_check : Private { $c->detach( 'redirect_area' ); } + if ( $c->cobrand->reports_by_body ) { + my $problem = $c->cobrand->problems->search({ 'lower(me.external_body)' => lc $q_council }, { columns => [ 'external_body' ], rows => 1 })->single; + if ( $problem ) { + # If external_body, put as a council with ID 0 for the moment. + $c->stash->{council} = { id => 0, name => $problem->external_body }; + return; + } + } + # We must now have a string to check my $area_types = $c->cobrand->area_types; my $areas = mySociety::MaPit::call( 'areas', $q_council, type => $area_types, min_generation => $c->cobrand->area_min_generation ); + if (keys %$areas == 1) { ($c->stash->{council}) = values %$areas; return; @@ -255,9 +258,8 @@ sub council_check : Private { =head2 ward_check 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 +parent, already found with body_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 @@ -271,7 +273,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) { @@ -318,7 +320,8 @@ sub load_and_group_problems : Private { my $page = $c->req->params->{p} || 1; my $where = { - state => [ FixMyStreet::DB::Result::Problem->visible_states() ] + non_public => 0, + state => [ FixMyStreet::DB::Result::Problem->visible_states() ] }; if ($c->stash->{ward}) { $where->{areas} = { 'like', '%,' . $c->stash->{ward}->{id} . ',%' }; @@ -328,6 +331,9 @@ sub load_and_group_problems : Private { { 'like', $c->stash->{council}->{id} . ',%' }, { 'like', '%,' . $c->stash->{council}->{id} }, ]; + } elsif ($c->stash->{council} && $c->stash->{council}->{id} == 0) { + # A proxy for an external_body + $where->{'lower(external_body)'} = lc $c->stash->{council}->{name}; } elsif ($c->stash->{council}) { $where->{areas} = { 'like', '%,' . $c->stash->{council}->{id} . ',%' }; $where->{council} = [ @@ -363,6 +369,11 @@ sub load_and_group_problems : Private { my %problem = zip @cols, @problem; $problem{is_fixed} = FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}}; $c->log->debug( $problem{'cobrand'} . ', cobrand is ' . $c->cobrand->moniker ); + if ( !$c->stash->{council}->{id} ) { + # An external_body entry + add_row( \%problem, 0, \%problems, \@pins ); + next; + } if ( !$problem{council} ) { # Problem was not sent to any council, add to possible councils $problem{councils} = 0; @@ -375,7 +386,7 @@ sub load_and_group_problems : Private { my @council = split( /,/, $council ); $problem{councils} = scalar @council; foreach ( @council ) { - next if $c->stash->{council} && $_ != $c->stash->{council}->{id}; + next if $_ != $c->stash->{council}->{id}; add_row( \%problem, $_, \%problems, \@pins ); } } diff --git a/perllib/FixMyStreet/App/Controller/Root.pm b/perllib/FixMyStreet/App/Controller/Root.pm index 7f7d7f5fd..769a147bf 100644 --- a/perllib/FixMyStreet/App/Controller/Root.pm +++ b/perllib/FixMyStreet/App/Controller/Root.pm @@ -94,6 +94,13 @@ sub page_error_410_gone : Private { $c->response->status(410); } +sub page_error_403_access_denied : Private { + my ( $self, $c, $error_msg ) = @_; + $c->stash->{template} = 'index.html'; + $c->stash->{error} = $error_msg; + $c->response->status(403); +} + =head2 end Attempt to render a view, if needed. 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 ] ) diff --git a/perllib/FixMyStreet/App/View/Web.pm b/perllib/FixMyStreet/App/View/Web.pm index eac194dff..42878be37 100644 --- a/perllib/FixMyStreet/App/View/Web.pm +++ b/perllib/FixMyStreet/App/View/Web.pm @@ -171,6 +171,7 @@ sub version { my $path = FixMyStreet->path_to('web', $file); $version_hash{$file} = ( stat( $path ) )[9]; } + $version_hash{$file} ||= ''; return "$file?$version_hash{$file}"; } |