From 61d895c8fc280114bbbb636727618d9f4f81e5ac Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Mon, 7 Oct 2019 10:23:45 -0500 Subject: [PATCH] Merge pull request #2210 from overleaf/jel-provider-id-institution-registration Include provider ID with email data for institution registrations GitOrigin-RevId: a752005c03494bab717be0cbb915cbcb7a0aa729 --- .../web/app/src/Features/User/UserCreator.js | 21 ++++++++++++------- services/web/app/src/models/User.js | 3 ++- .../test/unit/src/User/UserCreatorTests.js | 9 ++++++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/services/web/app/src/Features/User/UserCreator.js b/services/web/app/src/Features/User/UserCreator.js index e82e56781f..2656817fdb 100644 --- a/services/web/app/src/Features/User/UserCreator.js +++ b/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() diff --git a/services/web/app/src/models/User.js b/services/web/app/src/models/User.js index 00a6820269..cb3b96032b 100644 --- a/services/web/app/src/models/User.js +++ b/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: '' }, diff --git a/services/web/test/unit/src/User/UserCreatorTests.js b/services/web/test/unit/src/User/UserCreatorTests.js index 7cfa405fd4..5dac565971 100644 --- a/services/web/test/unit/src/User/UserCreatorTests.js +++ b/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') + }) }) }) })