mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #2563 from overleaf/jel-add-affiliation-when-registering
Add affiliation when registering GitOrigin-RevId: e1915bbdc0a4fef399ef9b4a2154ede31e282cc3
This commit is contained in:
parent
222ba263ff
commit
528b2b5728
3 changed files with 12 additions and 41 deletions
|
@ -3,7 +3,7 @@ const util = require('util')
|
|||
const { User } = require('../../models/User')
|
||||
const { addAffiliation } = require('../Institutions/InstitutionsAPI')
|
||||
|
||||
async function createNewUser(attributes, options = {}) {
|
||||
async function createNewUser(attributes) {
|
||||
let user = new User()
|
||||
|
||||
if (attributes.first_name == null || attributes.first_name === '') {
|
||||
|
@ -40,17 +40,14 @@ async function createNewUser(attributes, options = {}) {
|
|||
|
||||
user = await user.save()
|
||||
|
||||
if (!options.skip_affiliation) {
|
||||
// There is no guarantee this will complete so we must not rely on it
|
||||
addAffiliation(user._id, user.email, err => {
|
||||
if (err) {
|
||||
logger.error(
|
||||
{ userId: user._id, email: user.email },
|
||||
"couldn't add affiliation for user on create"
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
addAffiliation(user._id, user.email, err => {
|
||||
if (err) {
|
||||
logger.error(
|
||||
{ userId: user._id, email: user.email },
|
||||
"couldn't add affiliation for user on create"
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
return user
|
||||
}
|
||||
|
|
|
@ -141,14 +141,10 @@ class UserHelper {
|
|||
* @param {object} options options for UserCreator
|
||||
* @returns {UserHelper}
|
||||
*/
|
||||
static async createUser(attributes = {}, options = {}) {
|
||||
static async createUser(attributes = {}) {
|
||||
const userHelper = new UserHelper()
|
||||
attributes = userHelper.getDefaultEmailPassword(attributes)
|
||||
// skip creating affiliations by default because it requires an
|
||||
// API call that will usually not be mocked in testing env
|
||||
if (attributes.skip_affiliation !== false) {
|
||||
attributes.skip_affiliation = true
|
||||
}
|
||||
|
||||
// hash password and delete plaintext if set
|
||||
if (attributes.password) {
|
||||
attributes.hashedPassword = await AuthenticationManager.promises.hashPassword(
|
||||
|
@ -157,10 +153,7 @@ class UserHelper {
|
|||
delete attributes.password
|
||||
}
|
||||
|
||||
userHelper.user = await UserCreator.promises.createNewUser(
|
||||
attributes,
|
||||
options
|
||||
)
|
||||
userHelper.user = await UserCreator.promises.createNewUser(attributes)
|
||||
|
||||
return userHelper
|
||||
}
|
||||
|
|
|
@ -123,18 +123,6 @@ describe('UserCreator', function() {
|
|||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not add affiliation if skipping', function(done) {
|
||||
const attributes = { email: this.email }
|
||||
const options = { skip_affiliation: true }
|
||||
this.UserCreator.createNewUser(attributes, options, (err, user) => {
|
||||
assert.ifError(err)
|
||||
process.nextTick(() => {
|
||||
sinon.assert.notCalled(this.addAffiliation)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with promises', function() {
|
||||
|
@ -156,13 +144,6 @@ describe('UserCreator', function() {
|
|||
sinon.assert.calledWithMatch(this.addAffiliation, user._id, this.email)
|
||||
})
|
||||
|
||||
it('should not add affiliation if skipping', async function() {
|
||||
const attributes = { email: this.email }
|
||||
const opts = { skip_affiliation: true }
|
||||
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,
|
||||
|
|
Loading…
Reference in a new issue