Просмотр исходного кода

Merge pull request #2210 from overleaf/jel-provider-id-institution-registration

Include provider ID with email data for institution registrations

GitOrigin-RevId: a752005c03494bab717be0cbb915cbcb7a0aa729
Jessica Lawshe 7 лет назад
Родитель
Сommit
61d895c8fc

+ 14 - 7
services/web/app/src/Features/User/UserCreator.js

@@ -23,13 +23,20 @@ async function createNewUser(attributes, options = {}) {
     .reverse()
     .join('')
 
-  user.emails = [
-    {
-      email: user.email,
-      createdAt: new Date(),
-      reversedHostname
-    }
-  ]
+  const emailData = {
+    email: user.email,
+    createdAt: new Date(),
+    reversedHostname
+  }
+  if (
+    attributes.samlIdentifiers &&
+    attributes.samlIdentifiers[0] &&
+    attributes.samlIdentifiers[0].providerId
+  ) {
+    emailData.samlProviderId = attributes.samlIdentifiers[0].providerId
+  }
+
+  user.emails = [emailData]
 
   user = await user.save()
 

+ 2 - 1
services/web/app/src/models/User.js

@@ -27,7 +27,8 @@ const UserSchema = new Schema({
           return new Date()
         }
       },
-      confirmedAt: { type: Date }
+      confirmedAt: { type: Date },
+      samlProviderId: { type: String }
     }
   ],
   first_name: { type: String, default: '' },

+ 9 - 0
services/web/test/unit/src/User/UserCreatorTests.js

@@ -162,6 +162,15 @@ describe('UserCreator', function() {
         await this.UserCreator.promises.createNewUser(attributes, opts)
         sinon.assert.notCalled(this.addAffiliation)
       })
+
+      it('should include SAML provider ID with email', async function() {
+        const attributes = {
+          email: this.email,
+          samlIdentifiers: [{ email: this.email, providerId: '1' }]
+        }
+        const user = await this.UserCreator.promises.createNewUser(attributes)
+        assert.equal(user.emails[0].samlProviderId, '1')
+      })
     })
   })
 })