From 89d15bb71f377ad8a86d53caaffc7ce155fde23f Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 1 Nov 2024 16:11:00 -0500 Subject: [PATCH] Website: follow up changes from pr review (#23471) Changes: - Updated view-basic-documentation, view-transparency, and view-device-management to log warnings if the Cloudflare headers we use to determine whether or not to show the swag CTA are missing in production - Fixed a typo in save-questionnaire-progress --- website/api/controllers/docs/view-basic-documentation.js | 6 ++++++ website/api/controllers/save-questionnaire-progress.js | 2 +- website/api/controllers/view-device-management.js | 6 ++++++ website/api/controllers/view-transparency.js | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/website/api/controllers/docs/view-basic-documentation.js b/website/api/controllers/docs/view-basic-documentation.js index b5d1746e8b04..74dbc15ce5ec 100644 --- a/website/api/controllers/docs/view-basic-documentation.js +++ b/website/api/controllers/docs/view-basic-documentation.js @@ -57,6 +57,12 @@ module.exports = { let showSwagForm = false; // Due to shipping costs, we'll check the requesting user's cf-ipcountry to see if they're in the US, and their cf-iplongitude header to see if they're in the contiguous US. + if(sails.config.environment === 'production') { + // Log a warning if the cloudflare headers we use are missing in production. + if(!this.req.get('cf-ipcountry') || !this.req.get('cf-iplongitude')) { + sails.log.warn('When a user visted the docs, the Cloudflare header we use to determine if they are visiting from the contiguous United States is missing.'); + } + } if(this.req.get('cf-ipcountry') === 'US' && this.req.get('cf-iplongitude') > -125) { showSwagForm = true; } diff --git a/website/api/controllers/save-questionnaire-progress.js b/website/api/controllers/save-questionnaire-progress.js index 0cc7f3d325bd..fbdb103405a9 100644 --- a/website/api/controllers/save-questionnaire-progress.js +++ b/website/api/controllers/save-questionnaire-progress.js @@ -217,7 +217,7 @@ module.exports = { sails.log.warn(`When converting a user's (email: ${this.req.me.emailAddress}) getStartedQuestionnaireAnswers to a formatted string to send to the CRM, and error occurred`, err); } // Prepend the user's reported organization to the questionnaireProgressAsAFormattedString - questionnaireProgressAsAFormattedString = `organization-acording-to-fleetdm.com: ${this.req.me.organization}\n` + questionnaireProgressAsAFormattedString; + questionnaireProgressAsAFormattedString = `organization-according-to-fleetdm.com: ${this.req.me.organization}\n` + questionnaireProgressAsAFormattedString; // Create a dictionary of values to send to the CRM for this user. let contactInformation = { diff --git a/website/api/controllers/view-device-management.js b/website/api/controllers/view-device-management.js index aff3088ee341..3666e12c1904 100644 --- a/website/api/controllers/view-device-management.js +++ b/website/api/controllers/view-device-management.js @@ -41,6 +41,12 @@ module.exports = { let showSwagForm = false; // Due to shipping costs, we'll check the requesting user's cf-ipcountry to see if they're in the US, and their cf-iplongitude header to see if they're in the contiguous US. + if(sails.config.environment === 'production') { + // Log a warning if the cloudflare headers we use are missing in production. + if(!this.req.get('cf-ipcountry') || !this.req.get('cf-iplongitude')) { + sails.log.warn('When a user visted the device management page, the Cloudflare header we use to determine if they are visiting from the contiguous United States is missing.'); + } + } if(this.req.get('cf-ipcountry') === 'US' && this.req.get('cf-iplongitude') > -125) { showSwagForm = true; } diff --git a/website/api/controllers/view-transparency.js b/website/api/controllers/view-transparency.js index 4aa3a2b69f91..2796f4634eae 100644 --- a/website/api/controllers/view-transparency.js +++ b/website/api/controllers/view-transparency.js @@ -19,6 +19,12 @@ module.exports = { let showSwagForm = false; // Due to shipping costs, we'll check the requesting user's cf-ipcountry to see if they're in the US, and their cf-iplongitude header to see if they're in the contiguous US. + if(sails.config.environment === 'production') { + // Log a warning if the cloudflare headers we use are missing in production. + if(!this.req.get('cf-ipcountry') || !this.req.get('cf-iplongitude')) { + sails.log.warn('When a user visted the transparency page, the Cloudflare header we use to determine if they are visiting from the contiguous United States is missing.'); + } + } if(this.req.get('cf-ipcountry') === 'US' && this.req.get('cf-iplongitude') > -125) { showSwagForm = true; }