aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm9
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm11
-rw-r--r--perllib/FixMyStreet/App/Controller/Root.pm7
-rw-r--r--perllib/FixMyStreet/Cobrand/Default.pm5
-rw-r--r--perllib/FixMyStreet/Cobrand/UK.pm4
-rw-r--r--perllib/FixMyStreet/DB/Result/Contact.pm6
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm6
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/AlertType.pm4
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Nearby.pm1
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm4
-rw-r--r--perllib/FixMyStreet/Geocode/OSM.pm4
-rw-r--r--perllib/FixMyStreet/TestMech.pm106
14 files changed, 163 insertions, 18 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index f05639b41..2d1cf2c5a 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -301,6 +301,7 @@ 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 );
@@ -649,6 +650,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
@@ -656,8 +658,10 @@ 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 )
{
+ warn "edited";
$edited = 1;
}
@@ -667,6 +671,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(
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 57d27b3e4..a7e1e8a3a 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -91,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',
+ [ _('That report cannot be viewed on FixMyStreet.') ] #
+ );
+ }
}
$c->stash->{problem} = $problem;
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index b18e6e39f..a4462e035 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -595,6 +595,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 +648,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 +667,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;
@@ -872,6 +877,10 @@ 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 ) {
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 37766db44..444389ec2 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -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';
@@ -236,6 +229,7 @@ sub council_check : Private {
type => $area_types,
min_generation => $c->cobrand->area_min_generation
);
+
if (keys %$areas == 1) {
($c->stash->{council}) = values %$areas;
return;
@@ -318,7 +312,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} . ',%' };
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/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm
index 64e08f44c..cfc9455b5 100644
--- a/perllib/FixMyStreet/Cobrand/Default.pm
+++ b/perllib/FixMyStreet/Cobrand/Default.pm
@@ -4,6 +4,7 @@ use base 'FixMyStreet::Cobrand::Base';
use strict;
use warnings;
use FixMyStreet;
+use Encode;
use URI;
use Digest::MD5 qw(md5_hex);
@@ -674,7 +675,9 @@ sub _fallback_council_sender {
};
sub example_places {
- return FixMyStreet->config('EXAMPLE_PLACES') || [ 'High Street', 'Main Street' ];
+ my $e = FixMyStreet->config('EXAMPLE_PLACES') || [ 'High Street', 'Main Street' ];
+ $e = [ map { Encode::decode('UTF-8', $_) } @$e ];
+ return $e;
}
=head2 only_authed_can_create
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm
index feb3c9ecf..75f6ba061 100644
--- a/perllib/FixMyStreet/Cobrand/UK.pm
+++ b/perllib/FixMyStreet/Cobrand/UK.pm
@@ -145,13 +145,13 @@ sub find_closest {
my $str = $self->SUPER::find_closest( $latitude, $longitude, $problem );
# Get nearest postcode from Matthew's random gazetteer (put in MaPit? Or elsewhere?)
- my $url = "http://gazetteer.dracos.vm.bytemark.co.uk/point/$latitude,$longitude.json";
+ my $url = "http://mapit.mysociety.org/nearest/4326/$longitude,$latitude";
my $j = LWP::Simple::get($url);
if ($j) {
$j = JSON->new->utf8->allow_nonref->decode($j);
if ($j->{postcode}) {
$str .= sprintf(_("Nearest postcode to the pin placed on the map (automatically generated): %s (%sm away)"),
- $j->{postcode}[0], $j->{postcode}[1]) . "\n\n";
+ $j->{postcode}{postcode}, $j->{postcode}{distance}) . "\n\n";
}
}
diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm
index 2a6ffa2fe..993e3524b 100644
--- a/perllib/FixMyStreet/DB/Result/Contact.pm
+++ b/perllib/FixMyStreet/DB/Result/Contact.pm
@@ -36,6 +36,8 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 0 },
"extra",
{ data_type => "text", is_nullable => 1 },
+ "non_public",
+ { data_type => "boolean", default_value => \"false", is_nullable => 1 },
"endpoint",
{ data_type => "text", is_nullable => 1 },
"jurisdiction",
@@ -49,8 +51,8 @@ __PACKAGE__->set_primary_key("id");
__PACKAGE__->add_unique_constraint("contacts_area_id_category_idx", ["area_id", "category"]);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-29 17:34:28
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:getDAgTeXkAYQTcxHWflmA
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-31 10:29:17
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:t6yOPhZmedV/eH6AUvHI6w
__PACKAGE__->filter_column(
extra => {
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index af62a299b..761f57b01 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -92,6 +92,8 @@ __PACKAGE__->add_columns(
{ data_type => "timestamp", is_nullable => 1 },
"send_method_used",
{ data_type => "text", is_nullable => 1 },
+ "non_public",
+ { data_type => "boolean", default_value => \"false", is_nullable => 1 },
"external_source",
{ data_type => "text", is_nullable => 1 },
"external_source_id",
@@ -120,8 +122,8 @@ __PACKAGE__->belongs_to(
);
-# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-23 12:14:00
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:05LIWlb0CUWAR7bN5RAhOA
+# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-31 10:25:34
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:mudIAiLAUdmK8gGWIPiq6g
# Add fake relationship to stored procedure table
__PACKAGE__->has_one(
diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
index a0320ccc3..2d206d84e 100644
--- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
@@ -65,6 +65,9 @@ sub email_alerts ($) {
# call checks if this is the host that sends mail for this cobrand.
next unless $cobrand->email_host;
+ # this is for the new_updates alerts
+ next if $row->{non_public} and $row->{user_id} != $row->{alert_user_id};
+
my $hashref_restriction = $cobrand->site_restriction( $row->{cobrand_data} );
FixMyStreet::App->model('DB::AlertSent')->create( {
@@ -151,6 +154,7 @@ sub email_alerts ($) {
where nearby.problem_id = problem.id
and problem.user_id = users.id
and problem.state in ($states)
+ and problem.non_public = 'f'
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 <> ?
diff --git a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
index 83fc85a88..191223572 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Nearby.pm
@@ -8,6 +8,7 @@ sub nearby {
my ( $rs, $c, $dist, $ids, $limit, $mid_lat, $mid_lon, $interval ) = @_;
my $params = {
+ non_public => 0,
state => [ FixMyStreet::DB::Result::Problem::visible_states() ],
};
$params->{'current_timestamp-lastupdate'} = { '<', \"'$interval'::interval" }
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index e946e01c2..f7f88edf0 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -85,7 +85,8 @@ sub _recent {
$key .= ":$site_key:$num";
my $query = {
- state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
+ non_public => 0,
+ state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
};
$query->{photo} = { '!=', undef } if $photos;
@@ -141,6 +142,7 @@ sub around_map {
$attr->{rows} = $limit if $limit;
my $q = {
+ non_public => 0,
state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
latitude => { '>=', $min_lat, '<', $max_lat },
longitude => { '>=', $min_lon, '<', $max_lon },
diff --git a/perllib/FixMyStreet/Geocode/OSM.pm b/perllib/FixMyStreet/Geocode/OSM.pm
index ba939b443..78db7fe44 100644
--- a/perllib/FixMyStreet/Geocode/OSM.pm
+++ b/perllib/FixMyStreet/Geocode/OSM.pm
@@ -15,9 +15,10 @@ use Digest::MD5 qw(md5_hex);
use Encode;
use File::Slurp;
use File::Path ();
-use LWP::Simple;
+use LWP::Simple qw($ua);
use Memcached;
use XML::Simple;
+use mySociety::Locale;
my $osmapibase = "http://www.openstreetmap.org/api/";
my $nominatimbase = "http://nominatim.openstreetmap.org/";
@@ -49,6 +50,7 @@ sub string {
if (-s $cache_file) {
$js = File::Slurp::read_file($cache_file);
} else {
+ $ua->timeout(15);
$js = LWP::Simple::get($url);
$js = encode_utf8($js) if utf8::is_utf8($js);
File::Path::mkpath($cache_dir);
diff --git a/perllib/FixMyStreet/TestMech.pm b/perllib/FixMyStreet/TestMech.pm
index 2a49cc2f8..5866ee21c 100644
--- a/perllib/FixMyStreet/TestMech.pm
+++ b/perllib/FixMyStreet/TestMech.pm
@@ -378,6 +378,49 @@ sub extract_update_metas {
return \@metas;
}
+=head2 extract_problem_list
+
+ $problems = $mech->extract_problem_list
+
+Returns an array ref of all problem titles on a page featuring standard issue lists
+
+=cut
+
+sub extract_problem_list {
+ my $mech = shift;
+
+ my $result = scraper {
+ process 'ul.issue-list-a li a h4', 'problems[]', 'TEXT';
+ }->scrape( $mech->response );
+
+ return $result->{ problems } || [];
+}
+
+=head2 extract_report_stats
+
+ $stats = $mech->extract_report_stats
+
+Returns a hash ref keyed by council name of all the council stats from the all reports
+page. Each value is an array ref with the first element being the council name and the
+rest being the stats in the order the appear in each row.
+
+=cut
+
+sub extract_report_stats {
+ my $mech = shift;
+
+ my $result = scraper {
+ process 'tr[align=center]', 'councils[]' => scraper {
+ process 'td.title a', 'council', 'TEXT',
+ process 'td', 'stats[]', 'TEXT'
+ }
+ }->scrape( $mech->response );
+
+ my %councils = map { $_->{council} => $_->{stats} } @{ $result->{councils} };
+
+ return \%councils;
+}
+
=head2 visible_form_values
$hashref = $mech->visible_form_values( );
@@ -475,4 +518,67 @@ sub get_ok_json {
return decode_json( $res->content );
}
+sub delete_problems_for_council {
+ my $mech = shift;
+ my $council = shift;
+
+ my $reports = FixMyStreet::App->model('DB::Problem')->search( { council => $council } );
+ if ( $reports ) {
+ for my $r ( $reports->all ) {
+ $r->comments->delete;
+ }
+ $reports->delete;
+ }
+}
+
+sub create_problems_for_council {
+ my ( $mech, $count, $council, $title, $params ) = @_;
+
+ my $dt = $params->{dt} || DateTime->now();
+
+ my $user = $params->{user} ||
+ FixMyStreet::App->model('DB::User')
+ ->find_or_create( { email => 'test@example.com', name => 'Test User' } );
+
+ delete $params->{user};
+ delete $params->{dt};
+
+ my @problems;
+
+ while ($count) {
+ my $default_params = {
+ postcode => 'SW1A 1AA',
+ council => $council,
+ areas => ',105255,11806,11828,2247,2504,',
+ category => 'Other',
+ title => "$title Test $count for $council",
+ detail => "$title Test $count for $council Detail",
+ used_map => 't',
+ name => 'Test User',
+ anonymous => 'f',
+ state => 'confirmed',
+ confirmed => $dt->ymd . ' ' . $dt->hms,
+ lang => 'en-gb',
+ service => '',
+ cobrand => 'default',
+ cobrand_data => '',
+ send_questionnaire => 't',
+ latitude => '51.5016605453401',
+ longitude => '-0.142497580865087',
+ user_id => $user->id,
+ photo => 1,
+ };
+
+ my %report_params = ( %$default_params, %$params );
+
+ my $problem =
+ FixMyStreet::App->model('DB::Problem')->create( \%report_params );
+
+ push @problems, $problem;
+ $count--;
+ }
+
+ return @problems;
+}
+
1;