Skip to content
Snippets Groups Projects
Commit 7ef02127 authored by James Allen's avatar James Allen
Browse files

Update migration script for holding accounts to migrate group invites

parent 65d21f71
No related branches found
No related tags found
No related merge requests found
Settings = require "settings-sharelatex" Settings = require "settings-sharelatex"
mongojs = require("mongojs") mongojs = require("mongojs")
ObjectId = mongojs.ObjectId ObjectId = mongojs.ObjectId
db = mongojs(Settings.mongo.url, ['users', 'projects']) db = mongojs(Settings.mongo.url, ['users', 'projects', 'subscriptions'])
async = require "async" async = require "async"
module.exports = HoldingAccountMigration = module.exports = HoldingAccountMigration =
...@@ -59,6 +59,21 @@ module.exports = HoldingAccountMigration = ...@@ -59,6 +59,21 @@ module.exports = HoldingAccountMigration =
console.log "[Would have removed user]", user_id console.log "[Would have removed user]", user_id
callback() callback()
migrateGroupInvites: (user_id, email, callback = (error) ->) ->
if !user_id?
throw new Error("must have user_id")
if !HoldingAccountMigration.DRY_RUN
db.subscriptions.update {member_ids: user_id}, {
$pull: { member_ids: user_id },
$addToSet : { invited_emails: email }
}, { multi : true }, (error, result) ->
return callback(error) if error?
console.log "[Migrated user in group accounts]", user_id, email, result
callback()
else
console.log "[Would have migrated user in group accounts]", user_id, email
callback()
run: (done = () ->) -> run: (done = () ->) ->
console.log "[Getting list of holding accounts]" console.log "[Getting list of holding accounts]"
HoldingAccountMigration.findHoldingAccounts (error, users) -> HoldingAccountMigration.findHoldingAccounts (error, users) ->
...@@ -68,6 +83,8 @@ module.exports = HoldingAccountMigration = ...@@ -68,6 +83,8 @@ module.exports = HoldingAccountMigration =
jobs = users.map (u) -> jobs = users.map (u) ->
(cb) -> (cb) ->
console.log "[Removing user #{i++}/#{users.length}]" console.log "[Removing user #{i++}/#{users.length}]"
HoldingAccountMigration.migrateGroupInvites u._id, u.email, (error) ->
return cb(error) if error?
HoldingAccountMigration.deleteUser u._id, (error) -> HoldingAccountMigration.deleteUser u._id, (error) ->
return cb(error) if error? return cb(error) if error?
HoldingAccountMigration.deleteUserProjects u._id, (error) -> HoldingAccountMigration.deleteUserProjects u._id, (error) ->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment