Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Dec 10, 2024
1 parent 19a7c86 commit 63aefa7
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,16 @@ async def get_group_from_gid(
#


def _query_user_groups_with_read_access(query, user_id: UserID):
return query.select_from(
user_to_groups.join(groups, user_to_groups.c.gid == groups.c.gid),
).where(
(user_to_groups.c.uid == user_id)
& (user_to_groups.c.access_rights["read"].is_(True))
def _list_user_groups_with_read_access_query(*group_selection, user_id: UserID):
return (
sa.select(*group_selection, user_to_groups.c.access_rights)
.select_from(
user_to_groups.join(groups, user_to_groups.c.gid == groups.c.gid),
)
.where(
(user_to_groups.c.uid == user_id)
& (user_to_groups.c.access_rights["read"].is_(True))
)
)


Expand All @@ -162,9 +166,7 @@ async def get_all_user_groups_with_read_access(
standard_groups: list[GroupInfoTuple] = []
everyone_group: GroupInfoTuple | None = None

query = _query_user_groups_with_read_access(
sa.select(groups, user_to_groups.c.access_rights), user_id=user_id
)
query = _list_user_groups_with_read_access_query(groups, user_id=user_id)

async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
result = await conn.stream(query)
Expand Down Expand Up @@ -195,9 +197,8 @@ async def get_ids_of_all_user_groups_with_read_access(
user_id: UserID,
) -> list[GroupID]:
# thin version of `get_all_user_groups_with_read_access`
query = _query_user_groups_with_read_access(
sa.select(groups.c.gid, user_to_groups.c.access_rights), user_id=user_id
)

query = _list_user_groups_with_read_access_query(groups.c.gid, user_id=user_id)

async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
result = await conn.stream(query)
Expand Down

0 comments on commit 63aefa7

Please sign in to comment.