diff options
author | Dave Whiteland <dave@mysociety.org> | 2012-10-03 17:47:25 +0100 |
---|---|---|
committer | Dave Whiteland <dave@mysociety.org> | 2012-10-03 17:47:25 +0100 |
commit | 272dba7ce6d59d81b52579dd4c5fc7d65e9bec20 (patch) | |
tree | cabbefec7823061781050ffb002a38ce53d68f56 /perllib/FixMyStreet | |
parent | 39c1b648b30e67ceb8912a35b386eb4ee23857b8 (diff) | |
parent | f16a3e96b65394089d10c46c1d67cf82c67e72dd (diff) |
Merge branch 'fmb-read-only'
Conflicts:
db/schema.sql
perllib/FixMyStreet/DB/Result/Contact.pm
perllib/FixMyStreet/DB/Result/Problem.pm
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 17 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 49 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyBarangay.pm | 50 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Contact.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Open311conf.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/EmptyHomes.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/NI.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Open311.pm | 9 |
18 files changed, 191 insertions, 34 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index ef299d224..2d1cf2c5a 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -305,6 +305,10 @@ sub update_contacts : Private { $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'); @@ -341,7 +345,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 comment_user_id/; + my %params = map { $_ => $c->req->param($_) || '' } qw/open311_id endpoint jurisdiction api_key area_id send_method send_comments suppress_alerts comment_user_id devolved/; if ( $params{open311_id} ) { my $conf = $c->model('DB::Open311Conf')->find( { id => $params{open311_id} } ); @@ -353,6 +357,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->update(); @@ -367,6 +372,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->insert(); @@ -462,6 +468,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; } 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/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index cda569860..a7e1e8a3a 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 ) = @_; diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index a2c5e6a0c..a4462e035 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -1010,6 +1010,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(); @@ -1080,7 +1087,13 @@ 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} } ); + } 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 c49123a90..da4cc33ca 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; @@ -348,6 +352,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/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 8d0b5ab50..cfc9455b5 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -645,7 +645,34 @@ Get stats to display on the council reports page sub get_report_stats { return 0; } -sub get_council_sender { return 'Email' }; +sub get_council_sender { + my ( $self, $area_id, $area_info, $category ) = @_; + + my $send_method; + + my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $area_id } )->first; + $send_method = $council_config->send_method if $council_config; + + if ( $council_config && $council_config->can_be_devolved ) { + # look up via category + my $config = FixMyStreet::App->model("DB::Contact")->search( { area_id => $area_id, category => $category } )->first; + if ( $config->send_method ) { + return { method => $config->send_method, config => $config }; + } else { + return { method => $send_method, config => $council_config }; + } + } elsif ( $send_method ) { + return { method => $send_method, config => $council_config }; + } + + return $self->_fallback_council_sender( $area_id, $area_info, $category ); +} + +sub _fallback_council_sender { + my ( $self, $area_id, $area_info, $category ) = @_; + + return { method => 'Email' }; +}; sub example_places { my $e = FixMyStreet->config('EXAMPLE_PLACES') || [ 'High Street', 'Main Street' ]; @@ -653,6 +680,24 @@ sub example_places { return $e; } +=head2 only_authed_can_create + +If true, only users with the from_council flag set are able to create reports. + +=cut + +sub only_authed_can_create { + return 0; +} + +=head2 areas_on_around + +If set to an arrayref, will plot those area ID(s) from mapit on all the /around pages. + +=cut + +sub areas_on_around {} + sub process_extras {} =head 2 pin_colour @@ -678,5 +723,7 @@ Used in some cobrands to improve the intial display for Internet Explorer. sub tweak_all_reports_map {} +sub can_support_problems { return 0; } + 1; diff --git a/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm b/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm new file mode 100644 index 000000000..e2a8e9f87 --- /dev/null +++ b/perllib/FixMyStreet/Cobrand/FixMyBarangay.pm @@ -0,0 +1,50 @@ +package FixMyStreet::Cobrand::FixMyBarangay; +use base 'FixMyStreet::Cobrand::Default'; + +use strict; +use warnings; + +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 country { + return 'PH'; +} + +sub language_domain { 'FixMyBarangay' } + +sub area_types { + return [ 'BGY' ]; +} + +sub disambiguate_location { + return { + country => 'ph', + bing_country => 'Philippines', + }; +} + +sub site_title { + my ($self) = @_; + return 'FixMyBarangay'; +} + +sub only_authed_can_create { + return 1; +} + +sub areas_on_around { + return [ 1, 2 ]; +} + +sub can_support_problems { + return 1; +} + +1; + diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index 0d6f98590..75f6ba061 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -31,19 +31,11 @@ sub disambiguate_location { }; } -sub get_council_sender { - my ( $self, $area_id, $area_info ) = @_; - - my $send_method; - - my $council_config = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $area_id } )->first; - $send_method = $council_config->send_method if $council_config; - - return $send_method if $send_method; - - return 'London' if $area_info->{type} eq 'LBO'; - return 'NI' if $area_info->{type} eq 'LGD'; - return 'Email'; +sub _fallback_council_sender { + my ( $self, $area_id, $area_info, $category ) = @_; + return { method => 'London' } if $area_info->{type} eq 'LBO'; + return { method => 'NI' } if $area_info->{type} eq 'LGD'; + return { method => 'Email' }; } sub process_extras { diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 91695d7d0..8c9fea282 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -54,10 +54,6 @@ __PACKAGE__->add_columns( { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "problem_state", { data_type => "text", is_nullable => 1 }, - "external_id", - { data_type => "text", is_nullable => 1 }, - "extra", - { data_type => "text", is_nullable => 1 }, "send_fail_count", { data_type => "integer", default_value => 0, is_nullable => 0 }, "send_fail_reason", @@ -66,6 +62,10 @@ __PACKAGE__->add_columns( { data_type => "timestamp", is_nullable => 1 }, "whensent", { data_type => "timestamp", is_nullable => 1 }, + "external_id", + { data_type => "text", is_nullable => 1 }, + "extra", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to( @@ -82,8 +82,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-03-26 15:44:18 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:nvkElEgSU6XcLd9znSqhmQ +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-07-11 18:53:26 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tSejJzLxHD/fMWjpa10lfA __PACKAGE__->filter_column( extra => { diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm index cad12f1fc..993e3524b 100644 --- a/perllib/FixMyStreet/DB/Result/Contact.pm +++ b/perllib/FixMyStreet/DB/Result/Contact.pm @@ -38,6 +38,14 @@ __PACKAGE__->add_columns( { 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", + { data_type => "text", default_value => "", is_nullable => 1 }, + "api_key", + { data_type => "text", default_value => "", is_nullable => 1 }, + "send_method", + { data_type => "text", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("contacts_area_id_category_idx", ["area_id", "category"]); diff --git a/perllib/FixMyStreet/DB/Result/Open311conf.pm b/perllib/FixMyStreet/DB/Result/Open311conf.pm index c95b0c8f2..8051e27de 100644 --- a/perllib/FixMyStreet/DB/Result/Open311conf.pm +++ b/perllib/FixMyStreet/DB/Result/Open311conf.pm @@ -34,6 +34,8 @@ __PACKAGE__->add_columns( { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "suppress_alerts", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, + "can_be_devolved", + { data_type => "boolean", default_value => \"false", is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->add_unique_constraint("open311conf_area_id_key", ["area_id"]); @@ -50,8 +52,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-05-11 13:30:31 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ByJbRe/Y/9Z1WHdG8kaIHg +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-08-29 14:04:20 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Yoult8K/ldH6DMAKURtr3Q # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index a1cf107a9..761f57b01 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -94,6 +94,12 @@ __PACKAGE__->add_columns( { 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", + { data_type => "text", is_nullable => 1 }, + "interest_count", + { data_type => "integer", is_nullable => 1 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->has_many( diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index 2f426e8ca..f7f88edf0 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -310,8 +310,8 @@ sub send_reports { foreach my $council (@councils) { my $name = $areas_info->{$council}->{name}; - my $sender = $cobrand->get_council_sender( $council, $areas_info->{$council} ); - $sender = "FixMyStreet::SendReport::$sender"; + my $sender_info = $cobrand->get_council_sender( $council, $areas_info->{$council}, $row->category ); + my $sender = "FixMyStreet::SendReport::" . $sender_info->{method}; if ( ! exists $senders->{ $sender } ) { warn "No such sender [ $sender ] for council $name ( $council )"; @@ -324,7 +324,7 @@ sub send_reports { $reporters{ $sender }->skipped; } else { push @dear, $name; - $reporters{ $sender }->add_council( $council, $areas_info->{$council} ); + $reporters{ $sender }->add_council( $council, $areas_info->{$council}, $sender_info->{config} ); } } diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm index f750ef479..9ba507862 100644 --- a/perllib/FixMyStreet/SendReport.pm +++ b/perllib/FixMyStreet/SendReport.pm @@ -39,8 +39,9 @@ sub add_council { my $self = shift; my $council = shift; my $info = shift; + my $config = shift; - $self->councils->{ $council } = $info; + $self->councils->{ $council } = { info => $info, config => $config }; } diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 654ed6b3a..11ca196fb 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -12,6 +12,7 @@ sub build_recipient_list { my $all_confirmed = 1; foreach my $council ( keys %{ $self->councils } ) { + my $contact = FixMyStreet::App->model("DB::Contact")->find( { deleted => 0, area_id => $council, @@ -32,7 +33,7 @@ sub build_recipient_list { $self->unconfirmed_notes->{$council_email}{$row->category} = $note; } - push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{name} ]; + push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{info}->{name} ]; $recips{$council_email} = 1; } diff --git a/perllib/FixMyStreet/SendReport/EmptyHomes.pm b/perllib/FixMyStreet/SendReport/EmptyHomes.pm index e1b914523..4a6f058fe 100644 --- a/perllib/FixMyStreet/SendReport/EmptyHomes.pm +++ b/perllib/FixMyStreet/SendReport/EmptyHomes.pm @@ -28,7 +28,7 @@ sub build_recipient_list { #$note{$council_email}{$row->category} = $note; } - push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{name} ]; + push @{ $self->to }, [ $council_email, $self->councils->{ $council }->{ info }->{name} ]; $recips{$council_email} = 1; my $country = $self->councils->{$council}->{country}; diff --git a/perllib/FixMyStreet/SendReport/NI.pm b/perllib/FixMyStreet/SendReport/NI.pm index 0783a385b..810ee60e2 100644 --- a/perllib/FixMyStreet/SendReport/NI.pm +++ b/perllib/FixMyStreet/SendReport/NI.pm @@ -23,7 +23,7 @@ sub build_recipient_list { $email = 'N/A' unless $email; } - my $name = $self->councils->{$council}->{name}; + my $name = $self->councils->{$council}->{info}->{name}; if ( $email =~ /^roads.([^@]*)\@drdni/ ) { $name = "Roads Service (\u$1)"; $h->{councils_name} = $name; diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm index 42c103b82..70bce3d47 100644 --- a/perllib/FixMyStreet/SendReport/Open311.pm +++ b/perllib/FixMyStreet/SendReport/Open311.pm @@ -28,7 +28,7 @@ sub send { my $result = -1; foreach my $council ( keys %{ $self->councils } ) { - my $conf = FixMyStreet::App->model("DB::Open311conf")->search( { area_id => $council, endpoint => { '!=', '' } } )->first; + my $conf = $self->councils->{$council}->{config}; my $always_send_latlong = 1; my $send_notpinpointed = 0; @@ -94,10 +94,15 @@ sub send { $row->user->name( $row->user->id . ' ' . $row->user->name ); } + if ($row->cobrand eq 'fixmybarangay') { + # FixMyBarangay endpoints expect external_id as an attribute + $row->extra( [ { 'name' => 'external_id', 'value' => $row->id } ] ); + } + my $resp = $open311->send_service_request( $row, $h, $contact->email ); # make sure we don't save user changes from above - if ( $row->council =~ /2218/ || $row->council =~ /2482/ ) { + if ( $row->council =~ /2218/ || $row->council =~ /2482/ || $row->cobrand eq 'fixmybarangay') { $row->discard_changes(); } |