diff options
author | BonfaceKilz | 2021-10-25 12:07:05 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-10-25 14:00:14 +0300 |
commit | 696a6c6dc758e16b582e20419819acd5b17a75f1 (patch) | |
tree | 0bcd5d4241ddc570f0716972b490a80f62893341 /wqflask | |
parent | be0e73c1db12806580fa5c541eceec2a54c10ad3 (diff) | |
download | genenetwork2-696a6c6dc758e16b582e20419819acd5b17a75f1.tar.gz |
Add "POST /resource-management/<resource_id>/users/search"
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/resource_manager.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/wqflask/wqflask/resource_manager.py b/wqflask/wqflask/resource_manager.py index 9487bab5..58c0b5cb 100644 --- a/wqflask/wqflask/resource_manager.py +++ b/wqflask/wqflask/resource_manager.py @@ -11,7 +11,7 @@ from flask import request from flask import url_for from urllib.parse import urljoin -from typing import Dict +from typing import Dict, Tuple from wqflask.decorators import edit_access_required from wqflask.decorators import edit_admins_access_required @@ -187,3 +187,21 @@ def view_resource_owner(resource_id: str): return render_template( "admin/change_resource_owner.html", resource_id=resource_id) + + +@resource_management.route("<resource_id>/users/search", methods=('POST',)) +@edit_admins_access_required +@login_required +def search_user(resource_id: str): + results = {} + for user in (users := redis.from_url( + current_app.config["REDIS_URL"], + decode_responses=True).hgetall("users")): + user = json.loads(users[user]) + for q in (request.form.get("user_name"), + request.form.get("user_email")): + if q and (q in user.get("email_address") or + q in user.get("full_name")): + results[user.get("user_id", "")] = user + return json.dumps(tuple(results.values())) + |