فهرست منبع

Merge pull request #4057 from overleaf/msm-prevent-onboarding-email-server-pro

Prevented Onboarding email from being sent in CE/SP

GitOrigin-RevId: 68d117b477bd90c6410aabdcc6af8142626f7b4e
Hugh O'Brien 5 سال پیش
والد
کامیت
f16c60e009
2فایلهای تغییر یافته به همراه28 افزوده شده و 12 حذف شده
  1. 18 11
      services/web/app/src/Features/User/UserCreator.js
  2. 10 1
      services/web/test/unit/src/User/UserCreatorTests.js

+ 18 - 11
services/web/app/src/Features/User/UserCreator.js

@@ -8,6 +8,7 @@ const UserGetter = require('./UserGetter')
 const UserUpdater = require('./UserUpdater')
 const Analytics = require('../Analytics/AnalyticsManager')
 const UserOnboardingEmailQueueManager = require('./UserOnboardingEmailManager')
+const OError = require('@overleaf/o-error')
 
 async function _addAffiliation(user, affiliationOptions) {
   try {
@@ -24,8 +25,10 @@ async function _addAffiliation(user, affiliationOptions) {
     user = await UserGetter.promises.getUser(user._id)
   } catch (error) {
     logger.error(
-      { userId: user._id, email: user.email },
-      'could not get fresh user data'
+      OError.tag(error, 'could not get fresh user data', {
+        userId: user._id,
+        email: user.email,
+      })
     )
   }
   return user
@@ -73,22 +76,26 @@ async function createNewUser(attributes, options = {}) {
     } catch (error) {
       if (options.requireAffiliation) {
         await UserDeleter.promises.deleteMongoUser(user._id)
-        throw error
+        throw OError.tag(error)
       } else {
-        logger.error(error)
+        logger.error(OError.tag(error))
       }
     }
   }
 
   Analytics.recordEvent(user._id, 'user-registered')
   Analytics.setUserProperty(user._id, 'created-at', new Date())
-  try {
-    await UserOnboardingEmailQueueManager.scheduleOnboardingEmail(user)
-  } catch (error) {
-    logger.error(
-      `Failed to schedule sending of onboarding email for user '${user._id}'`,
-      error
-    )
+
+  if (Features.hasFeature('saas')) {
+    try {
+      await UserOnboardingEmailQueueManager.scheduleOnboardingEmail(user)
+    } catch (error) {
+      logger.error(
+        OError.tag(error, 'Failed to schedule sending of onboarding email', {
+          userId: user._id,
+        })
+      )
+    }
   }
 
   return user

+ 10 - 1
services/web/test/unit/src/User/UserCreatorTests.js

@@ -279,7 +279,8 @@ describe('UserCreator', function () {
         )
       })
 
-      it('should schedule an onboarding email on registration', async function () {
+      it('should schedule an onboarding email on registration with saas feature', async function () {
+        this.Features.hasFeature = sinon.stub().withArgs('saas').returns(true)
         const user = await this.UserCreator.promises.createNewUser({
           email: this.email,
         })
@@ -289,6 +290,14 @@ describe('UserCreator', function () {
           user
         )
       })
+
+      it('should not add schedule onboarding email when without saas feature', async function () {
+        const attributes = { email: this.email }
+        await this.UserCreator.promises.createNewUser(attributes)
+        sinon.assert.notCalled(
+          this.UserOnboardingEmailManager.scheduleOnboardingEmail
+        )
+      })
     })
   })
 })