Skip to content

Commit b61e1db

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

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
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([f"{PRIVATE_SPACE}-{self.username}"])
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

0 commit comments

Comments
 (0)