2014-02-12 05:23:40 -05:00
|
|
|
async = require("async")
|
|
|
|
_ = require("underscore")
|
|
|
|
SubscriptionUpdater = require("./SubscriptionUpdater")
|
|
|
|
SubscriptionLocator = require("./SubscriptionLocator")
|
2018-05-23 10:12:23 -04:00
|
|
|
UserGetter = require("../User/UserGetter")
|
2018-05-29 10:35:46 -04:00
|
|
|
Subscription = require("../../models/Subscription").Subscription
|
2014-02-12 05:23:40 -05:00
|
|
|
LimitationsManager = require("./LimitationsManager")
|
2015-05-27 11:33:47 -04:00
|
|
|
logger = require("logger-sharelatex")
|
2015-05-27 15:50:16 -04:00
|
|
|
OneTimeTokenHandler = require("../Security/OneTimeTokenHandler")
|
2018-05-30 06:29:21 -04:00
|
|
|
TeamInvitesHandler = require("./TeamInvitesHandler")
|
2015-05-27 15:50:16 -04:00
|
|
|
EmailHandler = require("../Email/EmailHandler")
|
|
|
|
settings = require("settings-sharelatex")
|
2016-02-18 06:43:43 -05:00
|
|
|
NotificationsBuilder = require("../Notifications/NotificationsBuilder")
|
2018-09-25 09:10:06 -04:00
|
|
|
UserMembershipViewModel = require("../UserMembership/UserMembershipViewModel")
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2015-05-27 15:50:16 -04:00
|
|
|
module.exports = SubscriptionGroupHandler =
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2018-07-11 04:31:57 -04:00
|
|
|
removeUserFromGroup: (subscriptionId, userToRemove_id, callback)->
|
|
|
|
SubscriptionUpdater.removeUserFromGroup subscriptionId, userToRemove_id, callback
|
2018-05-25 10:45:33 -04:00
|
|
|
|
|
|
|
replaceUserReferencesInGroups: (oldId, newId, callback) ->
|
2018-05-29 10:35:46 -04:00
|
|
|
Subscription.update {admin_id: oldId}, {admin_id: newId}, (error) ->
|
2018-05-25 10:45:33 -04:00
|
|
|
callback(error) if error?
|
|
|
|
|
2018-06-29 12:01:34 -04:00
|
|
|
replaceInArray Subscription, "manager_ids", oldId, newId, (error) ->
|
|
|
|
callback(error) if error?
|
2018-05-25 10:45:33 -04:00
|
|
|
|
2018-06-29 12:01:34 -04:00
|
|
|
replaceInArray Subscription, "member_ids", oldId, newId, callback
|
2018-05-25 10:45:33 -04:00
|
|
|
|
2015-05-27 11:33:47 -04:00
|
|
|
isUserPartOfGroup: (user_id, subscription_id, callback=(err, partOfGroup)->)->
|
|
|
|
SubscriptionLocator.getSubscriptionByMemberIdAndId user_id, subscription_id, (err, subscription)->
|
|
|
|
if subscription?
|
|
|
|
partOfGroup = true
|
|
|
|
else
|
|
|
|
partOfGroup = false
|
|
|
|
logger.log user_id:user_id, subscription_id:subscription_id, partOfGroup:partOfGroup, "checking if user is part of a group"
|
|
|
|
callback(err, partOfGroup)
|
|
|
|
|
2018-06-29 12:01:34 -04:00
|
|
|
replaceInArray = (model, property, oldValue, newValue, callback) ->
|
|
|
|
logger.log "Replacing #{oldValue} with #{newValue} in #{property} of #{model}"
|
|
|
|
|
|
|
|
# Mongo won't let us pull and addToSet in the same query, so do it in
|
|
|
|
# two. Note we need to add first, since the query is based on the old user.
|
|
|
|
query = {}
|
|
|
|
query[property] = oldValue
|
|
|
|
|
|
|
|
setNewValue = {}
|
|
|
|
setNewValue[property] = newValue
|
|
|
|
|
|
|
|
setOldValue = {}
|
|
|
|
setOldValue[property] = oldValue
|
|
|
|
|
|
|
|
model.update query, { $addToSet: setNewValue }, { multi: true }, (error) ->
|
|
|
|
return callback(error) if error?
|
|
|
|
model.update query, { $pull: setOldValue }, { multi: true }, callback
|