mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-25 12:20:32 -04:00
Add script for removing anonymous users from classrooms
This commit is contained in:
parent
d4c5d418ff
commit
cf76434943
1 changed files with 43 additions and 0 deletions
|
@ -0,0 +1,43 @@
|
|||
// Usage: Copy and paste into mongo shell
|
||||
|
||||
function removeAnonymousMembers(classroom) {
|
||||
if(!classroom.members) {
|
||||
return;
|
||||
}
|
||||
|
||||
print('checking classroom',
|
||||
classroom._id,
|
||||
'\n\t',
|
||||
classroom._id.getTimestamp(),
|
||||
classroom.members.length,
|
||||
'owner', classroom.ownerID);
|
||||
|
||||
classroom.members.forEach(function(userID) {
|
||||
var user = db.users.findOne({_id: userID}, {anonymous:1});
|
||||
if (!user) {
|
||||
return;
|
||||
}
|
||||
if(user.anonymous) {
|
||||
print('\tRemove user', JSON.stringify(user));
|
||||
|
||||
print('\t\tRemoving from course instances',
|
||||
db.course.instances.update(
|
||||
{classroomID: classroom._id},
|
||||
{$pull: {members: userID}})
|
||||
);
|
||||
|
||||
print('\t\tRemoving from classroom',
|
||||
db.classrooms.update(
|
||||
{_id: classroom._id},
|
||||
{$pull: {members: userID}})
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var startID = ObjectId('566838b00fb44a2e00000000');
|
||||
while (true) {
|
||||
var classroom = db.classrooms.findOne({_id: {$gt: startID}});
|
||||
removeAnonymousMembers(classroom);
|
||||
startID = classroom._id;
|
||||
}
|
Loading…
Add table
Reference in a new issue