From 9569af5fcd1ecdb48823b7cfa7c7be57a19711ad Mon Sep 17 00:00:00 2001
From: Just van Rossum <justvanrossum@gmail.com>
Date: Mon, 15 Jan 2024 22:35:08 +0100
Subject: [PATCH 1/2] Check user groups and permissions to determine read-only
 status, and 'dummy editor' status

---
 src/fontra_rcjk/projectmanager.py | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/fontra_rcjk/projectmanager.py b/src/fontra_rcjk/projectmanager.py
index 2c05690..ec44cd9 100644
--- a/src/fontra_rcjk/projectmanager.py
+++ b/src/fontra_rcjk/projectmanager.py
@@ -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]
@@ -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 users 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)

From 6e5b0f2aecccbd921bd34d712572ee42fbd61e49 Mon Sep 17 00:00:00 2001
From: Just van Rossum <justvanrossum@gmail.com>
Date: Mon, 15 Jan 2024 22:42:11 +0100
Subject: [PATCH 2/2] Fix typo

---
 src/fontra_rcjk/projectmanager.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/fontra_rcjk/projectmanager.py b/src/fontra_rcjk/projectmanager.py
index ec44cd9..c06bd83 100644
--- a/src/fontra_rcjk/projectmanager.py
+++ b/src/fontra_rcjk/projectmanager.py
@@ -219,7 +219,7 @@ async def _userPermissions(self) -> tuple[bool, bool]:
         userMeResponse = await self.rcjkClient.user_me()
         userInfo = userMeResponse["data"]
 
-        # Only check write permissions is the users belongs to at least one group
+        # Only check write permissions is the user belongs to at least one group
         userReadOnly = (
             not _hasKeyValue(
                 userInfo["permissions"], "codename", "change_characterglyph"