mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-04 22:59:01 +02:00
Merge pull request #665 from sharelatex/afc-import-team-invites
Add method to import invites
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user