From b16ad52401bc3749847be7d92144191746a21387 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Fri, 26 Aug 2022 00:16:54 +0530 Subject: [PATCH] Updated geolocation handling for email alerts refs https://github.com/TryGhost/Team/issues/1826 - geolocation is a stringified json on member, needs parsing --- ghost/staff-service/lib/emails.js | 16 +++++++++++++++- ghost/staff-service/test/staff-service.test.js | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ghost/staff-service/lib/emails.js b/ghost/staff-service/lib/emails.js index 84a8f1f00e..82b60a8847 100644 --- a/ghost/staff-service/lib/emails.js +++ b/ghost/staff-service/lib/emails.js @@ -150,11 +150,25 @@ class StaffServiceEmails { email: member?.email, adminUrl: this.urlUtils.urlJoin(this.urlUtils.urlFor('admin', true), '#', `/members/${member.id}`), initials: this.extractInitials(name), - location: member.geolocation?.country || null, + location: this.getGeolocationData(member.geolocation), createdAt: moment(member.created_at).format('D MMM YYYY') }; } + /** @private */ + getGeolocationData(geolocation) { + if (!geolocation) { + return null; + } + + try { + const geolocationData = JSON.parse(geolocation); + return geolocationData?.country || null; + } catch (e) { + return null; + } + } + /** @private */ getFormattedAmount({amount = 0, currency}) { if (!currency) { diff --git a/ghost/staff-service/test/staff-service.test.js b/ghost/staff-service/test/staff-service.test.js index a7e4f960ad..9c8a2560ed 100644 --- a/ghost/staff-service/test/staff-service.test.js +++ b/ghost/staff-service/test/staff-service.test.js @@ -153,7 +153,7 @@ describe('StaffService', function () { name: 'Ghost', email: 'member@example.com', id: 'abc', - geolocation: {country: 'France'}, + geolocation: '{"country": "France"}', created_at: '2022-08-01T07:30:39.882Z' }; @@ -185,7 +185,7 @@ describe('StaffService', function () { name: 'Ghost', email: 'member@example.com', id: 'abc', - geolocation: {country: 'France'}, + geolocation: '{"country": "France"}', created_at: '2022-08-01T07:30:39.882Z' }; offer = { @@ -316,7 +316,7 @@ describe('StaffService', function () { name: 'Ghost', email: 'member@example.com', id: 'abc', - geolocation: {country: 'France'}, + geolocation: '{"country": "France"}', created_at: '2022-08-01T07:30:39.882Z' };