diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 86 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Oxfordshire.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 38 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm | 22 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Bing.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Bristol.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Bromley.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/GoogleOL.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM/CycleMap.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM/MapQuest.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/OSM/StreetView.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/WMTSBase.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/Map/Zurich.pm | 4 |
18 files changed, 155 insertions, 72 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index e91597bb0..bbdf449aa 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -129,7 +129,7 @@ sub index : Path : Args(0) { sub config_page : Path( 'config' ) : Args(0) { my ($self, $c) = @_; - my $dir = $c->stash->{additional_template_paths}->[0]; + my $dir = FixMyStreet->path_to(); my $git_version = `cd $dir && git describe --tags`; chomp $git_version; $c->stash( @@ -1377,7 +1377,7 @@ sub user_edit : Path('user_edit') : Args(1) { } if ( $user->from_body ) { - unless ( $c->stash->{body} && $user->from_body->id eq $c->stash->{body}->id ) { + unless ( $c->stash->{live_contacts} ) { $c->stash->{body} = $user->from_body; $c->forward('fetch_contacts'); } diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 73479c584..5a1cfbe54 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -231,13 +231,8 @@ sub generate_map_tags : Private { latitude => $problem->latitude, longitude => $problem->longitude, pins => $problem->used_map - ? [ { - latitude => $problem->latitude, - longitude => $problem->longitude, - colour => $c->cobrand->pin_colour($problem, 'report'), - type => 'big', - } ] - : [], + ? [ $problem->pin_data($c, 'report', type => 'big') ] + : [], ); return 1; @@ -300,6 +295,7 @@ sub action_router : Path('') : Args(2) { my ( $self, $c, $id, $action ) = @_; $c->go( 'map', [ $id ] ) if $action eq 'map'; + $c->go( 'nearby_json', [ $id ] ) if $action eq 'nearby.json'; $c->detach( '/page_error_404_not_found', [] ); } @@ -312,15 +308,38 @@ sub inspect : Private { $c->stash->{categories} = $c->forward('/admin/categories_for_point'); $c->stash->{report_meta} = { map { $_->{name} => $_ } @{ $c->stash->{problem}->get_extra_fields() } }; + my %category_body = map { $_->category => $_->body_id } map { $_->contacts->all } values %{$problem->bodies}; + + my @priorities = $c->model('DB::ResponsePriority')->for_bodies($problem->bodies_str_ids)->all; + my $priorities_by_category = {}; + foreach my $pri (@priorities) { + my $any = 0; + foreach ($pri->contacts->all) { + $any = 1; + push @{$priorities_by_category->{$_->category}}, $pri->id . '=' . URI::Escape::uri_escape_utf8($pri->name); + } + if (!$any) { + foreach (grep { $category_body{$_} == $pri->body_id } @{$c->stash->{categories}}) { + push @{$priorities_by_category->{$_}}, $pri->id . '=' . URI::Escape::uri_escape_utf8($pri->name); + } + } + } + foreach (keys %{$priorities_by_category}) { + $priorities_by_category->{$_} = join('&', @{$priorities_by_category->{$_}}); + } + + $c->stash->{priorities_by_category} = $priorities_by_category; + if ( $c->get_param('save') ) { $c->forward('/auth/check_csrf_token'); my $valid = 1; my $update_text; my $reputation_change = 0; + my %update_params = (); if ($permissions->{report_inspect}) { - foreach (qw/detailed_information traffic_information/) { + foreach (qw/detailed_information traffic_information duplicate_of/) { $problem->set_extra_metadata( $_ => $c->get_param($_) ); } @@ -345,15 +364,19 @@ sub inspect : Private { if ( $problem->state eq 'hidden' ) { $problem->get_photoset->delete_cached; } + if ( $problem->state eq 'duplicate' && $old_state ne 'duplicate' ) { + # If the report is being closed as duplicate, make sure the + # update records this. + $update_params{problem_state} = "duplicate"; + } + if ( $problem->state ne 'duplicate' ) { + $problem->unset_extra_metadata('duplicate_of'); + } if ( $problem->state ne $old_state ) { $c->forward( '/admin/log_edit', [ $problem->id, 'problem', 'state_change' ] ); } } - if ($c->get_param('priority') && ($permissions->{report_inspect} || $permissions->{report_edit_priority})) { - $problem->response_priority( $problem->response_priorities->find({ id => $c->get_param('priority') }) ); - } - if ( !$c->forward( '/admin/report_edit_location', [ $problem ] ) ) { # New lat/lon isn't valid, show an error $valid = 0; @@ -373,10 +396,16 @@ sub inspect : Private { $c->forward('/report/new/set_report_extras', [ \@contacts, $param_prefix ]); } + # Updating priority must come after category, in case category has changed (and so might have priorities) + if ($c->get_param('priority') && ($permissions->{report_inspect} || $permissions->{report_edit_priority})) { + $problem->response_priority( $problem->response_priorities->find({ id => $c->get_param('priority') }) ); + } + if ($valid) { if ( $reputation_change != 0 ) { $problem->user->update_reputation($reputation_change); } + $problem->lastupdate( \'current_timestamp' ); $problem->update; if ( defined($update_text) ) { $problem->add_to_comments( { @@ -388,6 +417,7 @@ sub inspect : Private { state => 'confirmed', mark_fixed => 0, anonymous => 0, + %update_params, } ); } # This problem might no longer be visible on the current cobrand, @@ -416,6 +446,38 @@ sub map : Private { } +sub nearby_json : Private { + my ( $self, $c, $id ) = @_; + + $c->forward( 'load_problem_or_display_error', [ $id ] ); + my $p = $c->stash->{problem}; + my $dist = 1000; + + my $nearby = $c->model('DB::Nearby')->nearby( + $c, $dist, [ $p->id ], 5, $p->latitude, $p->longitude, undef, [ $p->category ], undef + ); + my @pins = map { + my $p = $_->problem; + my $colour = $c->cobrand->pin_colour( $p, 'around' ); + [ $p->latitude, $p->longitude, + $colour, + $p->id, $p->title_safe, 'small', JSON->false + ] + } @$nearby; + + my $on_map_list_html = $c->render_fragment( + 'around/on_map_list_items.html', + { on_map => [], around_map => $nearby } + ); + + my $json = { pins => \@pins }; + $json->{current} = $on_map_list_html if $on_map_list_html; + my $body = encode_json($json); + $c->res->content_type('application/json; charset=utf-8'); + $c->res->body($body); +} + + =head2 check_has_permission_to Ensure the currently logged-in user has any of the provided permissions applied diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index a2ca9f8c1..27111deb2 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -1184,6 +1184,7 @@ Return true if an Open311 service attribute should be a hidden field. sub category_extra_hidden { my ($self, $meta) = @_; + return 0; } 1; diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index a476b5e9b..dca208e98 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -119,4 +119,6 @@ sub contact_email { return join( '@', 'highway.enquiries', 'oxfordshire.gov.uk' ); } +sub admin_user_domain { 'oxfordshire.gov.uk' } + 1; diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index 42c9c5cbc..c22224307 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -55,8 +55,9 @@ sub updates_restriction { sub users_restriction { my ($self, $rs) = @_; - # Council admins can only see users who are members of the same council or - # users who have sent a report or update to that council. + # Council admins can only see users who are members of the same council, + # have an email address in a specified domain, or users who have sent a + # report or update to that council. my $problem_user_ids = $self->problems->search( undef, @@ -73,10 +74,16 @@ sub users_restriction { } )->as_query; - return $rs->search([ + my $or_query = [ from_body => $self->council_id, id => [ { -in => $problem_user_ids }, { -in => $update_user_ids } ], - ]); + ]; + if ($self->can('admin_user_domain')) { + my $domain = $self->admin_user_domain; + push @$or_query, email => { ilike => "%\@$domain" }; + } + + return $rs->search($or_query); } sub base_url { diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index f421394fa..203e72fae 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -181,6 +181,7 @@ use namespace::clean -except => [ 'meta' ]; use Utils; use FixMyStreet::Map::FMS; use LWP::Simple qw($ua); +use RABX; my $IM = eval { require Image::Magick; @@ -475,7 +476,7 @@ sub confirm { sub bodies_str_ids { my $self = shift; - return unless $self->bodies_str; + return [] unless $self->bodies_str; my @bodies = split( /,/, $self->bodies_str ); return \@bodies; } @@ -680,16 +681,7 @@ alphabetical order of name. sub response_priorities { my $self = shift; - return $self->result_source->schema->resultset('ResponsePriority')->search( - { - 'me.body_id' => $self->bodies_str_ids, - 'contact.category' => [ $self->category, undef ], - }, - { - order_by => 'name', - join => { 'contact_response_priorities' => 'contact' }, - } - ); + return $self->result_source->schema->resultset('ResponsePriority')->for_bodies($self->bodies_str_ids, $self->category); } # returns true if the external id is the council's ref, i.e., useful to publish it @@ -941,6 +933,7 @@ sub pin_data { id => $self->id, title => $opts{private} ? $self->title : $self->title_safe, problem => $self, + type => $opts{type}, } }; @@ -1032,4 +1025,27 @@ has shortlisted_user => ( }, ); +has duplicate_of => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + return unless $self->state eq 'duplicate'; + my $duplicate_of = int($self->get_extra_metadata("duplicate_of") || 0); + return unless $duplicate_of; + return $self->result_source->schema->resultset('Problem')->search({ id => $duplicate_of })->first; + }, +); + +has duplicates => ( + is => 'ro', + lazy => 1, + default => sub { + my $self = shift; + my $rabx_id = RABX::serialise( $self->id ); + my @duplicates = $self->result_source->schema->resultset('Problem')->search({ extra => { like => "\%duplicate_of,$rabx_id%" } })->all; + return \@duplicates; + }, +); + 1; diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 028394795..f4e5144f8 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -268,7 +268,7 @@ sub has_permission_to { my ($self, $permission_type, $body_ids) = @_; return 1 if $self->is_superuser; - return 0 unless $body_ids; + return 0 if !$body_ids || (ref $body_ids && !@$body_ids); my $permission = $self->user_body_permissions->find({ permission_type => $permission_type, diff --git a/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm b/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm new file mode 100644 index 000000000..aa9c426f4 --- /dev/null +++ b/perllib/FixMyStreet/DB/ResultSet/ResponsePriority.pm @@ -0,0 +1,22 @@ +package FixMyStreet::DB::ResultSet::ResponsePriority; +use base 'DBIx::Class::ResultSet'; + +use strict; +use warnings; + +sub for_bodies { + my ($rs, $bodies, $category) = @_; + my $attrs = { + 'me.body_id' => $bodies, + }; + if ($category) { + $attrs->{'contact.category'} = [ $category, undef ]; + } + $rs->search($attrs, { + order_by => 'name', + join => { 'contact_response_priorities' => 'contact' }, + distinct => 1, + }); +} + +1; diff --git a/perllib/FixMyStreet/Map/Bing.pm b/perllib/FixMyStreet/Map/Bing.pm index 4c1887641..617823b45 100644 --- a/perllib/FixMyStreet/Map/Bing.pm +++ b/perllib/FixMyStreet/Map/Bing.pm @@ -6,8 +6,7 @@ use base 'FixMyStreet::Map::OSM'; use strict; -# Is set by the JavaScript -sub map_type { '""' } +sub map_type { '' } sub map_template { 'bing' } diff --git a/perllib/FixMyStreet/Map/Bristol.pm b/perllib/FixMyStreet/Map/Bristol.pm index 3b60d1acf..c2925ff8d 100644 --- a/perllib/FixMyStreet/Map/Bristol.pm +++ b/perllib/FixMyStreet/Map/Bristol.pm @@ -60,9 +60,7 @@ sub copyright { return '© BCC'; } -sub map_type { - return 'bristol'; -} +sub map_template { 'bristol' } # Reproject a WGS84 lat/lon into BNG easting/northing sub reproject_from_latlon($$$) { diff --git a/perllib/FixMyStreet/Map/Bromley.pm b/perllib/FixMyStreet/Map/Bromley.pm index fc8726b34..0cd36a2ac 100644 --- a/perllib/FixMyStreet/Map/Bromley.pm +++ b/perllib/FixMyStreet/Map/Bromley.pm @@ -9,9 +9,7 @@ use base 'FixMyStreet::Map::FMS'; use strict; -sub map_type { - return '[ [ "", "a-" ], "https://{S}fix.bromley.gov.uk/tilma" ]'; -} +sub map_template { 'bromley' } sub map_tile_base { '-', "https://%sfix.bromley.gov.uk/tilma/%d/%d/%d.png"; diff --git a/perllib/FixMyStreet/Map/GoogleOL.pm b/perllib/FixMyStreet/Map/GoogleOL.pm index 2dfb697e5..55032d707 100644 --- a/perllib/FixMyStreet/Map/GoogleOL.pm +++ b/perllib/FixMyStreet/Map/GoogleOL.pm @@ -9,12 +9,8 @@ use parent 'FixMyStreet::Map::OSM'; use strict; -sub map_type { - return '""'; -} +sub map_type { '' } -sub map_template { - return 'google-ol'; -} +sub map_template { 'google-ol' } 1; diff --git a/perllib/FixMyStreet/Map/OSM.pm b/perllib/FixMyStreet/Map/OSM.pm index d4000f1a4..76af99d36 100644 --- a/perllib/FixMyStreet/Map/OSM.pm +++ b/perllib/FixMyStreet/Map/OSM.pm @@ -14,13 +14,9 @@ use Utils; use constant ZOOM_LEVELS => 6; use constant MIN_ZOOM_LEVEL => 13; -sub map_type { - return 'OpenLayers.Layer.OSM.Mapnik'; -} +sub map_type { 'OpenLayers.Layer.OSM.Mapnik' } -sub map_template { - return 'osm'; -} +sub map_template { 'osm' } sub map_tiles { my ( $self, %params ) = @_; diff --git a/perllib/FixMyStreet/Map/OSM/CycleMap.pm b/perllib/FixMyStreet/Map/OSM/CycleMap.pm index 8f1de39d2..bb6aefc8c 100644 --- a/perllib/FixMyStreet/Map/OSM/CycleMap.pm +++ b/perllib/FixMyStreet/Map/OSM/CycleMap.pm @@ -9,9 +9,7 @@ use base 'FixMyStreet::Map::OSM'; use strict; -sub map_type { - return 'OpenLayers.Layer.OSM.CycleMap'; -} +sub map_type { 'OpenLayers.Layer.OSM.CycleMap' } sub base_tile_url { return 'tile.opencyclemap.org/cycle'; diff --git a/perllib/FixMyStreet/Map/OSM/MapQuest.pm b/perllib/FixMyStreet/Map/OSM/MapQuest.pm index 3b0df14b1..ac80e61b5 100644 --- a/perllib/FixMyStreet/Map/OSM/MapQuest.pm +++ b/perllib/FixMyStreet/Map/OSM/MapQuest.pm @@ -9,13 +9,9 @@ use base 'FixMyStreet::Map::OSM'; use strict; -sub map_type { - return 'OpenLayers.Layer.OSM.MapQuestOpen'; -} +sub map_type { 'OpenLayers.Layer.OSM.MapQuestOpen' } -sub map_template { - return 'mapquest-attribution'; -} +sub map_template { 'mapquest-attribution' } sub map_tiles { my ( $self, %params ) = @_; diff --git a/perllib/FixMyStreet/Map/OSM/StreetView.pm b/perllib/FixMyStreet/Map/OSM/StreetView.pm index f37deaaae..12fbdb19d 100644 --- a/perllib/FixMyStreet/Map/OSM/StreetView.pm +++ b/perllib/FixMyStreet/Map/OSM/StreetView.pm @@ -9,13 +9,9 @@ use base 'FixMyStreet::Map::OSM'; use strict; -sub map_type { - return '""'; -} +sub map_type { '' } -sub map_template { - return 'osm-streetview'; -} +sub map_template { 'osm-streetview' } sub base_tile_url { return 'os.openstreetmap.org/sv'; diff --git a/perllib/FixMyStreet/Map/WMTSBase.pm b/perllib/FixMyStreet/Map/WMTSBase.pm index 909ada1d6..960a58a41 100644 --- a/perllib/FixMyStreet/Map/WMTSBase.pm +++ b/perllib/FixMyStreet/Map/WMTSBase.pm @@ -59,9 +59,7 @@ sub tile_parameters { } # This is used to determine which template to render the map with -sub map_type { - return 'fms'; -} +sub map_template { 'fms' } # Reproject a WGS84 lat/lon into an x/y coordinate in this map's CRS. # Subclasses will want to override this. @@ -198,7 +196,7 @@ sub get_map_hash { my @scales = $self->scales; return { %params, - type => $self->map_type, + type => $self->map_template, map_type => 'OpenLayers.Layer.WMTS', tiles => $self->map_tiles( %params ), copyright => $self->copyright(), diff --git a/perllib/FixMyStreet/Map/Zurich.pm b/perllib/FixMyStreet/Map/Zurich.pm index 1e302bdda..ed68daeee 100644 --- a/perllib/FixMyStreet/Map/Zurich.pm +++ b/perllib/FixMyStreet/Map/Zurich.pm @@ -67,9 +67,7 @@ sub copyright { return '© Stadt Zürich'; } -sub map_type { - return 'zurich'; -} +sub map_template { 'zurich' } # Reproject a WGS84 lat/lon into Swiss easting/northing |