diff options
Diffstat (limited to 'perllib/FixMyStreet/App')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 37 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 83 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 15 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Tokens.pm | 1 |
7 files changed, 135 insertions, 12 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 2aaa488d6..a34737844 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -217,7 +217,10 @@ sub council_list : Path('council_list') : Args(0) { $c->stash->{edit_activity} = $edit_activity; - my @area_types = $c->cobrand->area_types; + # Not London, as treated separately + my @area_types = $c->cobrand->moniker eq 'emptyhomes' + ? $c->cobrand->area_types + : grep { $_ ne 'LBO' } $c->cobrand->area_types; my $areas = mySociety::MaPit::call('areas', \@area_types); my @councils_ids = sort { strcoll($areas->{$a}->{name}, $areas->{$b}->{name}) } keys %$areas; @@ -331,6 +334,32 @@ sub update_contacts : Private { ); $c->stash->{updated} = _('Values updated'); + } elsif ( $posted eq 'open311' ) { + $c->forward('check_token'); + + my %params = map { $_ => $c->req->param($_) } qw/open311_id endpoint jurisdiction api_key area_id/; + + if ( $params{open311_id} ) { + my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } ); + + $conf->endpoint( $params{endpoint} ); + $conf->jurisdiction( $params{jurisdiction} ); + $conf->api_key( $params{api_key} ); + + $conf->update(); + + $c->stash->{updated} = _('Configuration updated'); + } else { + my $conf = $c->model('DB::Open311Conf')->find_or_new( { area_id => $params{area_id} } ); + + $conf->endpoint( $params{endpoint} ); + $conf->jurisdiction( $params{jurisdiction} ); + $conf->api_key( $params{api_key} ); + + $conf->insert(); + + $c->stash->{updated} = _('Configuration updated - contacts will be generated automatically later'); + } } } @@ -348,6 +377,12 @@ sub display_contacts : Private { $c->stash->{contacts} = $contacts; + my $open311 = $c->model('DB::Open311Conf')->search( + { area_id => $area_id } + ); + + $c->stash->{open311} = $open311; + if ( $c->req->param('text') && $c->req->param('text') == 1 ) { $c->stash->{template} = 'admin/council_contacts.txt'; $c->res->content_type('text/plain; charset=utf-8'); diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 72d6ac62b..148a22368 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -182,7 +182,7 @@ sub display_location : Private { # create a list of all the pins my @pins; - unless ($c->req->param('no_pins')) { + unless ($c->req->param('no_pins') || $c->cobrand->moniker eq 'emptyhomes') { @pins = map { # Here we might have a DB::Problem or a DB::Nearby, we always want the problem. my $p = (ref $_ eq 'FixMyStreet::App::Model::DB::Nearby') ? $_->problem : $_; diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index f16bd5393..e982d6a4c 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -15,6 +15,7 @@ use Path::Class; use Utils; use mySociety::EmailUtil; use mySociety::TempFiles; +use JSON; =head1 NAME @@ -113,11 +114,48 @@ sub report_form_ajax : Path('ajax') : Args(0) { # render templates to get the html my $category = $c->view('Web')->render( $c, 'report/new/category.html'); my $councils_text = $c->view('Web')->render( $c, 'report/new/councils_text.html'); + my $has_open311 = keys %{ $c->stash->{category_extras} }; my $body = JSON->new->utf8(1)->encode( { - councils_text => $councils_text, - category => $category, + councils_text => $councils_text, + category => $category, + has_open311 => $has_open311, + } + ); + + $c->res->content_type('application/json; charset=utf-8'); + $c->res->body($body); +} + +sub category_extras_ajax : Path('category_extras') : Args(0) { + my ( $self, $c ) = @_; + + $c->forward('initialize_report'); + if ( ! $c->forward('determine_location') ) { + my $body = JSON->new->utf8(1)->encode( + { + error => _("Sorry, we could not find that location."), + } + ); + $c->res->content_type('application/json; charset=utf-8'); + $c->res->body($body); + return 1; + } + $c->forward('setup_categories_and_councils'); + + my $category_extra = ''; + if ( $c->stash->{category_extras}->{ $c->req->param('category') } ) { + $c->stash->{report_meta} = {}; + $c->stash->{report} = { category => $c->req->param('category') }; + $c->stash->{category_extras} = { $c->req->param('category' ) => $c->stash->{category_extras}->{ $c->req->param('category') } }; + + $category_extra= $c->view('Web')->render( $c, 'report/new/category_extras.html'); + } + + my $body = JSON->new->utf8(1)->encode( + { + category_extra => $category_extra, } ); @@ -476,6 +514,7 @@ sub setup_categories_and_councils : Private { my %area_ids_to_list = (); # Areas with categories assigned my @category_options = (); # categories to show my $category_label = undef; # what to call them + my %category_extras = (); # extra fields to fill in for open311 # FIXME - implement in cobrand if ( $c->cobrand->moniker eq 'emptyhomes' ) { @@ -522,8 +561,12 @@ sub setup_categories_and_councils : Private { next if $contact->category eq _('Other'); - push @category_options, $contact->category - unless $seen{$contact->category}; + unless ( $seen{$contact->category} ) { + push @category_options, $contact->category; + + $category_extras{ $contact->category } = $contact->extra + if $contact->extra; + } $seen{$contact->category} = 1; } @@ -538,6 +581,8 @@ sub setup_categories_and_councils : Private { $c->stash->{area_ids_to_list} = [ keys %area_ids_to_list ]; $c->stash->{category_label} = $category_label; $c->stash->{category_options} = \@category_options; + $c->stash->{category_extras} = \%category_extras; + $c->stash->{category_extras_json} = encode_json \%category_extras; my @missing_details_councils = grep { !$area_ids_to_list{$_} } # @@ -716,6 +761,26 @@ sub process_report : Private { if $council_string && @{ $c->stash->{missing_details_councils} }; $report->council($council_string); + my @extra = (); + my $metas = $contacts[0]->extra; + + foreach my $field ( @$metas ) { + if ( lc( $field->{required} ) eq 'true' ) { + unless ( $c->request->param( $field->{code} ) ) { + $c->stash->{field_errors}->{ $field->{code} } = _('This information is required'); + } + } + push @extra, { + name => $field->{code}, + description => $field->{description}, + value => $c->request->param( $field->{code} ) || '', + }; + } + + if ( @extra ) { + $c->stash->{report_meta} = \@extra; + $report->extra( \@extra ); + } } elsif ( @{ $c->stash->{area_ids_to_list} } ) { # There was an area with categories, but we've not been given one. Bail. @@ -881,6 +946,16 @@ sub save_user_and_report : Private { # Save or update the user if appropriate if ( !$report->user->in_storage ) { + # User does not exist. + # Store changes in token for when token is validated. + $c->stash->{token_data} = { + name => $report->user->name, + phone => $report->user->phone, + password => $report->user->password, + }; + $report->user->name( undef ); + $report->user->phone( undef ); + $report->user->password( '', 1 ); $report->user->insert(); } elsif ( $c->user && $report->user->id == $c->user->id ) { diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index add9d1371..c67ca4d1f 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -255,6 +255,14 @@ sub save_update : Private { my $update = $c->stash->{update}; if ( !$update->user->in_storage ) { + # User does not exist. + # Store changes in token for when token is validated. + $c->stash->{token_data} = { + name => $update->user->name, + password => $update->user->password, + }; + $update->user->name( undef ); + $update->user->password( '', 1 ); $update->user->insert; } elsif ( $c->user && $c->user->id == $update->user->id ) { diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 93af3393c..0587a627a 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -110,6 +110,8 @@ sub ward : Path : Args(2) { $c->stash->{council_url} = '/reports/' . $council_short; + $c->stash->{stats} = $c->cobrand->get_report_stats(); + my $pins = $c->stash->{pins}; $c->stash->{page} = 'reports'; # So the map knows to make clickable pins @@ -338,7 +340,7 @@ sub load_and_group_problems : Private { $where, { columns => [ - 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', + 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', { duration => { extract => "epoch from current_timestamp-lastupdate" } }, { age => { extract => "epoch from current_timestamp-confirmed" } }, ], @@ -351,9 +353,10 @@ sub load_and_group_problems : Private { my ( %fixed, %open, @pins ); my $re_councils = join('|', keys %{$c->stash->{areas_info}}); - my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'duration', 'age' ); + my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'duration', 'age' ); while ( my @problem = $problems->next ) { my %problem = zip @cols, @problem; + $c->log->debug( $problem{'cobrand'} . ', cobrand is ' . $c->cobrand->moniker ); if ( !$problem{council} ) { # Problem was not sent to any council, add to possible councils $problem{councils} = 0; @@ -372,10 +375,10 @@ sub load_and_group_problems : Private { } } - $c->stash( - fixed => \%fixed, - open => \%open, - pins => \@pins, + $c->stash( + fixed => \%fixed, + open => \%open, + pins => \@pins, ); return 1; diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index 23345df65..7fddbed97 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -151,6 +151,7 @@ sub local_problems_ll : Private { sub output : Private { my ( $self, $c ) = @_; + $c->detach( '/page_error_404_not_found', [ 'Feed not found' ] ) if $c->cobrand->moniker eq 'emptyhomes'; $c->forward( 'lookup_type' ); $c->forward( 'query_main' ); $c->forward( 'generate' ); diff --git a/perllib/FixMyStreet/App/Controller/Tokens.pm b/perllib/FixMyStreet/App/Controller/Tokens.pm index 10f994d9f..b974f94e6 100644 --- a/perllib/FixMyStreet/App/Controller/Tokens.pm +++ b/perllib/FixMyStreet/App/Controller/Tokens.pm @@ -69,6 +69,7 @@ sub confirm_problem : Path('/P') { # log the problem creation user in to the site if ( ref($data) && ( $data->{name} || $data->{password} ) ) { $problem->user->name( $data->{name} ) if $data->{name}; + $problem->user->phone( $data->{phone} ) if $data->{phone}; $problem->user->password( $data->{password}, 1 ) if $data->{password}; $problem->user->update; } |