Skip to content

Commit

Permalink
assorted tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
apdavison committed Jan 18, 2024
1 parent 708b718 commit 36eac08
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
2 changes: 1 addition & 1 deletion api/simqueue/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions api/simqueue/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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])
Expand Down
14 changes: 9 additions & 5 deletions api/simqueue/resources/for_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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)

Expand Down
16 changes: 6 additions & 10 deletions api/simqueue/tests/test_auth_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
17 changes: 16 additions & 1 deletion api/simqueue/tests/test_quotas_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 36eac08

Please sign in to comment.