Skip to content

Commit

Permalink
Switch from ip to tz for takeovers. Remove IP address geolocation (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
carkod committed Jun 6, 2024
1 parent a95c04f commit 68ef50f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 37 deletions.
5 changes: 3 additions & 2 deletions templates/base_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ <h2>Multi-cloud applications&nbsp;&ndash;&nbsp;beyond PAAS</h2>
) {
var userCountry = JSON.parse(fetchUserCountry.responseText).country_code;
var selectedTakeovers = takeovers.filter(function(item) {
if (item.target_country && item.target_country == userCountry) {
if (item.target_country && item.target_country.toLowerCase() == userCountry.toLowerCase()) {
return true;
} else if (item.lang === primaryParentLanguage || item.lang === "") {
return true;
Expand Down Expand Up @@ -1185,7 +1185,8 @@ <h2>Multi-cloud applications&nbsp;&ndash;&nbsp;beyond PAAS</h2>

xhr.open("GET", "/takeovers.json", true);
xhr.send();
fetchUserCountry.open("GET", "/user-country.json", true);
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
fetchUserCountry.open("GET", `/user-country-tz.json?tz=${timezone}`, true);
fetchUserCountry.send();
takeoverAnimation.className += " is-loading";
}
Expand Down
2 changes: 0 additions & 2 deletions webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
engage_thank_you,
french_why_openstack,
german_why_openstack,
get_user_country_by_ip,
get_user_country_by_tz,
json_asset_query,
marketo_submit,
Expand Down Expand Up @@ -630,7 +629,6 @@ def takeovers_index():
core_services_guide.init_app(app)


app.add_url_rule("/user-country.json", view_func=get_user_country_by_ip)
app.add_url_rule("/user-country-tz.json", view_func=get_user_country_by_tz)

# All other routes
Expand Down
33 changes: 0 additions & 33 deletions webapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1052,39 +1052,6 @@ def get_user_country_by_tz():
)


def get_user_country_by_ip():
x_forwarded_for = flask.request.headers.get("X-Forwarded-For")

if x_forwarded_for:
client_ip = x_forwarded_for.split(",")[0]
else:
client_ip = flask.request.remote_addr

ip_location = ip_reader.get(client_ip)

try:
country_code = ip_location["country"]["iso_code"]
except KeyError:
# geolite2 can't identify IP address
country_code = None
except Exception as error:
# Errors not documented in the geolite2 module
country_code = None
flask.current_app.extensions["sentry"].captureException(
extra={"ip_location object": ip_location, "error": error}
)

response = flask.jsonify(
{
"client_ip": client_ip,
"country_code": country_code,
}
)
response.cache_control.private = True

return response


def subscription_centre():
sfdcLeadId = flask.request.args.get("id")
return_url = flask.request.form.get("returnURL")
Expand Down

0 comments on commit 68ef50f

Please sign in to comment.