mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
WIP: notification when user is sent an invite
This commit is contained in:
parent
d59b51aacd
commit
9b46c1b1f7
3 changed files with 37 additions and 3 deletions
|
@ -6,6 +6,7 @@ CollaboratorsInviteHandler = require('./CollaboratorsInviteHandler')
|
|||
logger = require('logger-sharelatex')
|
||||
EmailHelper = require "../Helpers/EmailHelper"
|
||||
EditorRealTimeController = require("../Editor/EditorRealTimeController")
|
||||
NotificationsBuilder = require("../Notifications/NotificationsBuilder")
|
||||
|
||||
|
||||
module.exports = CollaboratorsInviteController =
|
||||
|
@ -19,10 +20,27 @@ module.exports = CollaboratorsInviteController =
|
|||
return next(err)
|
||||
res.json({invites: invites})
|
||||
|
||||
_trySendInviteNotification: (projectId, sendingUser, invite, callback=(err)->) ->
|
||||
email = invite.email
|
||||
UserGetter.getUser {email: email}, {_id: 1}, (err, existingUser) ->
|
||||
if err?
|
||||
logger.err {projectId, email}, "error checking if user exists"
|
||||
return next(err)
|
||||
if existingUser
|
||||
ProjectGetter.getProject projectId, (err, project) ->
|
||||
if err?
|
||||
logger.err {projectId, email}, "error getting project"
|
||||
return next(err)
|
||||
if !project
|
||||
logger.log {projectId}, "no project found while sending notification, returning"
|
||||
return callback()
|
||||
NotificationsBuilder.projectInvite(invite, project, sendingUser, existingUser).create(callback)
|
||||
|
||||
inviteToProject: (req, res, next) ->
|
||||
projectId = req.params.Project_id
|
||||
email = req.body.email
|
||||
sendingUserId = req.session?.user?._id
|
||||
sendingUser = req.session.user
|
||||
sendingUserId = sendingUser._id
|
||||
logger.log {projectId, email, sendingUserId}, "inviting to project"
|
||||
LimitationsManager.canAddXCollaborators projectId, 1, (error, allowed) =>
|
||||
return next(error) if error?
|
||||
|
@ -40,6 +58,8 @@ module.exports = CollaboratorsInviteController =
|
|||
return next(err)
|
||||
logger.log {projectId, email, sendingUserId}, "invite created"
|
||||
EditorRealTimeController.emitToRoom projectId, 'project:membership:changed', {invites: true}
|
||||
# async check if email is for an existing user, send a notification
|
||||
CollaboratorsInviteController._trySendInviteNotification(projectId, sendingUser, invite, ()->)
|
||||
return res.json {invite: invite}
|
||||
|
||||
revokeInvite: (req, res, next) ->
|
||||
|
|
|
@ -7,6 +7,7 @@ PrivilegeLevels = require "../Authorization/PrivilegeLevels"
|
|||
Errors = require "../Errors/Errors"
|
||||
Crypto = require 'crypto'
|
||||
|
||||
|
||||
module.exports = CollaboratorsInviteHandler =
|
||||
|
||||
getAllInvites: (projectId, callback=(err, invites)->) ->
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
logger = require("logger-sharelatex")
|
||||
NotificationsHandler = require("./NotificationsHandler")
|
||||
|
||||
module.exports =
|
||||
module.exports =
|
||||
|
||||
groupPlan: (user, licence)->
|
||||
key : "join-sub-#{licence.subscription_id}"
|
||||
create: (callback = ->)->
|
||||
messageOpts =
|
||||
messageOpts =
|
||||
groupName: licence.name
|
||||
subscription_id: licence.subscription_id
|
||||
logger.log user_id:user._id, key:key, "creating notification key for user"
|
||||
|
@ -14,3 +14,16 @@ module.exports =
|
|||
|
||||
read: (callback = ->)->
|
||||
NotificationsHandler.markAsReadWithKey user._id, @key, callback
|
||||
|
||||
projectInvite: (invite, project, sendingUser, user) ->
|
||||
key: "project-invite-#{invite._id}"
|
||||
create: (callback=()->) ->
|
||||
messageOpts =
|
||||
userName: sendingUser.first_name
|
||||
projectName: project.name
|
||||
projectId: project._id.toString()
|
||||
token: invite.token
|
||||
logger.log {user_id: user._id, project_id: project._id, invite_id: invite._id, key: @key}, "creating project invite notification for user"
|
||||
NotificationsHandler.createNotification user._id, @key, "notification_project_invite", messageOpts, callback
|
||||
read: (callback=()->) ->
|
||||
NotificationsHandler.markAsReadWithKey user._id, @key, callback
|
||||
|
|
Loading…
Reference in a new issue