Skip to content

Commit

Permalink
Merge pull request #990 from alphagov/remove-snac
Browse files Browse the repository at this point in the history
Remove internal support for SNACs
  • Loading branch information
KludgeKML authored Nov 29, 2023
2 parents 50e9495 + de86055 commit 8bafd79
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 535 deletions.
36 changes: 14 additions & 22 deletions app/models/data_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ def number_of_places
# location - a Point object representing the centre of the search area
# distance (optional) - a Distance object representing the maximum distance
# limit (optional) - a maximum number of results to return
# authority_codes (optional) - array of GSS/SNAC codes to scope the results to a local authority
# authority_code (optional) - array of GSS codes to scope the results to a local authority
#
# Returns:
# an array of Place objects
def places_near(location, distance = nil, limit = nil, authority_codes = [])
def places_near(location, distance = nil, limit = nil, authority_code = nil)
loc_string = "'SRID=4326;POINT(#{location.longitude} #{location.latitude})'::geometry"
query = places
query = query.where(gss: authority_codes) if authority_codes.any?
query = query.where(gss: authority_code) if authority_code
query = query.limit(limit) if limit
query = query.where(Place.arel_table[:location].st_distance(location).lt(distance.in(:meters))) if distance
query = query.reorder(Arel.sql("location <-> #{loc_string}, RANDOM()"))
Expand All @@ -60,24 +60,24 @@ def places_for_postcode(postcode, distance = nil, limit = nil, local_authority_s
location = RGeo::Geographic.spherical_factory.point(location_data["longitude"], location_data["latitude"])
return places_near(location, distance, limit) if service.location_match_type == "nearest"

authority_codes = if local_authority_slug
authority_codes_for_local_authority_slug(local_authority_slug)
else
appropriate_authority_codes_for_postcode(postcode)
end
return [] unless authority_codes
authority_code = if local_authority_slug
authority_code_for_local_authority_slug(local_authority_slug)
else
appropriate_authority_code_for_postcode(postcode)
end
return [] unless authority_code

places_near(location, distance, limit, authority_codes)
places_near(location, distance, limit, authority_code)
end

def authority_codes_for_local_authority_slug(local_authority_slug)
def authority_code_for_local_authority_slug(local_authority_slug)
local_authorities_response = GdsApi.local_links_manager.local_authority(local_authority_slug)

local_authority = local_authorities_response.to_hash["local_authorities"].find do |la|
[service.local_authority_hierarchy_match_type, "unitary"].include?(la["tier"])
end

gss_and_snac(local_authority)
local_authority["gss"]
end

def appropriate_authority_for_local_custodian_code(local_custodian_code)
Expand All @@ -87,7 +87,7 @@ def appropriate_authority_for_local_custodian_code(local_custodian_code)
end
end

def appropriate_authority_codes_for_postcode(postcode)
def appropriate_authority_code_for_postcode(postcode)
local_custodian_codes = GdsApi.locations_api.local_custodian_code_for_postcode(postcode)
return nil if local_custodian_codes.compact.empty?

Expand All @@ -106,19 +106,11 @@ def appropriate_authority_codes_for_postcode(postcode)
end

authority_hash = appropriate_authority_for_local_custodian_code(local_custodian_codes.first) # there should be 0-1, return first or nil
gss_and_snac(authority_hash)
authority_hash["gss"]
rescue GdsApi::HTTPNotFound
nil
end

def gss_and_snac(authority_hash)
# Not all LAs have SNACs now, so we return an array including
# GSS and SNAC (or whichever they have)
return [] unless authority_hash

[authority_hash["gss"], authority_hash["snac"]].compact
end

def duplicating?
state == "duplicating"
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/place.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def self.parameters_from_hash(data_set, row)
fax: row["fax"],
text_phone: row["text_phone"],
source_address: row["source_address"] || "#{row['address1']} #{row['address2']} #{row['town']} #{row['postcode']}",
gss: row["gss"] || row["snac"],
gss: row["gss"],
}
location_parameters = if row["lng"] && row["lat"]
{ override_lng: row["lng"], override_lat: row["lat"] }
Expand Down
14 changes: 0 additions & 14 deletions features/data_sets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,3 @@ Feature: Managing data sets
And I go to the page for the "Register Offices" service

Then I should see that the current service has 2 missing GSS codes

Scenario: Creating a new data set for a service with local authority lookup with a CSV file with SNAC codes
Given I have previously created a service with the following attributes:
| name | Register Offices |
| location_match_type | Local authority |

When I go to the page for the "Register Offices" service
And I upload a new data set with a CSV with a SNAC column instead of GSS

When background processing has completed
And I activate the most recent data set for the "Register Offices" service
And I go to the page for the "Register Offices" service

Then I should see that the current service has 0 missing GSS codes
7 changes: 0 additions & 7 deletions features/step_definitions/data_set_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@
end
end

When(/^I upload a new data set with a CSV with a SNAC column instead of GSS$/) do
within "#new-data" do
attach_file "Data file", Rails.root.join("features/support/data/register-offices-with-snac-codes.csv")
click_button "Create Data set"
end
end

When(/^I upload a new data set with a CSV with missing GSS codes$/) do
within "#new-data" do
attach_file "Data file", Rails.root.join("features/support/data/register-offices-with-missing-gss-codes.csv")
Expand Down
4 changes: 0 additions & 4 deletions features/support/data/register-offices-with-snac-codes.csv

This file was deleted.

43 changes: 0 additions & 43 deletions lib/tasks/once_off/convert_snac_to_gss.rake

This file was deleted.

Loading

0 comments on commit 8bafd79

Please sign in to comment.