diff options
author | Frederick Muriuki Muriithi | 2024-05-30 12:03:38 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-06-03 10:02:08 -0500 |
commit | 7c0ee01c1d134cbee0a2c8243dd55e4eeaaa5f7c (patch) | |
tree | caeb61fab877b7b344608af4a55b36a18b3283c2 /gn_auth/auth/authorisation/users | |
parent | d2e9e9afde6d01bca49e5173282ac318c37460e0 (diff) | |
download | gn-auth-7c0ee01c1d134cbee0a2c8243dd55e4eeaaa5f7c.tar.gz |
Move user creation from db resultset into static method
Creation of a User object from the database resultset will mostly be
the same. This commit moves the repetitive code into a static method
that can be called wherever we need it.
This improves maintainability, since we only ever need to do an update
in one place now.
Diffstat (limited to 'gn_auth/auth/authorisation/users')
-rw-r--r-- | gn_auth/auth/authorisation/users/admin/views.py | 3 | ||||
-rw-r--r-- | gn_auth/auth/authorisation/users/models.py | 4 |
2 files changed, 2 insertions, 5 deletions
diff --git a/gn_auth/auth/authorisation/users/admin/views.py b/gn_auth/auth/authorisation/users/admin/views.py index 73e808a..8ca1e51 100644 --- a/gn_auth/auth/authorisation/users/admin/views.py +++ b/gn_auth/auth/authorisation/users/admin/views.py @@ -189,8 +189,7 @@ def register_client(): with db.cursor(conn) as cursor: cursor.execute("SELECT * FROM users") return tuple( - User(uuid.UUID(row["user_id"]), row["email"], row["name"]) - for row in cursor.fetchall()) + User.from_sqlite3_row(row) for row in cursor.fetchall()) if request.method == "GET": return render_template( "admin/register-client.html", diff --git a/gn_auth/auth/authorisation/users/models.py b/gn_auth/auth/authorisation/users/models.py index 8b47fc1..bde2e33 100644 --- a/gn_auth/auth/authorisation/users/models.py +++ b/gn_auth/auth/authorisation/users/models.py @@ -17,9 +17,7 @@ def list_users(conn: db.DbConnection) -> tuple[User, ...]: """List out all users.""" with db.cursor(conn) as cursor: cursor.execute("SELECT * FROM users") - return tuple( - User(uuid.UUID(row["user_id"]), row["email"], row["name"]) - for row in cursor.fetchall()) + return tuple(User.from_sqlite3_row(row) for row in cursor.fetchall()) def __build_resource_roles__(rows): def __build_roles__(roles, row): |