diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 11 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/LichfieldDC.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/AlertType.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 4 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 8 |
9 files changed, 31 insertions, 18 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 871da737f..3bcadd758 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -50,7 +50,7 @@ sub index : Path : Args(0) { $c->forward('check_page_allowed'); - my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); + my ( $id, $site_restriction ) = $c->cobrand->site_restriction(); my $problems = $c->cobrand->problems->summary_count; @@ -122,7 +122,7 @@ sub timeline : Path( 'timeline' ) : Args(0) { $c->forward('check_page_allowed'); - my ( $sql_restriction, $id, $site_restriction ) = $c->cobrand->site_restriction(); + my ( $id, $site_restriction ) = $c->cobrand->site_restriction(); my %time; $c->model('DB')->schema->storage->sql_maker->quote_char( '"' ); @@ -472,7 +472,7 @@ sub search_reports : Path('search_reports') { if (my $search = $c->req->param('search')) { $c->stash->{searched} = 1; - my ( $site_res_sql, $site_key, $site_restriction ) = $c->cobrand->site_restriction; + my ( $site_key, $site_restriction ) = $c->cobrand->site_restriction; my $search_n = 0; $search_n = int($search) if $search =~ /^\d+$/; @@ -574,7 +574,7 @@ sub search_reports : Path('search_reports') { sub report_edit : Path('report_edit') : Args(1) { my ( $self, $c, $id ) = @_; - my ( $site_res_sql, $site_key, $site_restriction ) = $c->cobrand->site_restriction; + my ( $site_key, $site_restriction ) = $c->cobrand->site_restriction; my $problem = $c->cobrand->problems->search( { @@ -735,8 +735,7 @@ sub search_users: Path('search_users') : Args(0) { sub update_edit : Path('update_edit') : Args(1) { my ( $self, $c, $id ) = @_; - my ( $site_res_sql, $site_key, $site_restriction ) = - $c->cobrand->site_restriction; + my ( $site_key, $site_restriction ) = $c->cobrand->site_restriction; my $update = $c->model('DB::Comment')->search( { id => $id, diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index 4d0b6cb93..f898d06a0 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -205,14 +205,14 @@ sub query_main : Private { my ( $self, $c ) = @_; my $alert_type = $c->stash->{alert_type}; - my ( $site_restriction, $site_id ) = $c->cobrand->site_restriction( $c->cobrand->extra_data ); + my ( $sql_restriction ) = $c->cobrand->sql_restriction( $c->cobrand->extra_data ); # Only apply a site restriction if the alert uses the problem table - $site_restriction = '' unless $alert_type->item_table eq 'problem'; + $sql_restriction = '' unless $alert_type->item_table eq 'problem'; # FIXME Do this in a nicer way at some point in the future... my $query = 'select * from ' . $alert_type->item_table . ' where ' . ($alert_type->head_table ? $alert_type->head_table . '_id=? and ' : '') - . $alert_type->item_where . $site_restriction . ' order by ' + . $alert_type->item_where . $sql_restriction . ' order by ' . $alert_type->item_order; my $rss_limit = mySociety::Config::get('RSS_LIMIT'); $query .= " limit $rss_limit" unless $c->stash->{type} =~ /^all/; diff --git a/perllib/FixMyStreet/Cobrand.pm b/perllib/FixMyStreet/Cobrand.pm index b88f6facc..d694e4bdb 100644 --- a/perllib/FixMyStreet/Cobrand.pm +++ b/perllib/FixMyStreet/Cobrand.pm @@ -38,7 +38,7 @@ Simply returns the config variable (so this function can be overridden in test s =cut sub _get_allowed_cobrands { - return FixMyStreet->config('ALLOWED_COBRANDS'); + return FixMyStreet->config('ALLOWED_COBRANDS') || []; } =head2 available_cobrand_classes diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index b06c534ac..aabf708f8 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -50,7 +50,8 @@ empty string and site key 0 if the cobrand uses all the data. =cut -sub site_restriction { return ( "", 0, {} ) } +sub site_restriction { return ( 0, {} ) } +sub sql_restriction { return ""; } =head2 restriction diff --git a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm index 804289d34..014981daf 100644 --- a/perllib/FixMyStreet/Cobrand/LichfieldDC.pm +++ b/perllib/FixMyStreet/Cobrand/LichfieldDC.pm @@ -12,7 +12,10 @@ sub council_url { return 'lichfielddc'; } # Different to councils parent due to this being a two-tier council. If we get # more, this can be genericised in the parent. sub site_restriction { - return ( "and council like '%2434%'", 'lichfield', { council => '2434' } ); + return ( 'lichfield', { council => '2434' } ); +} +sub sql_restriction { + return "and council like '%2434%'"; } sub problems_clause { diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index 8a6954418..036e2684a 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -13,7 +13,11 @@ sub is_council { sub site_restriction { my $self = shift; - return ( "and council='" . $self->council_id . "'", $self->council_url, { council => sprintf('%d', $self->council_id) } ); + return ( $self->council_url, { council => sprintf('%d', $self->council_id) } ); +} +sub sql_restriction { + my $self = shift; + return "and council='" . $self->council_id . "'"; } sub restriction { diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm index 26d8f32a9..b985ccad6 100644 --- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm +++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm @@ -65,7 +65,7 @@ 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} ); + my ( $name_restictions, $hashref_restriction ) = $cobrand->site_restriction( $row->{cobrand_data} ); FixMyStreet::App->model('DB::AlertSent')->create( { alert_id => $row->{alert_id}, @@ -141,7 +141,7 @@ sub email_alerts ($) { my $longitude = $alert->parameter; my $latitude = $alert->parameter2; - my ($site_restriction, $site_id, $hashref_restriction) = $cobrand->site_restriction( $alert->cobrand_data ); + my ($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 { diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index a7738becf..c4fd07615 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -14,13 +14,11 @@ use mySociety::MaPit; use FixMyStreet::App; use FixMyStreet::SendReport; -my $site_restriction; my $site_key; sub set_restriction { - my ( $rs, $sql, $key, $restriction ) = @_; + my ( $rs, $key, $restriction ) = @_; $site_key = $key; - $site_restriction = $restriction; } # Front page statistics diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index 29fb650e5..2875af537 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -34,6 +34,9 @@ my %contact_params = ( note => 'Created for test', ); # Let's make some contacts to send things to! +FixMyStreet::App->model('DB::Contact')->search( { + email => { 'like', '%example.com' }, +} )->delete; my $contact1 = FixMyStreet::App->model('DB::Contact')->find_or_create( { %contact_params, area_id => 2651, # Edinburgh @@ -859,6 +862,11 @@ for my $test ( ) { subtest $test->{desc} => sub { + if ( $test->{host} =~ /bromley/ && !FixMyStreet::Cobrand->exists('bromley') ) { + ok 1, 'Skipping Bromley tests without Bromley cobrand'; + return; + } + $mech->host( $test->{host} ); $mech->log_out_ok; |