Skip to content

Commit

Permalink
Apply review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
illusional committed Oct 22, 2023
1 parent 72c8db9 commit 16fcf1a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
18 changes: 10 additions & 8 deletions db/python/tables/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,11 @@ async def get_and_check_access_to_projects_for_ids(
group_id_project_map = {p.write_group_id: p for p in projects}

group_ids = set(gid for gid in group_id_project_map.keys() if gid)
# awkward double negative to find missing projects
missing_group_ids = await self.gtable.check_which_groups_member_is_missing(

present_group_ids = await self.gtable.check_which_groups_member_has(
group_ids=group_ids, member=user
)
missing_group_ids = group_ids - present_group_ids

if missing_group_ids:
# so we can directly return the project names they're missing
Expand Down Expand Up @@ -248,10 +249,10 @@ async def check_access_to_project_ids(
group_id_project_map = {p.write_group_id: p for p in projects}

group_ids = set(gid for gid in group_id_project_map.keys() if gid)
# awkward double negative to find missing projects
missing_group_ids = await self.gtable.check_which_groups_member_is_missing(
present_group_ids = await self.gtable.check_which_groups_member_has(
group_ids=group_ids, member=user
)
missing_group_ids = group_ids - present_group_ids

if missing_group_ids:
# so we can directly return the project names they're missing
Expand Down Expand Up @@ -543,10 +544,12 @@ async def check_if_member_in_group_name(self, group_name: str, member: str) -> b

return bool(value)

async def check_which_groups_member_is_missing(
async def check_which_groups_member_has(
self, group_ids: set[int], member: str
) -> set[int]:
"""Check if a member is in a group"""
"""
Check which groups a member has
"""
if self.allow_full_access:
return set()

Expand All @@ -558,8 +561,7 @@ async def check_which_groups_member_is_missing(
results = await self.connection.fetch_all(
_query, {'group_ids': group_ids, 'member': member}
)
membered_group_ids = set(r['gid'] for r in results)
return group_ids - membered_group_ids
return set(r['gid'] for r in results)

async def create_group(self, name: str) -> int:
"""Create a new group"""
Expand Down
11 changes: 6 additions & 5 deletions test/test_project_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,30 @@ async def test_group_set_members_succeeded(self):

@run_as_sync
async def test_check_which_groups_member_is_missing(self):
"""Test the check_which_groups_member_is_missing function"""
"""Test the check_which_groups_member_has function"""
await self._add_group_member_direct(GROUP_NAME_MEMBERS_ADMIN)

group = str(uuid.uuid4())
gid = await self.pttable.gtable.create_group(group)
missing_gids = await self.pttable.gtable.check_which_groups_member_is_missing(
present_gids = await self.pttable.gtable.check_which_groups_member_has(
{gid}, self.author
)

missing_gids = {gid} - present_gids
self.assertEqual(1, len(missing_gids))
self.assertEqual(gid, missing_gids.pop())

@run_as_sync
async def test_check_which_groups_member_is_missing_none(self):
"""Test the check_which_groups_member_is_missing function"""
"""Test the check_which_groups_member_has function"""
await self._add_group_member_direct(GROUP_NAME_MEMBERS_ADMIN)

group = str(uuid.uuid4())
gid = await self.pttable.gtable.create_group(group)
await self.pttable.gtable.set_group_members(gid, [self.author], self.author)
missing_gids = await self.pttable.gtable.check_which_groups_member_is_missing(
present_gids = await self.pttable.gtable.check_which_groups_member_has(
{gid}, self.author
)
missing_gids = {gid} - present_gids

self.assertEqual(0, len(missing_gids))

Expand Down

0 comments on commit 16fcf1a

Please sign in to comment.