mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-24 18:22:01 +00:00
Merge pull request #3493 from overleaf/jel-reconfirmedAt-query
Simplify email confirmation method GitOrigin-RevId: 05cc41694d4edbb744de611d3a626b036d27e863
This commit is contained in:
parent
274dd56300
commit
26143d13d3
2 changed files with 8 additions and 9 deletions
|
@ -175,18 +175,16 @@ async function confirmEmail(userId, email) {
|
||||||
_id: userId,
|
_id: userId,
|
||||||
'emails.email': email
|
'emails.email': email
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// only update confirmedAt if it was not previously set
|
||||||
const update = {
|
const update = {
|
||||||
$set: {
|
$set: {
|
||||||
'emails.$.reconfirmedAt': confirmedAt
|
'emails.$.reconfirmedAt': confirmedAt
|
||||||
|
},
|
||||||
|
$min: {
|
||||||
|
'emails.$.confirmedAt': confirmedAt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const user = await UserGetter.promises.getUser(userId)
|
|
||||||
const emailUnconfirmed = user.emails.find(emailData => {
|
|
||||||
if (emailData.email === email && !emailData.confirmedAt) return true
|
|
||||||
})
|
|
||||||
if (emailUnconfirmed) {
|
|
||||||
update.$set['emails.$.confirmedAt'] = confirmedAt
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Features.hasFeature('affiliations')) {
|
if (Features.hasFeature('affiliations')) {
|
||||||
update.$unset = {
|
update.$unset = {
|
||||||
|
|
|
@ -718,7 +718,6 @@ describe('UserUpdater', function() {
|
||||||
describe('confirmEmail', function() {
|
describe('confirmEmail', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
this.UserUpdater.promises.updateUser = sinon.stub().resolves({ n: 1 })
|
this.UserUpdater.promises.updateUser = sinon.stub().resolves({ n: 1 })
|
||||||
this.UserGetter.promises.getUser.resolves(this.stubbedUser)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should update the email record', function(done) {
|
it('should update the email record', function(done) {
|
||||||
|
@ -735,8 +734,10 @@ describe('UserUpdater', function() {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
'emails.$.confirmedAt': new Date(),
|
|
||||||
'emails.$.reconfirmedAt': new Date()
|
'emails.$.reconfirmedAt': new Date()
|
||||||
|
},
|
||||||
|
$min: {
|
||||||
|
'emails.$.confirmedAt': new Date()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue