From 7c0ee01c1d134cbee0a2c8243dd55e4eeaaa5f7c Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 30 May 2024 12:03:38 -0500 Subject: 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. --- gn_auth/auth/authorisation/resources/groups/models.py | 3 +-- gn_auth/auth/authorisation/resources/views.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'gn_auth/auth/authorisation/resources') diff --git a/gn_auth/auth/authorisation/resources/groups/models.py b/gn_auth/auth/authorisation/resources/groups/models.py index 3feefa6..03a93b6 100644 --- a/gn_auth/auth/authorisation/resources/groups/models.py +++ b/gn_auth/auth/authorisation/resources/groups/models.py @@ -276,8 +276,7 @@ def group_users(conn: db.DbConnection, group_id: UUID) -> Iterable[User]: {"group_id": str(group_id)}) results = cursor.fetchall() - return (User(UUID(row["user_id"]), row["email"], row["name"]) - for row in results) + return (User.from_sqlite3_row(row) for row in results) @authorised_p( diff --git a/gn_auth/auth/authorisation/resources/views.py b/gn_auth/auth/authorisation/resources/views.py index 0200222..c481ef9 100644 --- a/gn_auth/auth/authorisation/resources/views.py +++ b/gn_auth/auth/authorisation/resources/views.py @@ -172,7 +172,7 @@ def resource_users(resource_id: uuid.UUID): def __organise_users_n_roles__(users_n_roles, row): user_id = uuid.UUID(row["user_id"]) user = users_n_roles.get(user_id, {}).get( - "user", User(user_id, row["email"], row["name"])) + "user", User.from_sqlite3_row(row)) role = Role( uuid.UUID(row["role_id"]), row["role_name"], bool(int(row["user_editable"])), tuple()) -- cgit v1.2.3