Skip to content

Commit

Permalink
Runtime fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
illusional committed Oct 21, 2023
1 parent d72d605 commit 06ec1ec
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
1 change: 0 additions & 1 deletion .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
# used for generating API
SM_DOCKER: australia-southeast1-docker.pkg.dev/sample-metadata/images/server:${{ github.sha }}
SM_API_DOCKER: australia-southeast1-docker.pkg.dev/cpg-common/images/sm-api
defaults:
run:
shell: bash -eo pipefail -l {0}
Expand Down
2 changes: 1 addition & 1 deletion api/routes/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def get_my_projects(connection=get_projectless_db_connection):
async def create_project(
name: str,
dataset: str,
create_test_project: bool = True,
create_test_project: bool = False,
connection: Connection = get_projectless_db_connection,
) -> int:
"""
Expand Down
39 changes: 20 additions & 19 deletions db/python/tables/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ async def get_projects_accessible_by_user(
relevant_project_ids = await self.connection.fetch_all(
_query, {'author': author}
)
projects = await self._get_projects_by_ids(relevant_project_ids)
projects = await self._get_projects_by_ids(
[p['id'] for p in relevant_project_ids]
)

return projects

Expand Down Expand Up @@ -571,21 +573,20 @@ async def set_group_members(self, group_id: int, members: list[str], author: str
"""
Set group members for a group (by id)
"""
async with self.connection.transaction():
await self.connection.execute(
"""
DELETE FROM group_member
WHERE group_id = :group_id
""",
{'group_id': group_id},
)
await self.connection.execute_many(
"""
INSERT INTO group_member (group_id, member, author)
VALUES (:group_id, :member, :author)
""",
[
{'group_id': group_id, 'member': member, 'author': author}
for member in members
],
)
await self.connection.execute(
"""
DELETE FROM group_member
WHERE group_id = :group_id
""",
{'group_id': group_id},
)
await self.connection.execute_many(
"""
INSERT INTO group_member (group_id, member, author)
VALUES (:group_id, :member, :author)
""",
[
{'group_id': group_id, 'member': member, 'author': author}
for member in members
],
)
25 changes: 25 additions & 0 deletions test/test_project_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,28 @@ async def test_project_access_success(self):
user=self.author, project_name=g, readonly=True
)
self.assertEqual(pid, project_for_name.id)

@run_as_sync
async def test_get_my_projects(self):
"""
Test that a user with permission only has MY projects
"""
await self._add_group_member_direct(GROUP_NAME_PROJECT_CREATORS)
await self._add_group_member_direct(GROUP_NAME_MEMBERS_ADMIN)

g = str(uuid.uuid4())

pid = await self.pttable.create_project(g, g, self.author)

await self.pttable.set_group_members(
group_name=self.pttable.get_project_group_name(g, readonly=True),
members=[self.author],
author=self.author,
)

projects = await self.pttable.get_projects_accessible_by_user(
author=self.author
)

self.assertEqual(1, len(projects))
self.assertEqual(pid, projects[0].id)

0 comments on commit 06ec1ec

Please sign in to comment.