diff options
Diffstat (limited to 'gn3/authentication.py')
-rw-r--r-- | gn3/authentication.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/gn3/authentication.py b/gn3/authentication.py index 6719631..d0b35bc 100644 --- a/gn3/authentication.py +++ b/gn3/authentication.py @@ -113,9 +113,9 @@ def get_groups_by_user_uid(user_uid: str, conn: Redis) -> Dict: """ admin = [] member = [] - for uuid, group_info in conn.hgetall("groups").items(): + for group_uuid, group_info in conn.hgetall("groups").items(): group_info = json.loads(group_info) - group_info["uuid"] = uuid + group_info["uuid"] = group_uuid if user_uid in group_info.get('admins'): admin.append(group_info) if user_uid in group_info.get('members'): @@ -130,11 +130,10 @@ def get_user_info_by_key(key: str, value: str, conn: Redis) -> Optional[Dict]: """Given a key, get a user's information if value is matched""" if key != "user_id": - for uuid, user_info in conn.hgetall("users").items(): + for user_uuid, user_info in conn.hgetall("users").items(): user_info = json.loads(user_info) - if (key in user_info and - user_info.get(key) == value): - user_info["user_id"] = uuid + if (key in user_info and user_info.get(key) == value): + user_info["user_id"] = user_uuid return user_info elif key == "user_id": if user_info := conn.hget("users", value): @@ -145,9 +144,13 @@ def get_user_info_by_key(key: str, value: str, def create_group(conn: Redis, group_name: Optional[str], - admin_user_uids: List = [], - member_user_uids: List = []) -> Optional[Dict]: + admin_user_uids: List = None, + member_user_uids: List = None) -> Optional[Dict]: """Create a group given the group name, members and admins of that group.""" + if admin_user_uids is None: + admin_user_uids = [] + if member_user_uids is None: + member_user_uids = [] if group_name and bool(admin_user_uids + member_user_uids): timestamp = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p') group = { @@ -160,3 +163,4 @@ def create_group(conn: Redis, group_name: Optional[str], } conn.hset("groups", group_id, json.dumps(group)) return group + return None |