mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-22 02:04:31 +00:00
Merge pull request #605 from sharelatex/afc-update-user-references
Add method to update user references
This commit is contained in:
commit
e7e429a963
2 changed files with 65 additions and 14 deletions
services/web
app/coffee/Features/Subscription
test/unit/coffee/Subscription
|
@ -3,6 +3,7 @@ _ = require("underscore")
|
|||
SubscriptionUpdater = require("./SubscriptionUpdater")
|
||||
SubscriptionLocator = require("./SubscriptionLocator")
|
||||
UserGetter = require("../User/UserGetter")
|
||||
Subscription = require("../../models/Subscription").Subscription
|
||||
LimitationsManager = require("./LimitationsManager")
|
||||
logger = require("logger-sharelatex")
|
||||
OneTimeTokenHandler = require("../Security/OneTimeTokenHandler")
|
||||
|
@ -43,6 +44,21 @@ module.exports = SubscriptionGroupHandler =
|
|||
removeEmailInviteFromGroup: (adminUser_id, email, callback) ->
|
||||
SubscriptionUpdater.removeEmailInviteFromGroup adminUser_id, email, callback
|
||||
|
||||
|
||||
replaceUserReferencesInGroups: (oldId, newId, callback) ->
|
||||
Subscription.update {admin_id: oldId}, {admin_id: newId}, (error) ->
|
||||
callback(error) if error?
|
||||
|
||||
# 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 = { member_ids: oldId }
|
||||
addNewUserUpdate = $addToSet: { member_ids: newId }
|
||||
removeOldUserUpdate = $pull: { member_ids: oldId }
|
||||
|
||||
Subscription.update query, addNewUserUpdate, { multi: true }, (error) ->
|
||||
return callback(error) if error?
|
||||
Subscription.update query, removeOldUserUpdate, { multi: true }, callback
|
||||
|
||||
getPopulatedListOfMembers: (adminUser_id, callback)->
|
||||
SubscriptionLocator.getUsersSubscription adminUser_id, (err, subscription)->
|
||||
users = []
|
||||
|
|
|
@ -24,6 +24,9 @@ describe "SubscriptionGroupHandler", ->
|
|||
getSubscriptionByMemberIdAndId: sinon.stub()
|
||||
getSubscription: sinon.stub()
|
||||
|
||||
@UserCreator =
|
||||
getUserOrCreateHoldingAccount: sinon.stub().callsArgWith(1, null, @user)
|
||||
|
||||
@SubscriptionUpdater =
|
||||
addUserToGroup: sinon.stub().callsArgWith(2)
|
||||
removeUserFromGroup: sinon.stub().callsArgWith(2)
|
||||
|
@ -44,6 +47,9 @@ describe "SubscriptionGroupHandler", ->
|
|||
@EmailHandler =
|
||||
sendEmail:sinon.stub()
|
||||
|
||||
@Subscription =
|
||||
update: sinon.stub().yields()
|
||||
|
||||
@settings =
|
||||
siteUrl:"http://www.sharelatex.com"
|
||||
|
||||
|
@ -56,6 +62,7 @@ describe "SubscriptionGroupHandler", ->
|
|||
"../User/UserCreator": @UserCreator
|
||||
"./SubscriptionUpdater": @SubscriptionUpdater
|
||||
"./SubscriptionLocator": @SubscriptionLocator
|
||||
"../../models/Subscription": Subscription: @Subscription
|
||||
"../User/UserGetter": @UserGetter
|
||||
"./LimitationsManager": @LimitationsManager
|
||||
"../Security/OneTimeTokenHandler":@OneTimeTokenHandler
|
||||
|
@ -114,6 +121,35 @@ describe "SubscriptionGroupHandler", ->
|
|||
@SubscriptionUpdater.removeUserFromGroup.calledWith(@adminUser_id, @user._id).should.equal true
|
||||
done()
|
||||
|
||||
describe "replaceUserReferencesInGroups", ->
|
||||
beforeEach ->
|
||||
@oldId = "ba5eba11"
|
||||
@newId = "5ca1ab1e"
|
||||
|
||||
it "replaces the admin_id", (done) ->
|
||||
@Handler.replaceUserReferencesInGroups @oldId, @newId, (err) =>
|
||||
|
||||
@Subscription.update.calledWith(
|
||||
{ admin_id: @oldId },
|
||||
{ admin_id: @newId }
|
||||
).should.equal true
|
||||
|
||||
done()
|
||||
|
||||
it "replaces the member ids", (done) ->
|
||||
@Handler.replaceUserReferencesInGroups @oldId, @newId, (err) =>
|
||||
|
||||
@Subscription.update.calledWith(
|
||||
{ member_ids: @oldId },
|
||||
{ $addToSet: { member_ids: @newId } }
|
||||
).should.equal true
|
||||
|
||||
@Subscription.update.calledWith(
|
||||
{ member_ids: @oldId },
|
||||
{ $pull: { member_ids: @oldId } }
|
||||
).should.equal true
|
||||
|
||||
done()
|
||||
|
||||
describe "getPopulatedListOfMembers", ->
|
||||
beforeEach ->
|
||||
|
@ -232,4 +268,3 @@ describe "SubscriptionGroupHandler", ->
|
|||
.calledWith(group.admin_id, @user_id)
|
||||
.should.equal true
|
||||
done()
|
||||
|
||||
|
|
Loading…
Reference in a new issue