Przeglądaj źródła

Merge pull request #328 from sharelatex/sk-plain-text-email

Sk plain text email
Shane Kilkelly 10 lat temu
rodzic
commit
95a66bbf00

+ 2 - 2
services/web/app/coffee/Features/Collaborators/CollaboratorsInviteHandler.coffee

@@ -82,7 +82,7 @@ module.exports = CollaboratorsInviteHandler =
 					if err?
 					if err?
 						logger.err {projectId, email}, "error sending messages for invite"
 						logger.err {projectId, email}, "error sending messages for invite"
 				callback(null, invite)
 				callback(null, invite)
-				
+
 
 
 	revokeInvite: (projectId, inviteId, callback=(err)->) ->
 	revokeInvite: (projectId, inviteId, callback=(err)->) ->
 		logger.log {projectId, inviteId}, "removing invite"
 		logger.log {projectId, inviteId}, "removing invite"
@@ -104,7 +104,7 @@ module.exports = CollaboratorsInviteHandler =
 				return callback(null)
 				return callback(null)
 			CollaboratorsInviteHandler._sendMessages projectId, sendingUser, invite, (err) ->
 			CollaboratorsInviteHandler._sendMessages projectId, sendingUser, invite, (err) ->
 				if err?
 				if err?
-					logger.err {projectid, inviteId}, "error resending invite messages"
+					logger.err {projectId, inviteId}, "error resending invite messages"
 					return callback(err)
 					return callback(err)
 				callback(null)
 				callback(null)
 
 

+ 10 - 0
services/web/app/coffee/Features/Email/EmailBuilder.coffee

@@ -91,6 +91,15 @@ templates.projectInvite =
 	subject: _.template "<%= project.name %> - shared by <%= owner.email %>"
 	subject: _.template "<%= project.name %> - shared by <%= owner.email %>"
 	layout: NotificationEmailLayout
 	layout: NotificationEmailLayout
 	type:"notification"
 	type:"notification"
+	plainTextTemplate: _.template """
+Hi, <%= owner.email %> wants to share '<%= project.name %>' with you.
+
+Follow this link to view the project: <%= inviteUrl %>
+
+Thank you
+
+#{settings.appName} - <%= siteUrl %>
+"""
 	compiledTemplate: _.template """
 	compiledTemplate: _.template """
 <p>Hi, <%= owner.email %> wants to share <a href="<%= project.url %>">'<%= project.name %>'</a> with you</p>
 <p>Hi, <%= owner.email %> wants to share <a href="<%= project.url %>">'<%= project.name %>'</a> with you</p>
 <center>
 <center>
@@ -137,5 +146,6 @@ module.exports =
 		return {
 		return {
 			subject : template.subject(opts)
 			subject : template.subject(opts)
 			html: template.layout(opts)
 			html: template.layout(opts)
+			text: template?.plainTextTemplate?(opts)
 			type:template.type
 			type:template.type
 		}
 		}

+ 3 - 2
services/web/app/coffee/Features/Email/EmailHandler.coffee

@@ -3,7 +3,7 @@ EmailBuilder = require "./EmailBuilder"
 EmailSender = require "./EmailSender"
 EmailSender = require "./EmailSender"
 
 
 if !settings.email?
 if !settings.email?
-	settings.email = 
+	settings.email =
 		lifecycleEnabled:false
 		lifecycleEnabled:false
 
 
 
 
@@ -14,6 +14,7 @@ module.exports =
 		if email.type == "lifecycle" and !settings.email.lifecycle
 		if email.type == "lifecycle" and !settings.email.lifecycle
 			return callback()
 			return callback()
 		opts.html = email.html
 		opts.html = email.html
+		opts.text = email.text
 		opts.subject = email.subject
 		opts.subject = email.subject
 		EmailSender.sendEmail opts, (err)->
 		EmailSender.sendEmail opts, (err)->
-			callback(err)
+			callback(err)

+ 1 - 0
services/web/app/coffee/Features/Email/EmailSender.coffee

@@ -49,6 +49,7 @@ module.exports =
 			from: defaultFromAddress
 			from: defaultFromAddress
 			subject: options.subject
 			subject: options.subject
 			html: options.html
 			html: options.html
+			text: options.text
 			replyTo: options.replyTo || Settings.email.replyToAddress
 			replyTo: options.replyTo || Settings.email.replyToAddress
 			socketTimeout: 30 * 1000
 			socketTimeout: 30 * 1000
 		client.sendMail options, (err, res)->
 		client.sendMail options, (err, res)->

