diff options
author | Frederick Muriuki Muriithi | 2023-01-31 14:13:35 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-01-31 14:13:35 +0300 |
commit | 6fc120aca6062f96725adaece85a7b76000affda (patch) | |
tree | 915999652c153d0f25724ce61dfb965223646251 /gn3/auth/authorisation/groups.py | |
parent | 83a8bf8e45951b771b476d2200ed1b69e4904975 (diff) | |
download | genenetwork3-6fc120aca6062f96725adaece85a7b76000affda.tar.gz |
auth: Retrieve group members.
Diffstat (limited to 'gn3/auth/authorisation/groups.py')
-rw-r--r-- | gn3/auth/authorisation/groups.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gn3/auth/authorisation/groups.py b/gn3/auth/authorisation/groups.py index 0e022ee..c691457 100644 --- a/gn3/auth/authorisation/groups.py +++ b/gn3/auth/authorisation/groups.py @@ -209,3 +209,15 @@ def add_user_to_group(cursor: db.DbCursor, the_group: Group, user: User): ("INSERT INTO group_users VALUES (:group_id, :user_id) " "ON CONFLICT (group_id, user_id) DO NOTHING"), {"group_id": str(the_group.group_id), "user_id": str(user.user_id)}) + +def group_users(conn: db.DbConnection, group_id: UUID) -> Iterable[User]: + """Retrieve all users that are members of group with id `group_id`.""" + with db.cursor(conn) as cursor: + cursor.execute( + "SELECT u.* FROM group_users AS gu INNER JOIN users AS u " + "ON gu.user_id = u.user_id WHERE gu.group_id=:group_id", + {"group_id": str(group_id)}) + results = cursor.fetchall() + + return (User(UUID(row["user_id"]), row["email"], row["name"]) + for row in results) |