diff --git a/api/simqueue/db.py b/api/simqueue/db.py index 30f4a5b..f83d764 100644 --- a/api/simqueue/db.py +++ b/api/simqueue/db.py @@ -803,7 +803,7 @@ async def query_quotas( ): query = quotas.select() if project_id: - query = query.where(quotas.c.project_id == str(project_id)) + query = query.where(quotas.c.project_id == project_id) if platform: query = query.where(quotas.c.platform == platform) query = query.offset(from_index).limit(size) diff --git a/api/simqueue/oauth.py b/api/simqueue/oauth.py index 4f1d308..7dd210d 100644 --- a/api/simqueue/oauth.py +++ b/api/simqueue/oauth.py @@ -80,7 +80,7 @@ async def can_view(self, collab): role: f"collab-{collab}-{role}" for role in ("viewer", "editor", "administrator") } for role, team_name in target_team_names.items(): - if team_name in self.roles["team"]: + if team_name in self.roles.get("team", []): return True # if that fails, check if it's a public collab try: @@ -95,12 +95,14 @@ def can_edit(self, collab): role: f"collab-{collab}-{role}" for role in ("editor", "administrator") } for role, team_name in target_team_names.items(): - if team_name in self.roles["team"]: + if team_name in self.roles.get("team", []): return True def get_collabs(self, access=["viewer", "editor", "administrator"]): collabs = set() - for team_access in self.roles["team"]: + for team_access in self.roles.get("team", []): + # note, if team information is missing from userinfo that means + # the user is not a member of any collab parts = team_access.split("-") assert parts[0] == "collab" collab = "-".join(parts[1:-1]) diff --git a/api/simqueue/resources/for_users.py b/api/simqueue/resources/for_users.py index 6db70b2..a4e0581 100644 --- a/api/simqueue/resources/for_users.py +++ b/api/simqueue/resources/for_users.py @@ -792,7 +792,7 @@ async def delete_project( if project is not None: if (as_admin and user.is_admin) or user.can_edit(project["collab"]): - if await db.query_quotas([project_id]) is not None: + if await db.query_quotas(project_id) is not None: await db.delete_quotas_from_project(str(project_id)) await db.delete_project(str(project_id)) else: @@ -867,7 +867,8 @@ async def create_project( status_code=status_codes.HTTP_403_FORBIDDEN, detail="You do not have permisson to create projects in this Collab", ) - await db.create_project(project) + created_project = await db.create_project(project) + return Project.from_db(created_project) @router.get("/projects/{project_id}/quotas/", response_model=List[Quota]) @@ -999,9 +1000,12 @@ async def query_collabs( status_code=status_codes.HTTP_501_NOT_IMPLEMENTED, detail="This option has not been implemented yet", ) - projects = await db.query_projects( - status=status, collab=collabs, owner=None, from_index=from_index, size=size - ) + if collabs: + projects = await db.query_projects( + status=status, collab=collabs, owner=None, from_index=from_index, size=size + ) + else: + projects = [] collabs = set(prj["collab"] for prj in projects) return sorted(collabs) diff --git a/api/simqueue/tests/test_auth_router.py b/api/simqueue/tests/test_auth_router.py index 0f78f53..7b12924 100644 --- a/api/simqueue/tests/test_auth_router.py +++ b/api/simqueue/tests/test_auth_router.py @@ -8,13 +8,9 @@ def test_read_main(): response = client.get("/") assert response.status_code == 200 - assert response.json() == { - "about": "This is the EBRAINS Neuromorphic Computing Job Queue API.", - "authentication": { - "client-id": None, - "collaboratory": "https://wiki.ebrains.eu/rest/v1/", - "server": "https://iam.ebrains.eu/auth/realms/hbp", - }, - "version": "3", - "links": {"documentation": "/docs"}, - } + result = response.json() + assert result["about"] == "This is the EBRAINS Neuromorphic Computing Job Queue API." + assert result["authentication"]["collaboratory"].startswith("https://wiki") + assert result["authentication"]["server"].startswith("https://iam") + assert result["version"] == "3" + assert result["links"] == {"documentation": "/docs"} diff --git a/api/simqueue/tests/test_quotas_router.py b/api/simqueue/tests/test_quotas_router.py index 6c7c920..3dbd9d3 100644 --- a/api/simqueue/tests/test_quotas_router.py +++ b/api/simqueue/tests/test_quotas_router.py @@ -248,9 +248,24 @@ def test_get_project(mocker): assert simqueue.db.get_project.await_args.args == expected_args +mock_project = { + "collab": "my-collab", + "title": "testing Collaboratory v2 integration", + "abstract": "abstract goes here", + "description": "dddddd", + "context": "3da3e111-6a73-4a78-a850-67fabd524cba", + "owner": "haroldlloyd", + "duration": 0, + "submission_date": None, + "decision_date": None, + "start_date": None, + "accepted": False, +} + + def test_create_project_asmember(mocker): mocker.patch("simqueue.oauth.User", MockUser) - mocker.patch("simqueue.db.create_project") + mocker.patch("simqueue.db.create_project", return_value=mock_project) datap = { "collab": "my-collab",