+ 25 - 0
services/web/test/UnitTests/coffee/Email/EmailBuilderTests.coffee

@@ -34,6 +34,31 @@ describe "EmailBuilder", ->
 			@email.html.indexOf(@opts.owner.email).should.not.equal -1
 			@email.html.indexOf(@opts.owner.email).should.not.equal -1
 			@email.subject.indexOf(@opts.owner.email).should.not.equal -1
 			@email.subject.indexOf(@opts.owner.email).should.not.equal -1
 
 
+		it 'should not have text component', ->
+			expect(@email.html?).to.equal true
+			expect(@email.text?).to.equal false
+
+		it "should not have undefined in it", ->
+			@email.html.indexOf("undefined").should.equal -1
+			@email.subject.indexOf("undefined").should.equal -1
+
+	describe "projectInvite", ->
+		beforeEach ->
+			@opts =
+				to:"bob@bob.com"
+				first_name:"bob"
+				owner:
+					email:"sally@hally.com"
+				inviteUrl: "http://example.com/invite"
+				project:
+					url:"http://www.project.com"
+					name:"standard project"
+			@email = @EmailBuilder.buildEmail("projectInvite", @opts)
+
+		it 'should have html and text properties', ->
+			expect(@email.html?).to.equal true
+			expect(@email.text?).to.equal true
+
 		it "should not have undefined in it", ->
 		it "should not have undefined in it", ->
 			@email.html.indexOf("undefined").should.equal -1
 			@email.html.indexOf("undefined").should.equal -1
 			@email.subject.indexOf("undefined").should.equal -1
 			@email.subject.indexOf("undefined").should.equal -1

+ 18 - 2
services/web/test/UnitTests/coffee/Email/EmailHandlerTests.coffee

@@ -10,9 +10,9 @@ describe "EmailHandler", ->
 
 
 	beforeEach ->
 	beforeEach ->
 
 
-		@settings = 
+		@settings =
 			email:{}
 			email:{}
-		@EmailBuilder = 
+		@EmailBuilder =
 			buildEmail:sinon.stub()
 			buildEmail:sinon.stub()
 		@EmailSender =
 		@EmailSender =
 			sendEmail:sinon.stub()
 			sendEmail:sinon.stub()
@@ -74,3 +74,19 @@ describe "EmailHandler", ->
 			@EmailHandler.sendEmail "welcome", opts, =>
 			@EmailHandler.sendEmail "welcome", opts, =>
 				@EmailSender.sendEmail.called.should.equal true
 				@EmailSender.sendEmail.called.should.equal true
 				done()
 				done()
+
+		describe 'with plain-text email content', () ->
+
+			beforeEach ->
+				@text = "hello there"
+
+			it 'should pass along the text field', (done) ->
+				@EmailBuilder.buildEmail.returns({html: @html, text: @text})
+				@EmailSender.sendEmail.callsArgWith(1)
+				opts =
+					to: "bob@bob.com"
+				@EmailHandler.sendEmail "welcome", opts, =>
+					args = @EmailSender.sendEmail.args[0][0]
+					args.html.should.equal @html
+					args.text.should.equal @text
+					done()

+ 17 - 1
services/web/test/UnitTests/coffee/Email/EmailSenderTests.coffee

@@ -31,7 +31,7 @@ describe "EmailSender", ->
 				warn:->
 				warn:->
 				err:->
 				err:->
 			"../../infrastructure/Metrics": inc:->
 			"../../infrastructure/Metrics": inc:->
-				
+
 
 
 
 
 		@opts =
 		@opts =
@@ -83,3 +83,19 @@ describe "EmailSender", ->
 				args = @sesClient.sendMail.args[0][0]
 				args = @sesClient.sendMail.args[0][0]
 				args.replyTo.should.equal @opts.replyTo
 				args.replyTo.should.equal @opts.replyTo
 				done()
 				done()
+
+		describe 'with plain-text email content', () ->
+
+			beforeEach ->
+				@opts.text = "hello there"
+
+			it "should set the text property on the email to send", (done)->
+				@sesClient.sendMail.callsArgWith(1)
+
+				@sender.sendEmail @opts, =>
+					args = @sesClient.sendMail.args[0][0]
+					args.html.should.equal @opts.html
+					args.text.should.equal @opts.text
+					args.to.should.equal @opts.to
+					args.subject.should.equal @opts.subject
+					done()