mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Add method to import invites
This commit is contained in:
parent
55112dc7dc
commit
81c102b501
2 changed files with 30 additions and 1 deletions
|
@ -56,6 +56,20 @@ module.exports = TeamInvitesHandler =
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
createInvite(subscription, email, inviterName, callback)
|
createInvite(subscription, email, inviterName, callback)
|
||||||
|
|
||||||
|
importInvite: (subscription, inviterName, email, token, sentAt, callback) ->
|
||||||
|
checkIfInviteIsPossible subscription, email, (error, possible, reason) ->
|
||||||
|
return callback(error) if error?
|
||||||
|
return callback(reason) unless possible
|
||||||
|
|
||||||
|
subscription.teamInvites.push({
|
||||||
|
email: email
|
||||||
|
inviterName: inviterName
|
||||||
|
token: token
|
||||||
|
sentAt: sentAt
|
||||||
|
})
|
||||||
|
|
||||||
|
subscription.save callback
|
||||||
|
|
||||||
acceptInvite: (token, userId, callback) ->
|
acceptInvite: (token, userId, callback) ->
|
||||||
logger.log {userId}, "Accepting invite"
|
logger.log {userId}, "Accepting invite"
|
||||||
TeamInvitesHandler.getInvite token, (err, invite, subscription) ->
|
TeamInvitesHandler.getInvite token, (err, invite, subscription) ->
|
||||||
|
@ -93,7 +107,6 @@ createInvite = (subscription, email, inviterName, callback) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
return callback(reason) unless possible
|
return callback(reason) unless possible
|
||||||
|
|
||||||
|
|
||||||
invite = subscription.teamInvites.find (invite) -> invite.email == email
|
invite = subscription.teamInvites.find (invite) -> invite.email == email
|
||||||
|
|
||||||
if !invite?
|
if !invite?
|
||||||
|
|
|
@ -175,6 +175,22 @@ describe "TeamInvitesHandler", ->
|
||||||
).should.equal true
|
).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
describe "importInvite", ->
|
||||||
|
beforeEach ->
|
||||||
|
@sentAt = new Date()
|
||||||
|
|
||||||
|
it "can imports an invite from v1", ->
|
||||||
|
@TeamInvitesHandler.importInvite @subscription, "A-Team", "hannibal@a-team.org",
|
||||||
|
"secret", @sentAt, (error) =>
|
||||||
|
expect(error).not.to.exist
|
||||||
|
|
||||||
|
@subscription.save.calledOnce.should.eq true
|
||||||
|
|
||||||
|
invite = @subscription.teamInvites.find (i) -> i.email == "hannibal@a-team.org"
|
||||||
|
expect(invite.token).to.eq("secret")
|
||||||
|
expect(invite.sentAt).to.eq(@sentAt)
|
||||||
|
|
||||||
|
|
||||||
describe "acceptInvite", ->
|
describe "acceptInvite", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@user = {
|
@user = {
|
||||||
|
|
Loading…
Reference in a new issue