diff options
author | zsloan | 2020-06-05 16:52:56 -0500 |
---|---|---|
committer | zsloan | 2020-06-05 16:52:56 -0500 |
commit | a302a2b0ac0e7c0f26a0d063c3f2b057f61d47f1 (patch) | |
tree | a9f5c88f7d2818bf4e0481b85872c7580a8d577c /wqflask/utility/redis_tools.py | |
parent | 218576a04f90cc0bc9e53685323e1caa8cffe986 (diff) | |
download | genenetwork2-a302a2b0ac0e7c0f26a0d063c3f2b057f61d47f1.tar.gz |
Commiting other current group/resource management code, plus the new files
Diffstat (limited to 'wqflask/utility/redis_tools.py')
-rw-r--r-- | wqflask/utility/redis_tools.py | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/wqflask/utility/redis_tools.py b/wqflask/utility/redis_tools.py index 0ad96879..bc30a0af 100644 --- a/wqflask/utility/redis_tools.py +++ b/wqflask/utility/redis_tools.py @@ -95,14 +95,17 @@ def get_user_groups(user_id): user_group_ids = [] #ZS: Group IDs where user is a regular user groups_list = Redis.hgetall("groups") for key in groups_list: - group_ob = json.loads(groups_list[key]) - group_admins = set(group_ob['admins']) - group_members = set(group_ob['members']) - if user_id in group_admins: - admin_group_ids.append(group_ob['id']) - elif user_id in group_members: - user_group_ids.append(group_ob['id']) - else: + try: + group_ob = json.loads(groups_list[key]) + group_admins = set(group_ob['admins']) + group_members = set(group_ob['members']) + if user_id in group_admins: + admin_group_ids.append(group_ob['id']) + elif user_id in group_members: + user_group_ids.append(group_ob['id']) + else: + continue + except: continue admin_groups = [] @@ -122,6 +125,24 @@ def get_group_info(group_id): return group_info +def get_group_by_unique_column(column_name, column_value): + """ Get group by column; not sure if there's a faster way to do this """ + + matched_groups = [] + + all_group_list = Redis.hgetall("groups") + for key in all_group_list: + group_info = json.loads(all_group_list[key]) + if column_name == "admins" or column_name == "members": #ZS: Since these fields are lists, search in the list + if column_value in group_info[column_name]: + matched_groups.append(group_info) + else: + if group_info[column_name] == column_value: + matched_groups.append(group_info) + + return matched_groups + + def create_group(admin_user_ids, member_user_ids = [], group_name = "Default Group Name"): group_id = str(uuid.uuid4()) new_group = { |