Skip to content

Commit 10ef7f0

Browse files
committed
add script to remove unused user attributes in user profile in firebase
1 parent 6559f78 commit 10ef7f0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from firebase_admin import auth
2+
3+
from mapswipe_workers.auth import firebaseDB
4+
from mapswipe_workers.definitions import logger
5+
6+
7+
def remove_unused_user_attributes(uid):
8+
"""Set username in Firebase DB based on auth.display_name for user id."""
9+
fb_db = firebaseDB()
10+
try:
11+
ref = fb_db.reference(f"v2/users/{uid}/")
12+
ref.update({
13+
"projectContributionCount": None,
14+
"groupContributionCount": None
15+
})
16+
17+
user_projects = fb_db.reference(f"v2/users/{uid}/contributions/").get(shallow=True)
18+
if user_projects:
19+
for project_id in user_projects.keys():
20+
ref = fb_db.reference(f"v2/users/{uid}/contributions/{project_id}")
21+
ref.update({
22+
"groupContributionCount": None
23+
})
24+
25+
logger.info(f"removed attributes for user {uid}")
26+
except:
27+
logger.info(f"could NOT remove attributes for user {uid}.")
28+
29+
30+
def get_all_users():
31+
"""Get the user ids from all users in Firebase DB."""
32+
fb_db = firebaseDB()
33+
users = fb_db.reference("v2/users/").get(shallow=True)
34+
uid_list = users.keys()
35+
return uid_list
36+
37+
38+
if __name__ == "__main__":
39+
"""Get all user ids from Firebase and update username based on auth.display_name."""
40+
uid_list = get_all_users()
41+
for uid in uid_list:
42+
remove_unused_user_attributes(uid)

0 commit comments

Comments
 (0)