From 08fceeffc0ea8a3c132e580dfceb4476ea3a2961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 9 Jun 2016 17:19:46 +0200 Subject: [PATCH] Added management command to find duplicate users, based on their BlenderID --- pillar/manage.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pillar/manage.py b/pillar/manage.py index 3570a737..391c3d5b 100755 --- a/pillar/manage.py +++ b/pillar/manage.py @@ -824,5 +824,40 @@ def create_badger_account(email, badges): print(' expires on: %s' % token['expire_time']) +@manager.command +def find_duplicate_users(): + """Finds users that have the same BlenderID user_id.""" + + from collections import defaultdict + + users_coll = app.data.driver.db['users'] + nodes_coll = app.data.driver.db['nodes'] + projects_coll = app.data.driver.db['projects'] + + found_users = defaultdict(list) + + for user in users_coll.find(): + blender_ids = [auth['user_id'] for auth in user['auth'] + if auth['provider'] == 'blender-id'] + if not blender_ids: + continue + blender_id = blender_ids[0] + found_users[blender_id].append(user) + + for blender_id, users in found_users.iteritems(): + if len(users) == 1: + continue + + usernames = ', '.join(user['username'] for user in users) + print('Blender ID: %5s has %i users: %s' % ( + blender_id, len(users), usernames)) + + for user in users: + print(' %s owns %i nodes and %i projects' % ( + user['username'], + nodes_coll.count({'user': user['_id']}), + projects_coll.count({'user': user['_id']}), + )) + if __name__ == '__main__': manager.run()