Skip to content

Commit

Permalink
TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Dec 10, 2024
1 parent 401438e commit 19a7c86
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ async def get_group_from_gid(app: web.Application, group_id: GroupID) -> Group |
#
# USER GROUPS: groups a user belongs to
#
async def list_user_groups_ids_with_read_access(
app: web.Application, *, user_id: UserID
) -> list[GroupID]:

return await _groups_db.get_ids_of_all_user_groups_with_read_access(
app, user_id=user_id
)


async def list_user_groups_with_read_access(
Expand All @@ -51,16 +44,21 @@ async def list_user_groups_with_read_access(
# NOTE: Careful! It seems we are filtering out groups, such as Product Groups,
# because they do not have read access. I believe this was done because the
# frontend did not want to display them.

return await _groups_db.get_all_user_groups_with_read_access(app, user_id=user_id)


async def list_user_groups_ids_with_read_access(
app: web.Application, *, user_id: UserID
) -> list[GroupID]:
return await _groups_db.get_ids_of_all_user_groups_with_read_access(
app, user_id=user_id
)


async def list_all_user_groups_ids(
app: web.Application, *, user_id: UserID
) -> list[GroupID]:
# TODO: Room for optimization. For the moment we reuse existing db functions
user_groups = await _groups_db.get_all_user_groups(app, user_id=user_id)
return [g.gid for g in user_groups]
return await _groups_db.get_ids_of_all_user_groups(app, user_id=user_id)


async def get_product_group_for_user(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ 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
)
Expand All @@ -215,7 +215,7 @@ async def get_all_user_groups(
"""
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
result = await conn.stream(
sa.select(_GROUP_COLUMNS)
sa.select(*_GROUP_COLUMNS)
.select_from(
user_to_groups.join(groups, user_to_groups.c.gid == groups.c.gid),
)
Expand All @@ -224,6 +224,26 @@ async def get_all_user_groups(
return [Group.model_validate(row) async for row in result]


async def get_ids_of_all_user_groups(
app: web.Application,
connection: AsyncConnection | None = None,
*,
user_id: UserID,
) -> list[GroupID]:
# thin version of `get_all_user_groups`
async with pass_or_acquire_connection(get_asyncpg_engine(app), connection) as conn:
result = await conn.stream(
sa.select(
groups.c.gid,
)
.select_from(
user_to_groups.join(groups, user_to_groups.c.gid == groups.c.gid),
)
.where(user_to_groups.c.uid == user_id)
)
return [row.id async for row in result]


async def get_user_group(
app: web.Application,
connection: AsyncConnection | None = None,
Expand Down

0 comments on commit 19a7c86

Please sign in to comment.