Explorar el Código

[web] Skip GeoIpLookup on CE/SP (#34348)

The regression was introduced in 487e1767b8ac531588a272f0492a900c24162b33.

GeoIp is not configured in CE/SP, yielding an error log when rendering the project list.

GitOrigin-RevId: 55410611a5fef95daa5914a31969893107777593
Miguel Serrano hace 2 meses
padre
commit
4ab8de3e38

+ 7 - 2
services/web/app/src/Features/Project/ProjectListController.mjs

@@ -501,8 +501,13 @@ async function projectListPage(req, res, next) {
   let showInrGeoBanner = false
   let showLATAMBanner = false
   let recommendedCurrency
-  const { countryCode, currencyCode } =
-    await GeoIpLookup.promises.getCurrencyCode(req.ip)
+  let countryCode
+  let currencyCode
+  if (isSaas) {
+    const currencyData = await GeoIpLookup.promises.getCurrencyCode(req.ip)
+    countryCode = currencyData.countryCode
+    currencyCode = currencyData.currencyCode
+  }
 
   if (
     usersBestSubscription?.type === 'free' ||

+ 7 - 0
services/web/app/src/infrastructure/GeoIpLookup.mjs

@@ -91,6 +91,13 @@ async function getDetails(ip, callback) {
   if (!ip) {
     return callback(new Error('no ip passed'))
   }
+  if (!settings.apis.geoIpLookup?.url) {
+    logger.warn(
+      {},
+      'settings.apis.geoIpLookup.url is not configured, skipping lookup'
+    )
+    return
+  }
   ip = ip.trim().split(' ')[0]
   const url = new URL(settings.apis.geoIpLookup.url)
   url.pathname += ip

+ 14 - 0
services/web/test/unit/src/Project/ProjectListController.test.mjs

@@ -467,6 +467,20 @@ describe('ProjectListController', function () {
       await ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
     })
 
+    it('should look up geo IP in saas', async function (ctx) {
+      ctx.Features.hasFeature.withArgs('saas').returns(true)
+      ctx.res.render = () => {}
+      await ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
+      expect(ctx.GeoIpLookup.promises.getCurrencyCode).to.have.been.calledOnce
+    })
+
+    it('should not look up geo IP in a non-saas environment', async function (ctx) {
+      ctx.Features.hasFeature.withArgs('saas').returns(false)
+      ctx.res.render = () => {}
+      await ctx.ProjectListController.projectListPage(ctx.req, ctx.res)
+      expect(ctx.GeoIpLookup.promises.getCurrencyCode).to.not.have.been.called
+    })
+
     it('should send groupRole to customer.io for group admins', async function (ctx) {
       ctx.Features.hasFeature.withArgs('saas').returns(true)
       ctx.SubscriptionViewModelBuilder.promises.getUsersSubscriptionDetails.resolves(