From c95fb89c630ab4fc97472ba079d4fe61c16dc9a2 Mon Sep 17 00:00:00 2001 From: Ludy Date: Sun, 21 Jun 2026 11:25:30 +0200 Subject: [PATCH] fix(frontend): correctly display the current user role in the edit dialog (#6758) # Description of Changes This PR fixes the role field in the People settings "Edit User" dialog so the currently assigned role is displayed correctly. - What was changed - The edit dialog now uses the actual role identifier from the user data when preselecting the role. - The role selection is made more robust by falling back to a valid default when the backend response does not provide a usable role value. - The role label shown in the UI is derived consistently from the role identifier. - Why the change was made - The dialog could open with an empty role field even though the user already had a role assigned. - This made role editing confusing and could lead to accidental changes. - The fix keeps the People UI aligned with the backend role data model. before: image after: image --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### Translations (if applicable) - [ ] I ran [`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have run `task check` to verify linters, typechecks, and tests pass - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#7-testing) for more details. --- .../public/locales/en-US/translation.toml | 1 + .../config/configSections/PeopleSection.tsx | 55 +++++++++++++++---- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/frontend/editor/public/locales/en-US/translation.toml b/frontend/editor/public/locales/en-US/translation.toml index 2e60ebf3d1..0bfb5749ce 100644 --- a/frontend/editor/public/locales/en-US/translation.toml +++ b/frontend/editor/public/locales/en-US/translation.toml @@ -8604,6 +8604,7 @@ disableByAdmin = "Disable MFA" [workspace.people.roleDescriptions] admin = "Can manage settings and invite users, with full administrative access." +currentRole = "Current assigned role." user = "Can view and edit shared files, but cannot manage workspace settings or users." [workspace.people.toggleEnabled] diff --git a/frontend/editor/src/proprietary/components/shared/config/configSections/PeopleSection.tsx b/frontend/editor/src/proprietary/components/shared/config/configSections/PeopleSection.tsx index 151d0c5dff..454b9e138c 100644 --- a/frontend/editor/src/proprietary/components/shared/config/configSections/PeopleSection.tsx +++ b/frontend/editor/src/proprietary/components/shared/config/configSections/PeopleSection.tsx @@ -94,6 +94,21 @@ export default function PeopleSection() { const isCurrentUser = (user: User) => currentUser?.username === user.username; const isLockedUser = (user: User) => lockedUsers.includes(user.username); + const getUserRoleId = (user: User) => + user.rolesAsString || + (user.roleName?.startsWith("ROLE_") ? user.roleName : undefined) || + "ROLE_USER"; + + const getRoleLabel = (roleId: string) => { + switch (roleId) { + case "ROLE_ADMIN": + return t("workspace.people.admin", "Admin"); + case "ROLE_USER": + return t("workspace.people.user", "User"); + default: + return roleId; + } + }; // Form state for edit user modal const [editForm, setEditForm] = useState({ @@ -353,7 +368,7 @@ export default function PeopleSection() { const openEditModal = (user: User) => { setSelectedUser(user); setEditForm({ - role: user.roleName, + role: getUserRoleId(user), teamId: user.team?.id, }); setEditUserModalOpened(true); @@ -385,7 +400,7 @@ export default function PeopleSection() { const roleOptions = [ { value: "ROLE_ADMIN", - label: t("workspace.people.admin"), + label: getRoleLabel("ROLE_ADMIN"), description: t( "workspace.people.roleDescriptions.admin", "Can manage settings and invite members, with full administrative access.", @@ -394,7 +409,7 @@ export default function PeopleSection() { }, { value: "ROLE_USER", - label: t("workspace.people.user"), + label: getRoleLabel("ROLE_USER"), description: t( "workspace.people.roleDescriptions.user", "Can view and edit shared files, but cannot manage workspace settings or members.", @@ -474,7 +489,9 @@ export default function PeopleSection() { {" "} - {t("workspace.people.license.users", "users")} + {t("workspace.people.license.users", "users", { + count: licenseInfo.totalUsers, + })} @@ -704,18 +721,18 @@ export default function PeopleSection() { size="sm" variant="light" color={ - (user.rolesAsString || "").includes("ROLE_ADMIN") + getUserRoleId(user) === "ROLE_ADMIN" ? "blue" - : "cyan" + : getUserRoleId(user) === "ROLE_PRO_USER" + ? "grape" + : "cyan" } styles={{ root: { maxWidth: "none" }, label: { overflow: "visible" }, }} > - {(user.rolesAsString || "").includes("ROLE_ADMIN") - ? t("workspace.people.admin", "Admin") - : t("workspace.people.user", "User")} + {getRoleLabel(getUserRoleId(user))} @@ -1009,7 +1026,25 @@ export default function PeopleSection() {