mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-09 22:45:49 +00:00
Merge pull request #3297 from overleaf/jel-unlink-email
Update unlinked email wording GitOrigin-RevId: 976349f1003e6b53ab04b27870356d9452464a39
This commit is contained in:
parent
1db0b27704
commit
5f59437ef9
3 changed files with 41 additions and 33 deletions
20
services/web/app/src/Features/Email/EmailOptionsHelper.js
Normal file
20
services/web/app/src/Features/Email/EmailOptionsHelper.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
function _getIndefiniteArticle(providerName) {
|
||||
const vowels = ['a', 'e', 'i', 'o', 'u']
|
||||
if (vowels.includes(providerName.charAt(0).toLowerCase())) return 'an'
|
||||
return 'a'
|
||||
}
|
||||
|
||||
function linkOrUnlink(accountLinked, providerName, email) {
|
||||
const action = accountLinked ? 'linked' : 'no longer linked'
|
||||
const actionDescribed = accountLinked ? 'was linked to' : 'was unlinked from'
|
||||
const indefiniteArticle = _getIndefiniteArticle(providerName)
|
||||
return {
|
||||
to: email,
|
||||
action: `${providerName} account ${action}`,
|
||||
actionDescribed: `${indefiniteArticle} ${providerName} account ${actionDescribed} your account ${email}`
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
linkOrUnlink
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
const APP_ROOT = '../../../../app/src'
|
||||
const UserAuditLogHandler = require(`${APP_ROOT}/Features/User/UserAuditLogHandler`)
|
||||
const EmailHandler = require(`${APP_ROOT}/Features/Email/EmailHandler`)
|
||||
const EmailOptionsHelper = require(`${APP_ROOT}/Features/Email/EmailOptionsHelper`)
|
||||
const Errors = require('../Errors/Errors')
|
||||
const _ = require('lodash')
|
||||
const logger = require('logger-sharelatex')
|
||||
|
@ -10,12 +11,6 @@ const { promisifyAll } = require(`${APP_ROOT}/util/promises`)
|
|||
|
||||
const oauthProviders = settings.oauthProviders || {}
|
||||
|
||||
function _getIndefiniteArticle(providerName) {
|
||||
const vowels = ['a', 'e', 'i', 'o', 'u']
|
||||
if (vowels.includes(providerName.charAt(0).toLowerCase())) return 'an'
|
||||
return 'a'
|
||||
}
|
||||
|
||||
function getUser(providerId, externalUserId, callback) {
|
||||
if (providerId == null || externalUserId == null) {
|
||||
return callback(new Error('invalid arguments'))
|
||||
|
@ -189,22 +184,17 @@ function _getUserQuery(providerId, externalUserId) {
|
|||
}
|
||||
|
||||
function _sendSecurityAlert(accountLinked, providerId, user, userId) {
|
||||
const operation = accountLinked ? 'linked' : 'no longer linked'
|
||||
const tense = accountLinked ? 'was' : 'is'
|
||||
const providerName = oauthProviders[providerId].name
|
||||
const indefiniteArticle = _getIndefiniteArticle(providerName)
|
||||
const emailOptions = {
|
||||
to: user.email,
|
||||
action: `${providerName} account ${operation}`,
|
||||
actionDescribed: `${indefiniteArticle} ${providerName} account ${tense} ${operation} to your account ${
|
||||
user.email
|
||||
}`
|
||||
}
|
||||
const emailOptions = EmailOptionsHelper.linkOrUnlink(
|
||||
accountLinked,
|
||||
providerName,
|
||||
user.email
|
||||
)
|
||||
EmailHandler.sendEmail('securityAlert', emailOptions, error => {
|
||||
if (error) {
|
||||
logger.error(
|
||||
{ error, userId },
|
||||
`could not send security alert email when ${providerName} ${operation}`
|
||||
{ err: error, userId },
|
||||
`could not send security alert email when ${emailOptions.action}`
|
||||
)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -117,13 +117,12 @@ describe('ThirdPartyIdentityManager', function() {
|
|||
this.auditLog,
|
||||
error => {
|
||||
expect(error).to.not.exist
|
||||
const loggerCall = this.logger.error.getCall(0)
|
||||
expect(loggerCall.args[0]).to.deep.equal({
|
||||
error: anError,
|
||||
userId: this.userId
|
||||
})
|
||||
expect(loggerCall.args[1]).to.contain(
|
||||
'could not send security alert email when Google linked'
|
||||
expect(this.logger.error.lastCall).to.be.calledWithExactly(
|
||||
{
|
||||
err: anError,
|
||||
userId: this.userId
|
||||
},
|
||||
'could not send security alert email when Google account linked'
|
||||
)
|
||||
done()
|
||||
}
|
||||
|
@ -142,7 +141,7 @@ describe('ThirdPartyIdentityManager', function() {
|
|||
const emailCall = this.EmailHandler.sendEmail.getCall(0)
|
||||
expect(emailCall.args[0]).to.equal('securityAlert')
|
||||
expect(emailCall.args[1].actionDescribed).to.contain(
|
||||
'an Orcid account is no longer linked'
|
||||
'an Orcid account was unlinked from'
|
||||
)
|
||||
})
|
||||
it('should update user audit log', async function() {
|
||||
|
@ -189,13 +188,12 @@ describe('ThirdPartyIdentityManager', function() {
|
|||
this.auditLog,
|
||||
error => {
|
||||
expect(error).to.not.exist
|
||||
const loggerCall = this.logger.error.getCall(0)
|
||||
expect(loggerCall.args[0]).to.deep.equal({
|
||||
error: anError,
|
||||
userId: this.userId
|
||||
})
|
||||
expect(loggerCall.args[1]).to.contain(
|
||||
'could not send security alert email when Google no longer linked'
|
||||
expect(this.logger.error.lastCall).to.be.calledWithExactly(
|
||||
{
|
||||
err: anError,
|
||||
userId: this.userId
|
||||
},
|
||||
'could not send security alert email when Google account no longer linked'
|
||||
)
|
||||
done()
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue