Honour invited_emails for the team being

We'll remove them soon, but we want to keep them for a while so
recent invites can join their teams.
This commit is contained in:
Alberto Fernández Capel 2018-06-07 16:22:38 +01:00
parent 670f24ef6f
commit a3bb99d755
5 changed files with 30 additions and 4 deletions

View file

@ -56,7 +56,10 @@ module.exports = LimitationsManager =
callback err, subscriptions.length > 0, subscriptions
teamHasReachedMemberLimit: (subscription) ->
currentTotal = (subscription.member_ids or []).length + (subscription.teamInvites or []).length
currentTotal = (subscription.member_ids or []).length
+ (subscription.teamInvites or []).length
+ (subscription.invited_emails or []).length
return currentTotal >= subscription.membersLimit
hasGroupMembersLimitReached: (user_id, callback = (err, limitReached, subscription)->)->

View file

@ -47,6 +47,9 @@ module.exports = SubscriptionGroupHandler =
users = []
for email in subscription.invited_emails or []
users.push buildEmailInviteViewModel(email)
for teamInvite in subscription.teamInvites or []
users.push buildEmailInviteViewModel(teamInvite.email)

View file

@ -47,6 +47,13 @@ module.exports = SubscriptionUpdater =
return callback(err)
FeaturesUpdater.refreshFeatures user_id, callback
removeEmailInviteFromGroup: (adminUser_id, email, callback)->
Subscription.update {
admin_id: adminUser_id
}, "$pull": {
invited_emails: email
}, callback
deleteSubscription: (subscription_id, callback = (error) ->) ->
SubscriptionLocator.getSubscription subscription_id, (err, subscription) ->
return callback(err) if err?

View file

@ -110,10 +110,18 @@ createInvite = (subscription, email, inviterName, callback) ->
return callback(error, invite)
removeInviteFromTeam = (subscriptionId, email, callback) ->
searchConditions = { _id: new ObjectId(subscriptionId.toString()) }
updateOp = { $pull: { teamInvites: { email: email.trim().toLowerCase() } } }
email = email.trim().toLowerCase()
searchConditions = { _id: new ObjectId(subscriptionId.toString()) }
removeInvite = { $pull: { teamInvites: { email: email } } }
removeLegacyInvite = { $pull: { invited_emails: email } }
async.series [
(cb) -> Subscription.update(searchConditions, removeInvite, cb),
(cb) -> Subscription.update(searchConditions, removeLegacyInvite, cb),
], callback
Subscription.update(searchConditions, updateOp, callback)
checkIfInviteIsPossible = (subscription, email, callback = (error, possible, reason) -> ) ->
if LimitationsManager.teamHasReachedMemberLimit(subscription)

View file

@ -201,6 +201,11 @@ describe "TeamInvitesHandler", ->
{ _id: new ObjectId("55153a8014829a865bbf700d") },
{ '$pull': { teamInvites: { email: "jorah@mormont.org" } } }
).should.eq true
@Subscription.update.calledWith(
{ _id: new ObjectId("55153a8014829a865bbf700d") },
{ '$pull': { invited_emails: "jorah@mormont.org" } }
).should.eq true
done()
describe "createTeamInvitesForLegacyInvitedEmail", (done) ->