Create User.emails field for newly created users in launchpad (#2083)

GitOrigin-RevId: b6cfad25eeba21294f70769e11c3e3fa825f93aa
This commit is contained in:
Miguel Serrano 2019-08-19 17:06:27 +02:00 committed by sharelatex
parent 9386bdeaff
commit 8c55989166
2 changed files with 60 additions and 28 deletions

View file

@ -165,7 +165,10 @@ module.exports = LaunchpadController = {
return User.update( return User.update(
{ _id: user._id }, { _id: user._id },
{ $set: { isAdmin: true } }, {
$set: { isAdmin: true },
emails: [{ email }]
},
function(err) { function(err) {
if (err != null) { if (err != null) {
logger.warn( logger.warn(
@ -219,31 +222,38 @@ module.exports = LaunchpadController = {
logger.log({ user_id: user._id }, 'making user an admin') logger.log({ user_id: user._id }, 'making user an admin')
const proceed = () => const proceed = () =>
User.update({ _id: user._id }, { $set: { isAdmin: true } }, function( User.update(
err { _id: user._id },
) { {
if (err != null) { $set: {
logger.err( isAdmin: true,
{ user_id: user._id, err }, emails: [{ email }]
'error setting user to admin' }
) },
return next(err) function(err) {
} if (err != null) {
logger.err(
{ user_id: user._id, err },
'error setting user to admin'
)
return next(err)
}
AuthenticationController.setRedirectInSession(req, '/launchpad') AuthenticationController.setRedirectInSession(req, '/launchpad')
logger.log( logger.log(
{ email, user_id: user._id }, { email, user_id: user._id },
'created first admin account' 'created first admin account'
) )
return res.json({ return res.json({
redir: '', redir: '',
id: user._id.toString(), id: user._id.toString(),
first_name: user.first_name, first_name: user.first_name,
last_name: user.last_name, last_name: user.last_name,
email: user.email, email: user.email,
created: Date.now() created: Date.now()
}) })
}) }
)
if ( if (
Settings.overleaf != null && Settings.overleaf != null &&

View file

@ -366,7 +366,15 @@ describe('LaunchpadController', function() {
it('should have updated the user to make them an admin', function() { it('should have updated the user to make them an admin', function() {
this.User.update.callCount.should.equal(1) this.User.update.callCount.should.equal(1)
return this.User.update return this.User.update
.calledWith({ _id: this.user._id }, { $set: { isAdmin: true } }) .calledWithMatch(
{ _id: this.user._id },
{
$set: {
isAdmin: true,
emails: [{ email: this.user.email }]
}
}
)
.should.equal(true) .should.equal(true)
}) })
@ -677,7 +685,15 @@ describe('LaunchpadController', function() {
it('should have updated the user to make them an admin', function() { it('should have updated the user to make them an admin', function() {
return this.User.update return this.User.update
.calledWith({ _id: this.user._id }, { $set: { isAdmin: true } }) .calledWith(
{ _id: this.user._id },
{
$set: {
isAdmin: true,
emails: [{ email: this.user.email }]
}
}
)
.should.equal(true) .should.equal(true)
}) })
@ -752,7 +768,13 @@ describe('LaunchpadController', function() {
it('should have updated the user to make them an admin', function() { it('should have updated the user to make them an admin', function() {
this.User.update.callCount.should.equal(1) this.User.update.callCount.should.equal(1)
return this.User.update return this.User.update
.calledWith({ _id: this.user._id }, { $set: { isAdmin: true } }) .calledWith(
{ _id: this.user._id },
{
$set: { isAdmin: true },
emails: [{ email: this.user.email }]
}
)
.should.equal(true) .should.equal(true)
}) })