mirror of
https://github.com/overleaf/overleaf.git
synced 2025-01-27 07:51:50 +00:00
Merge pull request #3221 from overleaf/jel-institution-sso-email
Note which institution email was linked/unlinked in email alert GitOrigin-RevId: 7e5ef743c8ec8b12c14f833fdd2b01676c95c1b6
This commit is contained in:
parent
9d3f2eb7dc
commit
35897cf492
2 changed files with 25 additions and 9 deletions
|
@ -128,14 +128,17 @@ async function _addInstitutionEmail(userId, email, providerId, auditLog) {
|
|||
}
|
||||
}
|
||||
|
||||
async function _sendLinkedEmail(userId, providerName) {
|
||||
async function _sendLinkedEmail(userId, providerName, institutionEmail) {
|
||||
const user = await UserGetter.promises.getUser(userId, { email: 1 })
|
||||
const emailOptions = {
|
||||
to: user.email,
|
||||
actionDescribed: `an Institutional SSO account at ${providerName} was linked to your account ${
|
||||
user.email
|
||||
}`,
|
||||
action: 'institutional SSO account linked'
|
||||
action: 'institutional SSO account linked',
|
||||
message: [
|
||||
`<span style="display:inline-block;padding: 0 20px;width:100%;">Linked: <br/><b>${institutionEmail}</b></span>`
|
||||
]
|
||||
}
|
||||
EmailHandler.sendEmail('securityAlert', emailOptions, error => {
|
||||
if (error) {
|
||||
|
@ -144,11 +147,14 @@ async function _sendLinkedEmail(userId, providerName) {
|
|||
})
|
||||
}
|
||||
|
||||
function _sendUnlinkedEmail(primaryEmail, providerName) {
|
||||
function _sendUnlinkedEmail(primaryEmail, providerName, institutionEmail) {
|
||||
const emailOptions = {
|
||||
to: primaryEmail,
|
||||
actionDescribed: `an Institutional SSO account at ${providerName} is no longer linked to your account ${primaryEmail}`,
|
||||
action: 'institutional SSO account no longer linked'
|
||||
actionDescribed: `an Institutional SSO account at ${providerName} was unlinked from your account ${primaryEmail}`,
|
||||
action: 'institutional SSO account no longer linked',
|
||||
message: [
|
||||
`<span style="display:inline-block;padding: 0 20px;width:100%;">No longer linked: <br/><b>${institutionEmail}</b></span>`
|
||||
]
|
||||
}
|
||||
EmailHandler.sendEmail('securityAlert', emailOptions, error => {
|
||||
if (error) {
|
||||
|
@ -208,7 +214,7 @@ async function linkAccounts(
|
|||
auditLog
|
||||
)
|
||||
await _addInstitutionEmail(userId, institutionEmail, providerId, auditLog)
|
||||
await _sendLinkedEmail(userId, providerName)
|
||||
await _sendLinkedEmail(userId, providerName, institutionEmail)
|
||||
// update v1 affiliations record
|
||||
if (hasEntitlement) {
|
||||
await InstitutionsAPI.promises.addEntitlement(userId, institutionEmail)
|
||||
|
@ -256,7 +262,7 @@ async function unlinkAccounts(
|
|||
// update v1 affiliations record
|
||||
await InstitutionsAPI.promises.removeEntitlement(userId, institutionEmail)
|
||||
// send email
|
||||
_sendUnlinkedEmail(primaryEmail, providerName)
|
||||
_sendUnlinkedEmail(primaryEmail, providerName, institutionEmail)
|
||||
}
|
||||
|
||||
async function updateEntitlement(
|
||||
|
|
|
@ -5,6 +5,8 @@ const SandboxedModule = require('sandboxed-module')
|
|||
const modulePath = '../../../../app/src/Features/User/SAMLIdentityManager.js'
|
||||
|
||||
describe('SAMLIdentityManager', function() {
|
||||
const linkedEmail = 'another@example.com'
|
||||
|
||||
beforeEach(function() {
|
||||
this.Errors = {
|
||||
EmailExistsError: sinon.stub(),
|
||||
|
@ -274,7 +276,13 @@ describe('SAMLIdentityManager', function() {
|
|||
},
|
||||
() => {
|
||||
expect(this.User.update).to.have.been.called
|
||||
expect(this.EmailHandler.sendEmail).to.have.been.called
|
||||
expect(this.EmailHandler.sendEmail).to.have.been.calledOnce
|
||||
const emailArgs = this.EmailHandler.sendEmail.lastCall.args
|
||||
expect(emailArgs[0]).to.equal('securityAlert')
|
||||
expect(emailArgs[1].to).to.equal(this.user.email)
|
||||
expect(emailArgs[1].actionDescribed).to.contain('was linked')
|
||||
expect(emailArgs[1].message[0]).to.contain('Linked')
|
||||
expect(emailArgs[1].message[0]).to.contain(this.user.email)
|
||||
}
|
||||
)
|
||||
})
|
||||
|
@ -282,7 +290,6 @@ describe('SAMLIdentityManager', function() {
|
|||
})
|
||||
|
||||
describe('unlinkAccounts', function() {
|
||||
const linkedEmail = 'another@example.com'
|
||||
it('should update the audit log', async function() {
|
||||
await this.SAMLIdentityManager.unlinkAccounts(
|
||||
this.user._id,
|
||||
|
@ -344,6 +351,9 @@ describe('SAMLIdentityManager', function() {
|
|||
const emailArgs = this.EmailHandler.sendEmail.lastCall.args
|
||||
expect(emailArgs[0]).to.equal('securityAlert')
|
||||
expect(emailArgs[1].to).to.equal(this.user.email)
|
||||
expect(emailArgs[1].actionDescribed).to.contain('was unlinked')
|
||||
expect(emailArgs[1].message[0]).to.contain('No longer linked')
|
||||
expect(emailArgs[1].message[0]).to.contain(linkedEmail)
|
||||
})
|
||||
|
||||
describe('errors', function() {
|
||||
|
|
Loading…
Reference in a new issue