diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Auth.pm | 49 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Contact.pm | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 155 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Photo.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 79 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 31 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Static.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Barnet.pm | 84 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 21 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/LichfieldDC.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/AlertType.pm | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Barnet.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 2 |
17 files changed, 434 insertions, 82 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index 3d9f0a511..6ccc801ce 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -319,6 +319,16 @@ sub send_email_cron { unpack('h*', random_bytes(5, 1)) ); + $params->{_parameters_}->{signature} = ''; + #$params->{_parameters_}->{signature} = $c->view('Email')->render( + # $c, 'signature.txt', { + # additional_template_paths => [ + # FixMyStreet->path_to( 'templates', 'email', $c->cobrand->moniker, $c->stash->{lang_code} )->stringify, + # FixMyStreet->path_to( 'templates', 'email', $c->cobrand->moniker )->stringify, + # ] + # } + #); + my $email = mySociety::Locale::in_gb_locale { mySociety::Email::construct_email($params) }; if ( FixMyStreet->test_mode ) { diff --git a/perllib/FixMyStreet/App/Controller/Auth.pm b/perllib/FixMyStreet/App/Controller/Auth.pm index c67de692a..3dc25dedf 100644 --- a/perllib/FixMyStreet/App/Controller/Auth.pm +++ b/perllib/FixMyStreet/App/Controller/Auth.pm @@ -7,6 +7,7 @@ BEGIN { extends 'Catalyst::Controller'; } use Email::Valid; use Net::Domain::TLD; use mySociety::AuthToken; +use JSON; =head1 NAME @@ -250,6 +251,54 @@ sub sign_out : Local { $c->logout(); } +sub ajax_sign_in : Path('ajax/sign_in') { + my ( $self, $c ) = @_; + + my $return = {}; + if ( $c->forward( 'sign_in' ) ) { + $return->{name} = $c->user->name; + } else { + $return->{error} = 1; + } + + my $body = JSON->new->utf8(1)->encode( $return ); + $c->res->content_type('application/json; charset=utf-8'); + $c->res->body($body); + + return 1; +} + +sub ajax_sign_out : Path('ajax/sign_out') { + my ( $self, $c ) = @_; + + $c->logout(); + + my $body = JSON->new->utf8(1)->encode( { signed_out => 1 } ); + $c->res->content_type('application/json; charset=utf-8'); + $c->res->body($body); + + return 1; +} + +sub ajax_check_auth : Path('ajax/check_auth') { + my ( $self, $c ) = @_; + + my $code = 401; + my $data = { not_authorized => 1 }; + + if ( $c->user ) { + $data = { name => $c->user->name }; + $code = 200; + } + + my $body = JSON->new->utf8(1)->encode( $data ); + $c->res->content_type('application/json; charset=utf-8'); + $c->res->code($code); + $c->res->body($body); + + return 1; +} + =head2 check_auth Utility page - returns a simple message 'OK' and a 200 response if the user is diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm index 91580f05a..c300aee9a 100644 --- a/perllib/FixMyStreet/App/Controller/Contact.pm +++ b/perllib/FixMyStreet/App/Controller/Contact.pm @@ -139,17 +139,17 @@ sub prepare_params_for_email : Private { $c->stash->{message} =~ s/\r\n/\n/g; $c->stash->{subject} =~ s/\r|\n/ /g; - my $base_url = $c->cobrand->base_url_for_emails( $c->cobrand->extra_data ); - my $admin_base_url = $c->cobrand->admin_base_url - || 'https://secure.mysociety.org/admin/bci/'; + my $base_url = $c->cobrand->base_url_for_emails( $c->cobrand->extra_data ); + my $admin_url = $c->cobrand->admin_base_url; if ( $c->stash->{update} ) { my $problem_url = $base_url . '/report/' . $c->stash->{update}->problem_id . '#update_' . $c->stash->{update}->id; - my $admin_url = $admin_base_url . 'update_edit/' . $c->stash->{update}->id; + my $admin_url = " - $admin_url" . 'update_edit/' . $c->stash->{update}->id + if $admin_url; $c->stash->{message} .= sprintf( - " \n\n[ Complaint about update %d on report %d - %s - %s ]", + " \n\n[ Complaint about update %d on report %d - %s%s ]", $c->stash->{update}->id, $c->stash->{update}->problem_id, $problem_url, $admin_url @@ -158,9 +158,10 @@ sub prepare_params_for_email : Private { elsif ( $c->stash->{problem} ) { my $problem_url = $base_url . '/report/' . $c->stash->{problem}->id; - my $admin_url = $admin_base_url . 'report_edit/' . $c->stash->{problem}->id; + $admin_url = " - $admin_url" . 'report_edit/' . $c->stash->{problem}->id + if $admin_url; $c->stash->{message} .= sprintf( - " \n\n[ Complaint about report %d - %s - %s ]", + " \n\n[ Complaint about report %d - %s%s ]", $c->stash->{problem}->id, $problem_url, $admin_url ); diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 0273e0eda..e4266dc64 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -3,6 +3,7 @@ use Moose; use namespace::autoclean; use DateTime; +use File::Slurp; BEGIN { extends 'Catalyst::Controller'; } @@ -18,6 +19,49 @@ Catalyst Controller. =cut +sub example : Local : Args(0) { + my ( $self, $c ) = @_; + $c->stash->{template} = 'dashboard/index.html'; + + $c->stash->{children} = {}; + for my $i (1..3) { + $c->stash->{children}{$i} = { id => $i, name => "Ward $i" }; + } + + # TODO Set up manual version of what the below would do + #$c->forward( '/report/new/setup_categories_and_councils' ); + + # See if we've had anything from the dropdowns - perhaps vary results if so + $c->stash->{ward} = $c->req->param('ward'); + $c->stash->{category} = $c->req->param('category'); + $c->stash->{q_state} = $c->req->param('state'); + + eval { + my $data = File::Slurp::read_file( + FixMyStreet->path_to( 'data/dashboard.json' )->stringify + ); + my $j = JSON->new->utf8->decode($data); + if ( !$c->stash->{ward} && !$c->stash->{category} ) { + $c->stash->{problems} = $j->{counts_all}; + } else { + $c->stash->{problems} = $j->{counts_some}; + } + $c->stash->{council} = $j->{council}; + $c->stash->{children} = $j->{wards}; + $c->stash->{category_options} = $j->{category_options}; + if ( lc($c->stash->{q_state}) eq 'all' or !$c->stash->{q_state} ) { + $c->stash->{lists} = $j->{lists}->{all}; + } else { + $c->stash->{lists} = $j->{lists}->{filtered}; + } + }; + if ($@) { + $c->stash->{message} = _("There was a problem showing this page. Please try again later.") . ' ' . + sprintf(_('The error was: %s'), $@); + $c->stash->{template} = 'errors/generic.html'; + } +} + =head2 check_page_allowed Checks if we can view this page, and if not redirect to 404. @@ -48,20 +92,21 @@ sub index : Path : Args(0) { # Set up the data for the dropdowns + my $council_detail = mySociety::MaPit::call('area', $council ); + $c->stash->{council} = $council_detail; + 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->stash->{all_councils} = { $council => $council_detail }; $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... @@ -71,40 +116,54 @@ sub index : Path : Args(0) { 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} - } + $c->stash->{where} = \%where; + my $prob_where = { %where }; + $prob_where->{state} = $prob_where->{'problem.state'}; + delete $prob_where->{'problem.state'}; + $c->stash->{prob_where} = $prob_where; my %counts; my $t = DateTime->today; + $counts{wtd} = $c->forward( 'updates_search', [ $t->subtract( days => $t->dow - 1 ) ] ); + $counts{week} = $c->forward( 'updates_search', [ DateTime->now->subtract( weeks => 1 ) ] ); + $counts{weeks} = $c->forward( 'updates_search', [ DateTime->now->subtract( weeks => 4 ) ] ); + $counts{ytd} = $c->forward( 'updates_search', [ DateTime->today->set( day => 1, month => 1 ) ] ); - $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 ) - } } ] ); + $c->stash->{problems} = \%counts; - $counts{ytd} = $c->forward( 'updates_search', [ { - %where, - 'me.confirmed' => { '>=', DateTime->today->set( day => 1, month => 1 ) - } } ] ); + # List of reports underneath summary table - $c->stash->{problems} = \%counts; + $c->stash->{q_state} = $c->req->param('state') || ''; + if ( $c->stash->{q_state} eq 'fixed' ) { + $prob_where->{state} = [ FixMyStreet::DB::Result::Problem->fixed_states() ]; + } elsif ( $c->stash->{q_state} ) { + $prob_where->{state} = $c->stash->{q_state}; + } + my $params = { + %$prob_where, + 'me.confirmed' => { '>=', DateTime->now->subtract( days => 30 ) }, + }; + my @problems = $c->cobrand->problems->search( $params )->all; + my %problems; + foreach (@problems) { + if ($_->confirmed >= DateTime->now->subtract(days => 7)) { + push @{$problems{1}}, $_; + } elsif ($_->confirmed >= DateTime->now->subtract(days => 14)) { + push @{$problems{2}}, $_; + } else { + push @{$problems{3}}, $_; + } + } + $c->stash->{lists} = \%problems; } sub updates_search : Private { - my ( $self, $c, $params ) = @_; + my ( $self, $c, $time ) = @_; + + my $params = { + %{$c->stash->{where}}, + 'me.confirmed' => { '>=', $time }, + }; my $comments = $c->model('DB::Comment')->search( $params, @@ -124,14 +183,48 @@ sub updates_search : Private { 'fixed - user', 'fixed', 'unconfirmed', 'hidden', 'partial', 'planned'); + for my $vars ( + [ 'time_to_fix', 'fixed - council' ], + [ 'time_to_mark', 'in progress', 'planned', 'investigating', 'closed' ], + ) { + my $col = shift @$vars; + my $substmt = "select min(id) from comment where me.problem_id=comment.problem_id and problem_state in ('" + . join("','", @$vars) . "')"; + $comments = $c->model('DB::Comment')->search( + { %$params, + problem_state => $vars, + 'me.id' => \"= ($substmt)", + }, + { + select => [ + { count => 'me.id' }, + { avg => { extract => "epoch from me.confirmed-problem.confirmed" } }, + ], + as => [ qw/state_count time/ ], + join => 'problem' + } + )->first; + $counts{$col} = int( ($comments->get_column('time')||0) / 60 / 60 / 24 + 0.5 ); + } + $counts{fixed_user} = $c->model('DB::Comment')->search( - { %$params, mark_fixed => 1 }, { join => 'problem' } + { %$params, mark_fixed => 1, problem_state => undef }, { join => 'problem' } )->count; - $params->{state} = $params->{'problem.state'}; - delete $params->{'problem.state'}; + $params = { + %{$c->stash->{prob_where}}, + 'me.confirmed' => { '>=', $time }, + }; $counts{total} = $c->cobrand->problems->search( $params )->count; + $params = { + %{$c->stash->{prob_where}}, + 'me.confirmed' => { '>=', $time }, + state => 'confirmed', + '(select min(id) from comment where me.id=problem_id and problem_state is not null)' => undef, + }; + $counts{not_marked} = $c->cobrand->problems->search( $params )->count; + return \%counts; } diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm index a6717fc33..fc4c3fde7 100644 --- a/perllib/FixMyStreet/App/Controller/Photo.pm +++ b/perllib/FixMyStreet/App/Controller/Photo.pm @@ -6,6 +6,8 @@ BEGIN {extends 'Catalyst::Controller'; } use DateTime::Format::HTTP; use Digest::SHA1 qw(sha1_hex); +use File::Path; +use File::Slurp; use Path::Class; =head1 NAME @@ -95,6 +97,10 @@ sub index :LocalRegex('^(c/)?(\d+)(?:\.(full|tn|fp))?\.jpeg$') { sub output : Private { my ( $self, $c, $photo ) = @_; + # Save to file + File::Path::make_path( FixMyStreet->path_to( 'web', 'photo', 'c' )->stringify ); + File::Slurp::write_file( FixMyStreet->path_to( 'web', $c->req->path )->stringify, \$photo ); + my $dt = DateTime->now()->add( years => 1 ); $c->res->content_type( 'image/jpeg' ); diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index cca625bd5..6f249b2fe 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -125,6 +125,8 @@ sub format_problem_for_display : Private { $c->stash->{add_alert} = 1; } + $c->stash->{extra_name_info} = $problem->council eq '2482' ? 1 : 0; + $c->forward('generate_map_tags'); return 1; diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 37ff1ae76..5bf184ae6 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -104,6 +104,68 @@ sub report_new : Path : Args(0) { $c->forward('redirect_or_confirm_creation'); } +# This is for the new phonegap versions of the app. It looks a lot like +# report_new but there's a few workflow differences as we only ever want +# to sent JSON back here + +sub report_new_ajax : Path('mobile') : Args(0) { + my ( $self, $c ) = @_; + + # create the report - loading a partial if available + $c->forward('initialize_report'); + + unless ( $c->forward('determine_location') ) { + $c->stash->{ json_response } = { errors => 'Unable to determine location' }; + $c->forward('send_json_response'); + return 1; + } + + $c->forward('setup_categories_and_councils'); + $c->forward('process_user'); + $c->forward('process_report'); + $c->forward('/photo/process_photo'); + + unless ($c->forward('check_for_errors')) { + $c->stash->{ json_response } = { errors => $c->stash->{field_errors} }; + $c->stash->{ json_response }->{check_name} = $c->user->name if $c->stash->{check_name}; + $c->forward('send_json_response'); + return 1; + } + + $c->forward('save_user_and_report'); + + my $report = $c->stash->{report}; + my $data = $c->stash->{token_data} || {}; + my $token = $c->model("DB::Token")->create( { + scope => 'problem', + data => { + %$data, + id => $report->id + } + } ); + if ( $report->confirmed ) { + $c->stash->{ json_response } = { success => 1, report => $report->id }; + } else { + $c->stash->{token_url} = $c->uri_for_email( '/P', $token->token ); + $c->send_email( 'problem-confirm.txt', { + to => [ [ $report->user->email, $report->name ] ], + } ); + $c->stash->{ json_response } = { success => 1 }; + } + + $c->forward('send_json_response'); +} + +sub send_json_response : Private { + my ( $self, $c ) = @_; + + my $body = JSON->new->utf8(1)->encode( + $c->stash->{json_response}, + ); + $c->res->content_type('application/json; charset=utf-8'); + $c->res->body($body); +} + sub report_form_ajax : Path('ajax') : Args(0) { my ( $self, $c ) = @_; @@ -124,7 +186,6 @@ sub report_form_ajax : Path('ajax') : Args(0) { # render templates to get the html 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') : ''; @@ -133,7 +194,6 @@ sub report_form_ajax : Path('ajax') : Args(0) { { councils_text => $councils_text, category => $category, - has_open311 => $has_open311, extra_name_info => $extra_name_info, } ); @@ -579,10 +639,6 @@ sub setup_categories_and_councils : Private { $area_ids_to_list{ $contact->area_id } = 1; - next # TODO - move this to the cobrand - if $c->cobrand->moniker eq 'southampton' - && $contact->category =~ /Street lighting|Traffic lights/; - next if $contact->category eq _('Other'); unless ( $seen{$contact->category} ) { @@ -595,8 +651,9 @@ sub setup_categories_and_councils : Private { } if (@category_options) { - @category_options = - ( _('-- Pick a category --'), @category_options, _('Other') ); + @category_options = ( _('-- Pick a category --'), @category_options ); + push @category_options, _('Other') + unless $first_council->{id} == 2482; $category_label = _('Category'); } } @@ -679,6 +736,7 @@ sub process_user : Private { my $user = $c->user->obj; $report->user( $user ); $report->name( $user->name ); + $c->stash->{check_name} = 1; $c->stash->{field_errors}->{name} = _('You have successfully signed in; please check and confirm your details are accurate:'); $c->log->info($user->id . ' logged in during problem creation'); return 1; @@ -712,6 +770,7 @@ sub process_report : Private { ( 'title', 'detail', 'pc', # 'detail_size', 'detail_depth', + 'detail_offensive', 'may_show_name', # 'category', # 'partial', # @@ -732,7 +791,7 @@ sub process_report : Private { $report->title( Utils::cleanup_text( $params{title} ) ); my $detail = Utils::cleanup_text( $params{detail}, { allow_multiline => 1 } ); - for my $w ('depth', 'size') { + for my $w ('depth', 'size', 'offensive') { next unless $params{"detail_$w"}; next if $params{"detail_$w"} eq '-- Please select --'; $detail .= "\n\n\u$w: " . $params{"detail_$w"}; @@ -813,7 +872,7 @@ sub process_report : Private { }; } - $c->cobrand->process_extras( $c, \@contacts, \@extra ); + $c->cobrand->process_extras( $c, $contacts[0]->area_id, \@extra ); if ( @extra ) { $c->stash->{report_meta} = \@extra; diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 5b0dad170..3a2b40c2c 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -201,13 +201,16 @@ sub process_update : Private { $update->problem_state( $params{state} ); } + my @extra; # Next function fills this, but we don't need it here. + # This is just so that the error checkign for these extra fields runs. + # TODO Use extra here as it is used on reports. + $c->cobrand->process_extras( $c, $update->problem->council, \@extra ); + 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'); + $extras{email_alerts_requested} = $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 } ) { @@ -392,14 +395,20 @@ sub signup_for_alerts : Private { if ( $c->stash->{add_alert} ) { my $update = $c->stash->{update}; - my $alert = $c->model('DB::Alert')->find_or_create( - user => $update->user, - alert_type => 'new_updates', - parameter => $update->problem_id, - cobrand => $update->cobrand, - cobrand_data => $update->cobrand_data, - lang => $update->lang, - ); + my $options = { + user => $update->user, + alert_type => 'new_updates', + parameter => $update->problem_id, + }; + my $alert = $c->model('DB::Alert')->find($options); + unless ($alert) { + $alert = $c->model('DB::Alert')->create({ + %$options, + cobrand => $update->cobrand, + cobrand_data => $update->cobrand_data, + lang => $update->lang, + }); + } $alert->confirm(); } elsif ( $c->user && ( my $alert = $c->user->alert_for_problem($c->stash->{update}->problem_id) ) ) { diff --git a/perllib/FixMyStreet/App/Controller/Static.pm b/perllib/FixMyStreet/App/Controller/Static.pm index d4b7a1b83..723f0f2e1 100755 --- a/perllib/FixMyStreet/App/Controller/Static.pm +++ b/perllib/FixMyStreet/App/Controller/Static.pm @@ -22,13 +22,6 @@ sub about : Global : Args(0) { # don't need to do anything here - should just pass through. } -sub for_councils : Path('/for-councils') : Args(0) { - my ( $self, $c ) = @_; -} -sub for_councils_faq : Path('/for-councils/faq') : Args(0) { - my ( $self, $c ) = @_; -} - sub privacy : Global : Args(0) { my ( $self, $c ) = @_; } diff --git a/perllib/FixMyStreet/Cobrand/Barnet.pm b/perllib/FixMyStreet/Cobrand/Barnet.pm index 6f115ec63..b3876a2c6 100644 --- a/perllib/FixMyStreet/Cobrand/Barnet.pm +++ b/perllib/FixMyStreet/Cobrand/Barnet.pm @@ -8,16 +8,100 @@ sub council_id { return 2489; } sub council_area { return 'Barnet'; } sub council_name { return 'Barnet Council'; } sub council_url { return 'barnet'; } +sub all_reports_style { return 'detailed'; } + +sub path_to_web_templates { + my $self = shift; + return [ + FixMyStreet->path_to( 'templates/web', $self->moniker )->stringify, + FixMyStreet->path_to( 'templates/web/fixmystreet' )->stringify + ]; +} sub disambiguate_location { my $self = shift; return { %{ $self->SUPER::disambiguate_location() }, + town => 'Barnet', centre => '51.612832,-0.218169', span => '0.0563,0.09', bounds => [ '51.584682,-0.263169', '51.640982,-0.173169' ], }; } +sub generate_problem_banner { + my ( $self, $problem ) = @_; + + my $banner = {}; + if ( $problem->is_open && time() - $problem->lastupdate_local->epoch > 8 * 7 * 24 * 60 * 60 ) + { + $banner->{id} = 'unknown'; + $banner->{text} = _('Unknown'); + } + if ($problem->is_fixed) { + $banner->{id} = 'fixed'; + $banner->{text} = _('Fixed'); + } + if ($problem->is_closed) { + $banner->{id} = 'closed'; + $banner->{text} = _('Closed'); + } + + if ( grep { $problem->state eq $_ } ( 'investigating', 'in progress', 'planned' ) ) { + $banner->{id} = 'progress'; + $banner->{text} = _('In progress'); + } + + return $banner; +} + +sub council_rss_alert_options { + my $self = shift; + my $all_councils = shift; + my $c = shift; + + my %councils = map { $_ => 1 } $self->area_types(); + + my $num_councils = scalar keys %$all_councils; + + my ( @options, @reported_to_options ); + if ( $num_councils == 1 or $num_councils == 2 ) { + my ($council, $ward); + foreach (values %$all_councils) { + if ($councils{$_->{type}}) { + $council = $_; + $council->{short_name} = $self->short_name( $council ); + ( $council->{id_name} = $council->{short_name} ) =~ tr/+/_/; + } else { + $ward = $_; + $ward->{short_name} = $self->short_name( $ward ); + ( $ward->{id_name} = $ward->{short_name} ) =~ tr/+/_/; + } + } + + push @options, + { + type => 'council', + id => sprintf( 'council:%s:%s', $council->{id}, $council->{id_name} ), + text => 'All problems within the council.', + rss_text => sprintf( _('RSS feed of problems within %s'), $council->{name}), + uri => $c->uri_for( '/rss/reports/' . $council->{short_name} ), + }; + push @options, + { + type => 'ward', + id => sprintf( 'ward:%s:%s:%s:%s', $council->{id}, $ward->{id}, $council->{id_name}, $ward->{id_name} ), + rss_text => sprintf( _('RSS feed of problems within %s ward'), $ward->{name}), + text => sprintf( _('Problems within %s ward'), $ward->{name}), + uri => $c->uri_for( '/rss/reports/' . $council->{short_name} . '/' . $ward->{short_name} ), + } if $ward; + } + + return ( \@options, @reported_to_options ? \@reported_to_options : undef ); +} + +sub example_places { + return [ 'N11 1NP', 'Wood St' ]; +} 1; diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index f7d885da2..c5c6c6345 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -10,11 +10,15 @@ sub council_id { return 2482; } sub council_area { return 'Bromley'; } sub council_name { return 'Bromley Council'; } sub council_url { return 'bromley'; } +sub all_reports_style { return 'detailed'; } sub base_url { - 'https://fix.bromley.gov.uk'; + return FixMyStreet->config('BASE_URL') if FixMyStreet->config('STAGING_SITE'); + return 'https://fix.bromley.gov.uk'; } +sub admin_base_url { '' } + sub path_to_web_templates { my $self = shift; return [ @@ -27,6 +31,9 @@ sub site_title { my ($self) = @_; return "London Borough of Bromley - Report a problem in Bromley\x{2019}s streets or parks"; } +sub site_name { + return 'Bromley FixMyStreet'; +} sub disambiguate_location { my $self = shift; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index be024f134..87bd2d316 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -97,7 +97,7 @@ Base URL for the admin interface. =cut -sub admin_base_url { 0 } +sub admin_base_url { '' } =head2 writetothem_url @@ -136,6 +136,15 @@ Parameter is QUERY sub enter_postcode_text { _('Enter a nearby street name and area') } +=head2 all_reports_style + +Return the type of problem information to display on the all reports +pages for councils. Can be either simple or detailed. + +=cut + +sub all_reports_style { return 'simple'; } + =head2 set_lang_and_domain my $set_lang = $cobrand->set_lang_and_domain( $lang, $unicode, $dir ) @@ -351,6 +360,16 @@ Return the title to be used in page heads. sub site_title { 'FixMyStreet' } +=head2 site_name + +Return short name for use in emails. + +=cut +sub site_name { + my $self = shift; + $self->site_title; +} + =head2 map_type Return an override type of map if necessary. diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index aba58495e..fbc48449c 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -14,6 +14,10 @@ sub enter_postcode_text { return _("Enter a nearby GB postcode, or street name and area"); } +sub admin_base_url { + return 'https://secure.mysociety.org/admin/bci/'; +} + sub get_council_sender { my ( $self, $area_id, $area_info ) = @_; @@ -29,6 +33,8 @@ sub get_council_sender { return 'Email'; } +sub all_reports_style { return 'detailed'; } + sub generate_problem_banner { my ( $self, $problem ) = @_; @@ -56,13 +62,13 @@ sub generate_problem_banner { } sub process_extras { - my $self = shift; - my $ctx = shift; - my $contacts = shift; - my $extra = shift; - my $fields = shift || []; + my $self = shift; + my $ctx = shift; + my $area_id = shift; + my $extra = shift; + my $fields = shift || []; - if ( $contacts->[0]->area_id == 2482 ) { + if ( $area_id == 2482 ) { my @fields = ( 'fms_extra_title', @$fields ); for my $field ( @fields ) { my $value = $ctx->request->param( $field ); diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm index 4d93aaf76..804289d34 100644 --- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm +++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm @@ -26,7 +26,7 @@ sub disambiguate_location { %{ $self->SUPER::disambiguate_location() }, centre => '52.688198,-1.804966', span => '0.1196,0.218675', - bounds => [ '52.807793,-1.586291', '52.584891,-1.963232' ], + bounds => [ '52.584891,-1.963232', '52.807793,-1.586291' ], }; } diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index 32654e534..26d8f32a9 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -65,6 +65,8 @@ sub email_alerts ($) { # call checks if this is the host that sends mail for this cobrand. next unless $cobrand->email_host; + my ( $sql_restriction, $name_restictions, $hashref_restriction ) = $cobrand->site_restriction( $row->{cobrand_data} ); + FixMyStreet::App->model('DB::AlertSent')->create( { alert_id => $row->{alert_id}, parameter => $row->{item_id}, @@ -84,6 +86,9 @@ sub email_alerts ($) { } my $url = $cobrand->base_url_for_emails( $row->{alert_cobrand_data} ); + if ( $hashref_restriction && $hashref_restriction->{council} && $row->{council} ne $hashref_restriction->{council} ) { + $url = mySociety::Config::get('BASE_URL'); + } # this is currently only for new_updates if ($row->{item_text}) { $data{problem_url} = $url . "/report/" . $row->{id}; @@ -136,8 +141,7 @@ sub email_alerts ($) { my $longitude = $alert->parameter; my $latitude = $alert->parameter2; - my $url = $cobrand->base_url_for_emails( $alert->cobrand_data ); - my ($site_restriction, $site_id) = $cobrand->site_restriction( $alert->cobrand_data ); + my ($site_restriction, $site_id, $hashref_restriction) = $cobrand->site_restriction( $alert->cobrand_data ); my $d = mySociety::Gaze::get_radius_containing_population($latitude, $longitude, 200000); # Convert integer to GB locale string (with a ".") $d = mySociety::Locale::in_gb_locale { @@ -145,14 +149,13 @@ sub email_alerts ($) { }; my $states = "'" . join( "', '", FixMyStreet::DB::Result::Problem::visible_states() ) . "'"; my %data = ( template => $template, data => '', alert_id => $alert->id, alert_email => $alert->user->email, lang => $alert->lang, cobrand => $alert->cobrand, cobrand_data => $alert->cobrand_data ); - my $q = "select problem.id, problem.postcode, problem.geocode, problem.title from problem_find_nearby(?, ?, ?) as nearby, problem, users + my $q = "select problem.id, problem.council, problem.postcode, problem.geocode, problem.title from problem_find_nearby(?, ?, ?) as nearby, problem, users where nearby.problem_id = problem.id and problem.user_id = users.id and problem.state in ($states) and problem.confirmed >= ? and problem.confirmed >= ms_current_timestamp() - '7 days'::interval and (select whenqueued from alert_sent where alert_sent.alert_id = ? and alert_sent.parameter::integer = problem.id) is null and users.email <> ? - $site_restriction order by confirmed desc"; $q = dbh()->prepare($q); $q->execute($latitude, $longitude, $d, $alert->whensubscribed, $alert->id, $alert->user->email); @@ -161,6 +164,10 @@ sub email_alerts ($) { alert_id => $alert->id, parameter => $row->{id}, } ); + my $url = $cobrand->base_url_for_emails( $alert->cobrand_data ); + if ( $hashref_restriction && $hashref_restriction->{council} && $row->{council} ne $hashref_restriction->{council} ) { + $url = mySociety::Config::get('BASE_URL'); + } my $postcode = $cobrand->format_postcode( $row->{postcode} ); $postcode = ", $postcode" if $postcode; $data{data} .= $url . "/report/" . $row->{id} . " - $row->{title}$postcode\n\n"; diff --git a/perllib/FixMyStreet/SendReport/Barnet.pm b/perllib/FixMyStreet/SendReport/Barnet.pm index 9a54dd91d..ecbe82872 100644 --- a/perllib/FixMyStreet/SendReport/Barnet.pm +++ b/perllib/FixMyStreet/SendReport/Barnet.pm @@ -149,14 +149,21 @@ sub send { 'string' => $result->get_faultstring(), 'detail' => $result->get_detail(), # possibly only contains debug info ); - $fault{$_}=~s/^\s*|\s*$//g foreach keys %fault; + foreach (keys %fault) { + $fault{$_}="" unless defined $fault{$_}; + $fault{$_}=~s/^\s*|\s*$//g; + } $fault{actor}&&=" (actor: $fault{actor})"; $fault{'detail'} &&= "\n" . $fault{'detail'}; $err_msg = "Failed (problem id $h{id}): Fault $fault{code}$fault{actor}\n$fault{string}$fault{detail}"; } }; - print "$err_msg\n" if $err_msg; + if ($err_msg) { + # for timeouts, we can tidy the message a wee bit (i.e. strip the 'error deserializing...' message) + $err_msg=~s/(?:Error deserializing message:.*)(Can't connect to [a-zA-Z0-9.:]+\s*\(Connection timed out\)).*/$1/s; + print "$err_msg\n"; + } if ($@) { my $e = shift; print "Caught an error: $@\n"; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index 845a6295c..9bb33b9ef 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -54,7 +54,6 @@ sub send { $always_send_latlong = 0; $send_notpinpointed = 1; - $basic_desc = 1; } @@ -93,6 +92,7 @@ sub send { if ( $resp ) { $row->external_id( $resp ); + $row->send_method_used('Open311'); $result *= 0; $self->success( 1 ); } else { |