mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
added settings check on sending lifcycle emails out
This commit is contained in:
parent
eb92e5832b
commit
5bacb2d784
4 changed files with 52 additions and 20 deletions
|
@ -1,14 +1,14 @@
|
||||||
EmailTemplator = require "./EmailTemplator"
|
settings = require("settings-sharelatex")
|
||||||
|
EmailBuilder = require "./EmailBuilder"
|
||||||
EmailSender = require "./EmailSender"
|
EmailSender = require "./EmailSender"
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
|
|
||||||
sendEmail : (emailType, opts, callback)->
|
sendEmail : (emailType, opts, callback)->
|
||||||
email = EmailTemplator.buildEmail emailType, opts
|
email = EmailBuilder.buildEmail emailType, opts
|
||||||
|
if email.type == "lifecycle" and !settings.email.lifecycle
|
||||||
|
return callback()
|
||||||
opts.html = email.html
|
opts.html = email.html
|
||||||
opts.subject = email.subject
|
opts.subject = email.subject
|
||||||
EmailSender.sendEmail opts, (err)->
|
EmailSender.sendEmail opts, (err)->
|
||||||
callback(err)
|
callback(err)
|
||||||
|
|
||||||
# module.exports.sendEmail "welcome", {first_name:"henry", to:"henry.oswald@gmail.com"}, ->
|
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ Settings = require('settings-sharelatex')
|
||||||
metrics = require("../../infrastructure/Metrics")
|
metrics = require("../../infrastructure/Metrics")
|
||||||
ses = require('node-ses')
|
ses = require('node-ses')
|
||||||
|
|
||||||
if Settings.ses?.key? and Settings.ses?.key != "" and Settings.ses?.secret? and Settings.ses?.secret != ""
|
if Settings.email?.ses? and Settings.email.ses?.key? and Settings.email.ses?.key != "" and Settings.email.ses?.secret? and Settings.email.ses?.secret != ""
|
||||||
client = ses.createClient({ key: Settings.ses.key, secret: Settings.ses.secret });
|
client = ses.createClient({ key: Settings.email.ses.key, secret: Settings.email.ses.secret });
|
||||||
else
|
else
|
||||||
logger.warn "AWS SES credentials are not configured. No emails will be sent."
|
logger.warn "AWS SES credentials are not configured. No emails will be sent."
|
||||||
client =
|
client =
|
||||||
|
|
|
@ -26,6 +26,7 @@ module.exports =
|
||||||
secret: ""
|
secret: ""
|
||||||
bucketName : ""
|
bucketName : ""
|
||||||
|
|
||||||
|
|
||||||
# Databases
|
# Databases
|
||||||
# ---------
|
# ---------
|
||||||
mongo:
|
mongo:
|
||||||
|
@ -155,6 +156,11 @@ module.exports =
|
||||||
# ShareLaTeX's help desk is provided by tenderapp.com
|
# ShareLaTeX's help desk is provided by tenderapp.com
|
||||||
# tenderUrl: ""
|
# tenderUrl: ""
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# email:
|
||||||
|
# fromAddress: ""
|
||||||
|
# replyTo: ""
|
||||||
|
# lifecycle: false
|
||||||
# ShareLaTeX uses Amazon's SES api to send transactional emails.
|
# ShareLaTeX uses Amazon's SES api to send transactional emails.
|
||||||
# Uncomment these lines and provide your credentials to be able to send emails.
|
# Uncomment these lines and provide your credentials to be able to send emails.
|
||||||
# ses:
|
# ses:
|
||||||
|
|
|
@ -10,13 +10,14 @@ describe "EmailHandler", ->
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
|
||||||
@settings = {}
|
@settings =
|
||||||
@EmailTemplator =
|
email:{}
|
||||||
|
@EmailBuilder =
|
||||||
buildEmail:sinon.stub()
|
buildEmail:sinon.stub()
|
||||||
@EmailSender =
|
@EmailSender =
|
||||||
sendEmail:sinon.stub()
|
sendEmail:sinon.stub()
|
||||||
@EmailHandler = SandboxedModule.require modulePath, requires:
|
@EmailHandler = SandboxedModule.require modulePath, requires:
|
||||||
"./EmailTemplator":@EmailTemplator
|
"./EmailBuilder":@EmailBuilder
|
||||||
"./EmailSender":@EmailSender
|
"./EmailSender":@EmailSender
|
||||||
"settings-sharelatex":@settings
|
"settings-sharelatex":@settings
|
||||||
"logger-sharelatex": log:->
|
"logger-sharelatex": log:->
|
||||||
|
@ -26,7 +27,7 @@ describe "EmailHandler", ->
|
||||||
describe "send email", ->
|
describe "send email", ->
|
||||||
|
|
||||||
it "should use the correct options", (done)->
|
it "should use the correct options", (done)->
|
||||||
@EmailTemplator.buildEmail.returns({html:@html})
|
@EmailBuilder.buildEmail.returns({html:@html})
|
||||||
@EmailSender.sendEmail.callsArgWith(1)
|
@EmailSender.sendEmail.callsArgWith(1)
|
||||||
|
|
||||||
opts =
|
opts =
|
||||||
|
@ -36,10 +37,8 @@ describe "EmailHandler", ->
|
||||||
args.html.should.equal @html
|
args.html.should.equal @html
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it "should return the erroor", (done)->
|
it "should return the erroor", (done)->
|
||||||
@EmailTemplator.buildEmail.returns({html:@html})
|
@EmailBuilder.buildEmail.returns({html:@html})
|
||||||
@EmailSender.sendEmail.callsArgWith(1, "error")
|
@EmailSender.sendEmail.callsArgWith(1, "error")
|
||||||
|
|
||||||
opts =
|
opts =
|
||||||
|
@ -48,3 +47,30 @@ describe "EmailHandler", ->
|
||||||
@EmailHandler.sendEmail "welcome", opts, (err)=>
|
@EmailHandler.sendEmail "welcome", opts, (err)=>
|
||||||
err.should.equal "error"
|
err.should.equal "error"
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
it "should not send an email if lifecycle is not enabled", (done)->
|
||||||
|
@settings.email.lifecycle = false
|
||||||
|
@EmailBuilder.buildEmail.returns({type:"lifecycle"})
|
||||||
|
@EmailHandler.sendEmail "welcome", {}, =>
|
||||||
|
@EmailSender.sendEmail.called.should.equal false
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should send an email if lifecycle is not enabled but the type is notification", (done)->
|
||||||
|
@settings.email.lifecycle = false
|
||||||
|
@EmailBuilder.buildEmail.returns({type:"notification"})
|
||||||
|
@EmailSender.sendEmail.callsArgWith(1)
|
||||||
|
opts =
|
||||||
|
to: "bob@bob.com"
|
||||||
|
@EmailHandler.sendEmail "welcome", opts, =>
|
||||||
|
@EmailSender.sendEmail.called.should.equal true
|
||||||
|
done()
|
||||||
|
|
||||||
|
it "should send lifecycle email if it is enabled", (done)->
|
||||||
|
@settings.email.lifecycle = true
|
||||||
|
@EmailBuilder.buildEmail.returns({type:"lifecycle"})
|
||||||
|
@EmailSender.sendEmail.callsArgWith(1)
|
||||||
|
opts =
|
||||||
|
to: "bob@bob.com"
|
||||||
|
@EmailHandler.sendEmail "welcome", opts, =>
|
||||||
|
@EmailSender.sendEmail.called.should.equal true
|
||||||
|
done()
|
||||||
|
|
Loading…
Reference in a new issue