Merge pull request #665 from sharelatex/afc-import-team-invites

Add method to import invites
This commit is contained in:
Alberto Fernández-Capel 2018-06-22 09:55:19 +01:00 committed by GitHub
commit d36dbfda07
2 changed files with 30 additions and 1 deletions

View file

@ -56,6 +56,20 @@ module.exports = TeamInvitesHandler =
return callback(error) if error?
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) ->
logger.log {userId}, "Accepting invite"
TeamInvitesHandler.getInvite token, (err, invite, subscription) ->
@ -93,7 +107,6 @@ createInvite = (subscription, email, inviterName, callback) ->
return callback(error) if error?
return callback(reason) unless possible
invite = subscription.teamInvites.find (invite) -> invite.email == email
if !invite?

View file

@ -175,6 +175,22 @@ describe "TeamInvitesHandler", ->
).should.equal true
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", ->
beforeEach ->
@user = {