Skip to content

Commit

Permalink
Scope constituency search to current constituencies
Browse files Browse the repository at this point in the history
Note that we don't have to do this for `find_by_postcode` as
Parliament's API will only return us the current constituency.
  • Loading branch information
pixeltrix committed Jun 3, 2024
1 parent 5d80023 commit f27f287
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 34 deletions.
4 changes: 2 additions & 2 deletions app/controllers/local_petitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ def postcode?
end

def find_by_postcode
@constituency = Constituency.find_by_postcode(@postcode)
@constituency = Constituency.current.find_by_postcode(@postcode)
end

def find_by_slug
@constituency = Constituency.find_by_slug!(params[:id])
@constituency = Constituency.current.find_by_slug!(params[:id])
end

def constituency?
Expand Down
4 changes: 4 additions & 0 deletions app/models/constituency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def find_by_postcode(postcode)
end
end

def current
where(end_date: nil)
end

def english
where(arel_table[:ons_code].matches('E%'))
end
Expand Down
64 changes: 32 additions & 32 deletions config/brakeman.ignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,45 @@
],
"note": ""
},
{
"warning_type": "SSL Verification Bypass",
"warning_code": 71,
"fingerprint": "83faaaee2d372a0a73dc703bf46452d519d79dbf3b069a5007f71392ec7d4a3e",
"check_name": "SSLVerify",
"message": "SSL certificate verification was bypassed",
"file": "features/support/ssl_server.rb",
"line": 97,
"link": "https://brakemanscanner.org/docs/warning_types/ssl_verification_bypass/",
"code": "Net::HTTP.new(host, @port).verify_mode = OpenSSL::SSL::VERIFY_NONE",
"render_path": null,
"location": {
"type": "method",
"class": "Capybara::Server",
"method": "responsive?"
},
"user_input": null,
"confidence": "High",
"cwe_id": [
295
],
"note": ""
},
{
"warning_type": "Cross-Site Scripting",
"warning_code": 4,
"fingerprint": "07b7188ce44b7041f5729077eea749b2def4b8e62736ba248267e3c96c1ca927",
"fingerprint": "859022bb61c3d1af5cdb14424490f6d3970c5b7bddd3784f62efb4f01e8fe02b",
"check_name": "LinkToHref",
"message": "Potentially unsafe model attribute in `link_to` href",
"file": "app/views/local_petitions/all.html.erb",
"line": 11,
"link": "https://brakemanscanner.org/docs/warning_types/link_to_href",
"code": "link_to(Constituency.find_by_slug!(params[:id]).mp_name, Constituency.find_by_slug!(params[:id]).mp_url, :rel => \"external\")",
"code": "link_to(Constituency.current.find_by_slug!(params[:id]).mp_name, Constituency.current.find_by_slug!(params[:id]).mp_url, :rel => \"external\")",
"render_path": [
{
"type": "controller",
"class": "LocalPetitionsController",
"method": "all",
"line": 30,
"line": 32,
"file": "app/controllers/local_petitions_controller.rb",
"rendered": {
"name": "local_petitions/all",
Expand All @@ -61,7 +84,7 @@
"type": "template",
"template": "local_petitions/all"
},
"user_input": "Constituency.find_by_slug!(params[:id]).mp_url",
"user_input": "Constituency.current.find_by_slug!(params[:id]).mp_url",
"confidence": "Weak",
"cwe_id": [
79
Expand All @@ -71,19 +94,19 @@
{
"warning_type": "Cross-Site Scripting",
"warning_code": 4,
"fingerprint": "22e002a1359fd28418d81e2cadeb49195a5597840a43d97787ac79a868acb51f",
"fingerprint": "b44e200c1415ee4d50599d5a9854799a8de42354f84c7530d5c382a35fe2547e",
"check_name": "LinkToHref",
"message": "Potentially unsafe model attribute in `link_to` href",
"file": "app/views/local_petitions/show.html.erb",
"line": 11,
"link": "https://brakemanscanner.org/docs/warning_types/link_to_href",
"code": "link_to(Constituency.find_by_slug!(params[:id]).mp_name, Constituency.find_by_slug!(params[:id]).mp_url, :rel => \"external\")",
"code": "link_to(Constituency.current.find_by_slug!(params[:id]).mp_name, Constituency.current.find_by_slug!(params[:id]).mp_url, :rel => \"external\")",
"render_path": [
{
"type": "controller",
"class": "LocalPetitionsController",
"method": "show",
"line": 22,
"line": 24,
"file": "app/controllers/local_petitions_controller.rb",
"rendered": {
"name": "local_petitions/show",
Expand All @@ -95,36 +118,13 @@
"type": "template",
"template": "local_petitions/show"
},
"user_input": "Constituency.find_by_slug!(params[:id]).mp_url",
"user_input": "Constituency.current.find_by_slug!(params[:id]).mp_url",
"confidence": "Weak",
"cwe_id": [
79
],
"note": ""
},
{
"warning_type": "SSL Verification Bypass",
"warning_code": 71,
"fingerprint": "83faaaee2d372a0a73dc703bf46452d519d79dbf3b069a5007f71392ec7d4a3e",
"check_name": "SSLVerify",
"message": "SSL certificate verification was bypassed",
"file": "features/support/ssl_server.rb",
"line": 97,
"link": "https://brakemanscanner.org/docs/warning_types/ssl_verification_bypass/",
"code": "Net::HTTP.new(host, @port).verify_mode = OpenSSL::SSL::VERIFY_NONE",
"render_path": null,
"location": {
"type": "method",
"class": "Capybara::Server",
"method": "responsive?"
},
"user_input": null,
"confidence": "High",
"cwe_id": [
295
],
"note": ""
},
{
"warning_type": "Cross-Site Scripting",
"warning_code": 114,
Expand Down Expand Up @@ -164,6 +164,6 @@
"note": ""
}
],
"updated": "2024-05-10 12:37:54 +0000",
"updated": "2024-05-31 17:06:26 +0000",
"brakeman_version": "6.1.2"
}

0 comments on commit f27f287

Please sign in to comment.