start adding the ProjectInvite workflow.

This commit is contained in:
Shane Kilkelly 2016-07-21 15:56:41 +01:00
parent e0562a2301
commit d9c6df0e47
3 changed files with 58 additions and 1 deletions

View file

@ -3,6 +3,7 @@ EmailHandler = require("../Email/EmailHandler")
Settings = require "settings-sharelatex" Settings = require "settings-sharelatex"
module.exports = module.exports =
notifyUserOfProjectShare: (project_id, email, callback)-> notifyUserOfProjectShare: (project_id, email, callback)->
Project Project
.findOne(_id: project_id ) .findOne(_id: project_id )
@ -22,4 +23,19 @@ module.exports =
"rs=ci" # referral source = collaborator invite "rs=ci" # referral source = collaborator invite
].join("&") ].join("&")
owner: project.owner_ref owner: project.owner_ref
EmailHandler.sendEmail "projectSharedWithYou", emailOptions, callback EmailHandler.sendEmail "projectSharedWithYou", emailOptions, callback
notifyUserOfProjectInvite: (project_id, email, invite, callback)->
Project
.findOne(_id: project_id )
.select("name owner_ref")
.populate('owner_ref')
.exec (err, project)->
emailOptions =
to: email
replyTo: project.owner_ref.email
project:
name: project.name
inviteUrl: "#{Settings.siteUrl}/project/#{project._id}/invite/token/#{invite.token}"
owner: project.owner_ref
EmailHandler.sendEmail "projectInvite", emailOptions, callback

View file

@ -1,5 +1,6 @@
UserCreator = require('../User/UserCreator') UserCreator = require('../User/UserCreator')
Project = require("../../models/Project").Project Project = require("../../models/Project").Project
ProjectInvite = require("../../models/ProjectInvite").ProjectInvite
mimelib = require("mimelib") mimelib = require("mimelib")
logger = require('logger-sharelatex') logger = require('logger-sharelatex')
UserGetter = require "../User/UserGetter" UserGetter = require "../User/UserGetter"
@ -8,10 +9,30 @@ CollaboratorsEmailHandler = require "./CollaboratorsEmailHandler"
Async = require "async" Async = require "async"
PrivilegeLevels = require "../Authorization/PrivilegeLevels" PrivilegeLevels = require "../Authorization/PrivilegeLevels"
Errors = require "../Errors/Errors" Errors = require "../Errors/Errors"
Crypto = require 'crypto'
module.experts = CollaboratorsInviteHandler = module.experts = CollaboratorsInviteHandler =
inviteToProject: (projectId, sendingUserId, email, privileges, callback=(err,invite)->) -> inviteToProject: (projectId, sendingUserId, email, privileges, callback=(err,invite)->) ->
logger.log {projectId, sendingUserId, email, privileges}, "adding invite"
Crypto.randomBytes 24, (err, buffer) ->
if err?
logger.err {err, projectId, sendingUserId, email}, "error generating random token"
return callback(err)
token = buffer.toString('hex')
invite = new ProjectInvite {
email: email
token: token
sendingUserId: sendingUserId
projectId: projectId
privileges: privileges
}
ProjectInvite.save (err) ->
if err?
logger.err {err, projectId, sendingUserId, email}, "error saving token"
return callback(err)
CollaboratorsEmailHandler.notifyUserOfProjectInvite projectId, email, invite
callback(null, invite)
revokeInvite: (projectId, inviteId, callback=(err)->) -> revokeInvite: (projectId, inviteId, callback=(err)->) ->

View file

@ -87,6 +87,26 @@ templates.projectSharedWithYou =
<p> <a href="<%= siteUrl %>">#{settings.appName}</a></p> <p> <a href="<%= siteUrl %>">#{settings.appName}</a></p>
""" """
templates.projectInvite =
subject: _.template "<%= owner.email %> wants to share <%= project.name %> with you"
layout: NotificationEmailLayout
type:"notification"
compiledTemplate: _.template """
<p>Hi, <%= owner.email %> wants to share <a href="<%= project.url %>">'<%= project.name %>'</a> with you</p>
<center>
<div style="width:200px;background-color:#a93629;border:1px solid #e24b3b;border-radius:3px;padding:15px; margin:24px;">
<div style="padding-right:10px;padding-left:10px">
<a href="<%= inviteUrl %>" style="text-decoration:none" target="_blank">
<span style= "font-size:16px;font-family:Helvetica,Arial;font-weight:400;color:#fff;white-space:nowrap;display:block; text-align:center">
View Invite
</span>
</a>
</div>
</div>
</center>
<p> Thank you</p>
<p> <a href="<%= siteUrl %>">#{settings.appName}</a></p>
"""
templates.completeJoinGroupAccount = templates.completeJoinGroupAccount =
subject: _.template "Verify Email to join <%= group_name %> group" subject: _.template "Verify Email to join <%= group_name %> group"