Skip to content

Commit c29bf8a

Browse files
committed
Add support for per-user quotas, by allowing a fake collab name "private" which is expanded to "private-{username}"
1 parent de5400b commit c29bf8a

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

api/simqueue/globals.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@
2626
"Spikey": 1.0,
2727
"Demo": 1.0,
2828
}
29+
30+
PRIVATE_SPACE = "private"

api/simqueue/oauth.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from fastapi import Security, HTTPException, status as status_codes
88

99
from . import settings, db
10+
from .globals import PRIVATE_SPACE
1011

1112

1213
logger = logging.getLogger("simqueue")
@@ -75,6 +76,8 @@ def username(self):
7576
return self.preferred_username
7677

7778
async def can_view(self, collab):
79+
if collab == f"{PRIVATE_SPACE}-{self.username}":
80+
return True
7881
# first of all, check team permissions
7982
target_team_names = {
8083
role: f"collab-{collab}-{role}" for role in ("viewer", "editor", "administrator")
@@ -91,6 +94,8 @@ async def can_view(self, collab):
9194
return collab_info.get("isPublic", False)
9295

9396
def can_edit(self, collab):
97+
if collab == f"{PRIVATE_SPACE}-{self.username}":
98+
return True
9499
target_team_names = {
95100
role: f"collab-{collab}-{role}" for role in ("editor", "administrator")
96101
}
@@ -99,7 +104,7 @@ def can_edit(self, collab):
99104
return True
100105

101106
def get_collabs(self, access=["viewer", "editor", "administrator"]):
102-
collabs = set()
107+
collabs = set() # do we add "private" to this set?
103108
for team_access in self.roles.get("team", []):
104109
# note, if team information is missing from userinfo that means
105110
# the user is not a member of any collab

api/simqueue/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from .data_models import ProjectStatus, ResourceUsage
1010
from . import db, settings
11-
from .globals import RESOURCE_USAGE_UNITS, PROVIDER_QUEUE_NAMES, DEMO_QUOTA_SIZES
11+
from .globals import RESOURCE_USAGE_UNITS, PROVIDER_QUEUE_NAMES, DEMO_QUOTA_SIZES, PRIVATE_SPACE
1212

1313
logger = logging.getLogger("simqueue")
1414

@@ -29,7 +29,13 @@ async def check_quotas(collab: str, hardware_platform: str, user: str = None):
2929
3030
If the collab has never had a quota for the given platform and , but a username `user` is specified,
3131
then a new test/demo quota will be created with the owner set to `user`.
32+
33+
If the collab is set to the special value "private", then we generate a fake collab name based
34+
on the username. This allows users to access the platform without needing to create a real collab.
35+
Results generated with such private access are not available to others.
3236
"""
37+
if user is not None and collab == PRIVATE_SPACE:
38+
collab = f"{PRIVATE_SPACE}-{user.username}"
3339
available_quotas = await get_available_quotas(collab, hardware_platform)
3440
if len(available_quotas) == 0 and user is not None and hardware_platform in DEMO_QUOTA_SIZES:
3541
# if this collab has never had a quota for this platform, we create a default test quota

0 commit comments

Comments
 (0)