Skip to content

Commit

Permalink
Merge pull request #145 from googlefonts/issue144
Browse files Browse the repository at this point in the history
Check user groups and permissions to determine read-only status, and 'dummy editor' status
  • Loading branch information
justvanrossum authored Jan 16, 2024
2 parents 033f542 + 6e5b0f2 commit a971ea0
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/fontra_rcjk/projectmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ async def getFontHandler(self, path: str) -> FontHandler:
self.rcjkClient, fontUID, self.cacheDir
)

userReadOnly, dummyEditor = await self._userPermissions()

async def closeFontHandler():
logger.info(f"closing FontHandler '{path}' for '{self.username}'")
del self.fontHandlers[path]
Expand All @@ -205,9 +207,35 @@ async def closeFontHandler():
logger.info(f"new FontHandler for '{path}'")
fontHandler = FontHandler(
backend,
readOnly=self.readOnly,
readOnly=self.readOnly or userReadOnly,
dummyEditor=dummyEditor,
allConnectionsClosedCallback=closeFontHandler,
)
await fontHandler.startTasks()
self.fontHandlers[path] = fontHandler
return fontHandler

async def _userPermissions(self) -> tuple[bool, bool]:
userMeResponse = await self.rcjkClient.user_me()
userInfo = userMeResponse["data"]

# Only check write permissions is the user belongs to at least one group
userReadOnly = (
not _hasKeyValue(
userInfo["permissions"], "codename", "change_characterglyph"
)
if "permissions" in userInfo and userInfo.get("groups")
else False
)

dummyEditor = (
_hasKeyValue(userInfo["groups"], "name", "DummyDesigners")
if "groups" in userInfo
else False
)

return userReadOnly, dummyEditor


def _hasKeyValue(items, key, value):
return any(item.get(key) == value for item in items)

0 comments on commit a971ea0

Please sign in to comment.