diff options
author | Frederick Muriuki Muriithi | 2025-06-24 12:52:48 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-06-24 12:52:48 -0500 |
commit | 8ad7019b381e618eb7d5e2bb36b4fd7ed19759a5 (patch) | |
tree | c9e409855986c99fdcf060a1f608d64c7ba5fdec /gn_auth/auth/authorisation/users/views.py | |
parent | 23d483874c0ed4f8bc031c7a38e1f70f032e542c (diff) | |
download | gn-auth-8ad7019b381e618eb7d5e2bb36b4fd7ed19759a5.tar.gz |
Enable filtering of data, and limiting length.
Diffstat (limited to 'gn_auth/auth/authorisation/users/views.py')
-rw-r--r-- | gn_auth/auth/authorisation/users/views.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/gn_auth/auth/authorisation/users/views.py b/gn_auth/auth/authorisation/users/views.py index b37164a..5140bcb 100644 --- a/gn_auth/auth/authorisation/users/views.py +++ b/gn_auth/auth/authorisation/users/views.py @@ -331,9 +331,27 @@ def user_join_request_exists(): @require_oauth("profile user") def list_all_users() -> Response: """List all the users.""" - with require_oauth.acquire("profile group") as _the_token: - return jsonify(tuple( - asdict(user) for user in with_db_connection(list_users))) + _kwargs = { + key: value + for key, value in request.json.items() + if key in ("email", "name", "verified", "age") + } + + with (require_oauth.acquire("profile group") as _the_token, + db.connection(current_app.config["AUTH_DB"]) as conn, + db.cursor(conn) as cursor): + _users = list_users(conn, **_kwargs) + _start = int(_kwargs.get("start", "0")) + _length = int(_kwargs.get("length", "0")) + cursor.execute("SELECT COUNT(*) FROM users") + _total_users = int(cursor.fetchone()["COUNT(*)"]) + return jsonify({ + "users": tuple(asdict(user) for user in + (_users[_start:_start+_length] + if _length else _users)), + "total-users": _total_users, + "total-filtered": len(_users) + }) @users.route("/handle-unverified", methods=["POST"]) def handle_unverified(): |