Ensure we can import both user and user stubs to teams

This commit is contained in:
Alberto Fernández Capel 2018-06-27 12:09:58 +01:00
parent 9f5e976539
commit 7e5ababe66
4 changed files with 19 additions and 5 deletions

View file

@ -1,12 +1,11 @@
_ = require("underscore")
logger = require('logger-sharelatex')
User = require('../../models/User').User
UserGetter = require('../User/UserGetter')
Settings = require "settings-sharelatex"
module.exports = ReferalFeatures =
getBonusFeatures: (user_id, callback = (error) ->) ->
query = _id: user_id
User.findOne query, (error, user) ->
UserGetter.getUserOrUserStubById user_id, { _id: 1 }, (error, user) ->
return callback(error) if error
return callback(new Error("user not found #{user_id} for assignBonus")) if !user?
logger.log user_id: user_id, refered_user_count: user.refered_user_count, "assigning bonus"

View file

@ -32,4 +32,7 @@ module.exports =
Subscription.find {member_ids: user_id}, {_id:1, planCode:1}, callback
getGroupsWithEmailInvite: (email, callback) ->
Subscription.find { invited_emails: email }, callback
Subscription.find { invited_emails: email }, callback
getGroupWithV1Id: (v1TeamId, callback) ->
Subscription.findOne { "overleaf.id": v1TeamId }, callback

View file

@ -24,6 +24,15 @@ module.exports = SubscriptionUpdater =
return callback(err) if err?
SubscriptionUpdater._updateSubscriptionFromRecurly recurlySubscription, subscription, callback
addUsersToGroup: (subscriptionId, memberIds, callback)->
logger.log subscriptionId: subscriptionId, memberIds: memberIds, "adding members into mongo subscription"
searchOps =
_id: new ObjectId(subscriptionId.toString())
insertOperation =
{ $push: { member_ids: { $each: memberIds } } }
Subscription.findAndModify searchOps, insertOperation, callback
addUserToGroup: (adminUser_id, user_id, callback)->
logger.log adminUser_id:adminUser_id, user_id:user_id, "adding user into mongo subscription"
searchOps =
@ -47,6 +56,9 @@ module.exports = SubscriptionUpdater =
return callback(err)
FeaturesUpdater.refreshFeatures user_id, callback
deleteWithV1Id: (v1TeamId, callback)->
Subscription.deleteOne { "overleaf.id": v1TeamId }, callback
deleteSubscription: (subscription_id, callback = (error) ->) ->
SubscriptionLocator.getSubscription subscription_id, (err, subscription) ->
return callback(err) if err?

View file

@ -62,7 +62,7 @@ module.exports = UserGetter =
user_ids = user_ids.map (u) -> ObjectId(u.toString())
catch error
return callback error
db.users.find { _id: { $in: user_ids} }, projection, callback
getUserOrUserStubById: (user_id, projection, callback = (error, user) ->) ->