diff options
author | BonfaceKilz | 2021-10-06 16:12:22 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-10-06 16:20:43 +0300 |
commit | 949789a00d8e6e901cc18b939737cd42e14c0236 (patch) | |
tree | 499cbf3e623b7a15d443061dbe5f8a6a986f07fd /scripts | |
parent | 7a15d24a6598f30801dd897ddc72d3773641e7bd (diff) | |
download | genenetwork2-949789a00d8e6e901cc18b939737cd42e14c0236.tar.gz |
scripts: group: Use a unique key to identify a group
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/authentication/group.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/scripts/authentication/group.py b/scripts/authentication/group.py index 76c7fb4f..eea13efe 100644 --- a/scripts/authentication/group.py +++ b/scripts/authentication/group.py @@ -29,6 +29,7 @@ import argparse import datetime import redis import json +import uuid from typing import Dict, List, Optional, Set @@ -71,26 +72,31 @@ def create_group_data(users: Dict, target_group: str, me@test2.com, me@test3.com" """ + # Emails + _members: Set = set("".join(members.split()).split(",") + if members else []) + _admins: Set = set("".join(admins.split()).split(",") + if admins else []) - _members: List = "".join(members.split()).split(",") if members else [] - _admins: List = "".join(admins.split()).split(",") if admins else [] + # Unique IDs + member_ids: Set = set() + admin_ids: Set = set() - user_ids: Dict = dict() for user_id, user_details in users.items(): _details = json.loads(user_details) - if _details.get("email_address"): - user_ids[_details.get("email_address")] = user_id - print(user_ids) + if _details.get("email_address") in _members: + member_ids.add(user_id) + if _details.get("email_address") in _admins: + admin_ids.add(user_id) + + timestamp: str = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p') return {"key": "groups", - "field": target_group, + "field": str(uuid.uuid4()), "value": json.dumps({ - "id": target_group, "name": target_group, - "admins": [user_ids[admin] for admin in _admins - if admin in user_ids], - "members": [user_ids[member] for member in _members - if member in user_ids], - "changed_timestamp": datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p') + "admins": list(admin_ids), + "members": list(member_ids), + "changed_timestamp": timestamp, })} |