Repository navigation
OpenConceptLab/ocl_online#648 | Organization roles on the org page - #105
Conversation
The org page uses the role the API sends. Only an admin or staff sees Edit Members, Edit and Delete. Any member still sees New Repository, and can now leave from the Manage menu, as Edit Members was the only way to before. Browse members shows each member's role, and Edit Members lets an admin set it. A save sends what gives rights before what takes them away, so that handing over to a new admin in one save works. The members request asks for up to 100, as the default page of 25 hid members of the largest organizations from these controls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…es last, re-selecting keeps a role An admin who demotes themselves in a save could lose the right to finish the rest of it, so their own change now goes last and a failure stops what follows. An existing admin taken off and selected again from a user search stays an admin: a search result has no role, so the role comes from the membership. Leaving finishes on the page even if refreshing the cached user fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…rty is just a username Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…er and repeated tests A role picked in the members dialog now stays on the selected member. Adds the Spanish for "Member", which the new controls show. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
snyaggarwal
left a comment
There was a problem hiding this comment.
Review with extra focus on race conditions, null pointers, new patterns and reuse. The main points are two double-submit races (Edit Members Submit, Leave), parallel demotions racing the API's last-admin check, stale admin UI after removing yourself via Edit Members, and the Manage button still gated by the cached org list while its items use user_role. Details inline.
🤖 Generated with Claude Code
| t(`org.member_${action}_failed`, {user: member.username, detail}) | ||
| ) | ||
|
|
||
| const onSubmit = async () => { |
There was a problem hiding this comment.
Race: Submit has no in-flight guard. The Submit link stays enabled while onSubmit runs. A double-click, or a second Submit before fetchOrg's refetch updates members, re-sends every batch against the stale list. The losing DELETE members/<user>/ gets a 404, which shows "Could not remove …" and keeps the dialog open although the change went through. Suggest a saving state that disables Submit until the refetch lands.
There was a problem hiding this comment.
Fixed in e7db18a and 7b85f03. Submit is off from the click until the members are fetched again, and the dialog can't be dismissed in the meantime, so neither a second click nor reopening it resends a change. 1b540cf also locks the search and role fields while it saves, so nothing typed then is lost.
Since then, Jon asked for a different Edit Members (c6d6526): there's no Submit, and each change is saved as it's made. The same guard holds there: every control is off from the change until the org and its members are fetched again, and a second change can't start before then.
| for(const batch of batches) { | ||
| // A batch can rely on the ones before it, so a failure stops the rest, and saving again retries them. | ||
| if(!results.some(({error}) => error)) | ||
| results.push(...await Promise.all(batch.map(updateMember))) |
There was a problem hiding this comment.
Race: revocations run in parallel. Promise.all sends every demotion and removal in the revocations batch at once, so the API's last-admin check can see the others as still admin. For example, a staff user who isn't a member demotes both of an org's two admins in one save, and both succeed. Running this batch one request at a time lets the API refuse the last one.
There was a problem hiding this comment.
Fixed in e7db18a: every change went one request at a time, in order, and the first failure stopped the rest, so the second demotion in your example got the API's 409.
Since then, Jon asked for a different Edit Members (c6d6526): there's no batch. Each change is saved as it's made, and the next can't start until the org and its members are fetched again, so two demotions never overlap. Demoting the last admin gets the API's 409, and the role stays as it was.
| } | ||
|
|
||
| fetchMembers() | ||
| fetchOrg() |
There was a problem hiding this comment.
Removing yourself here leaves the admin view up. getMemberChanges allows the requester to remove themselves, but after the save only fetchOrg() runs. For a private org that refetch returns 403/404, which fetchOrg ignores, so org.user_role stays admin and Edit, Delete and Edit Members stay visible. Unlike onLeave, the cached user isn't refreshed either, so subscribed_orgs is stale. Maybe route a self-removal through the same path as Leave.
Minor: fetchOrg also re-fetches the overview on every save; only a change to the requester's own role (batches[2].length) needs user_role refreshed.
There was a problem hiding this comment.
Fixed in e7db18a. Removing yourself in Edit Members now goes the way Leave does: the cached user is refreshed and the page moves to your profile. 1b540cf keeps the dialog up until then.
On the minor point: I tried refetching the org only after a change to your own role. A Codex check then showed that this misses a demotion someone else makes while the dialog is open, which leaves the admin controls up after a 403. So a8c259b refetches the org, then the members, after every save, and closes Edit Members once you aren't an admin.
|
|
||
| const newMembers = selectedMembers.filter(member => !members.map(user => user.username).includes(member.username)) | ||
| const deletedMembers = members.filter(member => !selectedMembers.map(user => user.username).includes(member.username)) | ||
| const batches = getMemberChanges(members, selectedMembers, getCurrentUser()?.username) |
There was a problem hiding this comment.
Two small things here:
selectedMembersstarts as[]and is filled by the mount effect above, so on the first render every member counts as a removal and the "- Remove" text flashes.React.useState(() => members || [])avoids the effect.getCurrentUser()?.usernameJSON-parses localStorage on every render;getCurrentUserUsername()incommon/utilsalready does this.
There was a problem hiding this comment.
| { | ||
| selectedMembers.map(member => ( | ||
| <ListItem key={member.username} disableGutters> | ||
| <ListItemText primary={getMemberDisplayName(member)} /> |
There was a problem hiding this comment.
Possible crash: getMemberDisplayName calls member.name.trim() with no guard, and this list now calls it for every selected member. A member or search result with a null name would throw and break the dialog. (member.name || '').trim() avoids that.
There was a problem hiding this comment.
Fixed in e7db18a: (member.name || '').trim().
| }) | ||
| } | ||
|
|
||
| const onLeave = () => { |
There was a problem hiding this comment.
Race: Leave can be submitted twice. LeaveOrgDialog's button stays enabled during the DELETE and the cache refresh. A double-click sends two DELETEs: the first returns 204 and navigates, the second returns 404 and runs the else-branch, so an error alert shows right after a successful leave. A pending flag that disables the button would fix it.
| refreshCurrentUserCache(onLeft, onLeft) | ||
| } else { | ||
| setLeaveOrg(false) | ||
| setAlert({severity: 'error', message: response?.response?.data?.detail || t('common.generic_error')}) |
There was a problem hiding this comment.
Reuse: this reads only response?.response?.data?.detail, while EditMembers has getErrorDetail / normalizeErrorDetail for the same members/<user>/ endpoint, which also handle error, __all__, list and object bodies. Moving that helper to common/utils and using it in both places keeps them from drifting.
There was a problem hiding this comment.
Done in e7db18a: getErrorDetail is in common/utils, and Leave uses it too.
| </MenuItem> | ||
| } | ||
| { | ||
| org.user_role && |
There was a problem hiding this comment.
Two sources of truth for access. These items now follow the API's org.user_role, but the Manage button that opens this menu is still gated by currentUserHasAccess(), which reads subscribed_orgs from the cached user. A user added or promoted since their cache was last refreshed has user_role from the API but no Manage button, so they can't leave or administer until they reload. Gating Manage on isAdminUser() || org.user_role would make the API the one source.
There was a problem hiding this comment.
Fixed in e7db18a: Manage shows for isAdminUser() || org.user_role, so the button and its items both follow the API.
| /> | ||
| { | ||
| member.role && | ||
| <Chip size='small' variant='outlined' sx={{marginTop: '8px', marginLeft: '8px'}} label={t(`org.${member.role}`)} /> |
There was a problem hiding this comment.
t(org.${member.role}) builds the key from raw API data. A role other than admin/member would show as the literal key (e.g. org.owner), and in EditMembers the Select would get an out-of-range value. A role→label map with a fallback next to ROLE_ADMIN/ROLE_MEMBER in orgRoles.js would keep the roles in one place.
There was a problem hiding this comment.
Done in e7db18a: ROLE_LABEL_KEYS and getRoleLabel sit next to the role constants in orgRoles.js. A role the app doesn't know shows as the API sent it. In Edit Members it shows but can't be picked, so the Select never gets an out-of-range value.
|
@paynejd Edit Members Dialog
Leave org dialog
Members List dialog
|
|
On point 1 of the Edit Members review (an org admin can remove superuser and staff members): @paynejd decided on Nov 18 to keep it as it works today. An org admin manages all of that org's members, staff and superusers included. Blocking it only in the dialog wouldn't stop the same API call, so if a real case for the rule appears, it gets its own oclapi2 ticket. No change is needed in this PR for point 1. The other review points still stand. |
… changes go one at a time, and removing yourself is leaving From review: - Edit Members sends its changes one request at a time, so the API's last-admin check sees each one, and Submit is off until the members are fetched again. - Leave is off while its request runs. - Removing yourself in Edit Members refreshes your cached user and leaves the page, as Leave does. A change to your own role refetches the org, and anything else only the members. - The Manage button follows the role the API gives you, like the items in it. - Role labels come from one map, and a role the app doesn't know shows as sent. - getErrorDetail moves to common/utils and Leave uses it too; a member with no name no longer breaks the dialog, and it no longer flashes every member as removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…mbers are fetched again, and only a 2xx counts as done From the Codex check of the review fixes: - The dialog stays up, with Submit off and no way to dismiss it, until the members are fetched again, so reopening it can't resend a change that went through. - A request with no response, such as a network error, is a failure, so the save stops there instead of going on as if it worked. - Adding yourself refetches the org too, so Leave shows without a reload. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…aving, and leaving holds until the page moves on From the second Codex check: - The member search and role controls are off while a save and its refresh run, so nothing typed then is dropped when the dialog closes. - After you remove yourself, the dialog stays up until your cached user is fresh and the page is on its way to your profile. - Leave ignores a click while its dialog fades out after a refusal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
… through refetches the org, and role labels use own keys only From the third Codex check: - A change to your own role that failed without a response may still have been made, so the org is fetched again for your role either way. - A role named like an object property, such as `constructor`, shows as sent instead of picking up an inherited property as its label. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…etched again, and the org too after an own role change From the final Codex check: the org request failing must not skip the members, or the next save compares against a list the API has moved past. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…etched before the members, so the count matches the list Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…he members, and Edit Members closes when you stop being an admin From the final Codex check: refetching the org only after a change to your own role missed a demotion someone else made while the dialog was open, which left the admin controls up. The org now comes back after every save, and Edit Members closes once you aren't an admin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…top being an admin Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…es it Closing it toggled it, so a backdrop click while it faded out could open it again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…in Edit Members, a red Leave, and an Admin chip that stands out From Sunny's look in the browser: - Edit Members shows each member as a user chip with their name, and picks the role with a Member | Admin toggle group instead of a select. - Leave Organization is red, and the org's name is bold. - In Browse members, Admin is a primary outlined chip and Member a default one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…with a role dropdown and a remove action, and adds one user at a time Each member shows once, in the list, with a role dropdown and a remove action at the right. Each change goes to the API as soon as it's made. Removing someone asks first in a dialog, and removing yourself asks with the Leave wording. Add Member opens the user search for a single user, with the role to add them as. The dropdown offers the roles this app knows, and keeps a role it doesn't know yet, so more roles can be added. The Leave message no longer says an admin can add you back, and opening Edit Members closes the Manage menu. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…arch shows, Leave can't be cancelled once sent, and Edit Members fits a phone - Typing a new search drops the user picked before it, and a user who has become a member since being picked is no longer picked, so Add never changes an existing member's role. - Leave's Cancel, Escape and backdrop are off while it's being sent. - The add row wraps, and avatars hide, at phone width. - The Leave and Remove messages show the org's name as typed, with no HTML entities. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…dds the picked user only while the search shows them Clearing the pick on typing made the search box empty itself. The pick now stays, and Add is on only while the search shows that user and they aren't a member. A pick who becomes a member is dropped. The Edit Members header wraps, so a long org name can't push Add Member off a phone screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…what you typed or picked, and one search runs at a time - The box is controlled in Edit Members: typing drops the pick, and MUI's own resets on blur or a pick change are ignored, so leaving the box can't bring back an earlier pick. - One delayed search lasts for the dialog's life, and a response counts only while its query is still the one in the box. - Long names and usernames wrap in their column at phone width. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…dule level Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…e a member stays dropped Add needs a new pick even if that user leaves the org again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…n asks first Edit Members asks before an admin takes away their own admin rights, since another admin would have to give them back. The role changes only on Change Role; Cancel leaves it as it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
…irm's warning Change Role, Remove Member and Leave Organization each point the dialog's description at their message, so it's read out with the title rather than only the buttons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
Claude review, with a Codex second opinion (commit 0c362ec)Verdict: The full review, with the acceptance criteria, is on the ticket. In short:
CI's lint and tests pass on this commit, and the 8 new tests pass locally. The app wasn't run in a browser. Codex (0.169.0, xhigh) found the same three, rating them P1, and one more retry edge case (P2, on the ticket); I disagree with its one other point, that the org edit route needs its own gate, since the API refuses the save and the form shows why. |
…picked The add row still shows Member, but until someone picks a role the request carries none: the API makes a new member a plain member and leaves an existing member's role alone. Edit Members loads the first 100 members, so in a larger org, adding someone past them who is already an admin no longer demotes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK
|
@snyaggarwal I've pushed the fixes for your 08:00Z review, e7db18a to bd9f0ff, and the visual changes after them, and replied to each inline comment. Codex checked each round of fixes until a check came back clean. On the way it found more problems of the same kind, and those are fixed too:
The full checks are on OpenConceptLab/ocl_online#648. Two edge cases are accepted rather than fixed:
Your 14:03Z points are done too, and Jon asked for more after seeing them, so Edit Members changed shape (a6982f8 to 60ad1bb):
Codex reviewed these in three passes and five checks, and no P0 or P1 is open. One check found that the confirms' warnings weren't read out by screen readers, only their titles and buttons; Change Role, Remove Member and Leave Organization now announce them. One more edge case is accepted: if two admins add the same person at the same moment, the later role wins, because the members PUT both adds and changes a role. Point 1 is answered above. The review of 0c362ec posted here on Nov 19 asked for four fixes. The commits above already cover three: Jon's Nov 19 changes, removing yourself in Edit Members now runs the Leave steps, and Manage shows for anyone with a role in the org. The fourth is 0fb84e6: an add sends a role only when someone picks one, so in an org with more than the 100 members Edit Members loads, adding an existing admin past them can't demote them. Codex's check of that commit suggested that choosing Member from the menu when it already shows Member should send it; I've left that out, since the add row adds people and shouldn't take an admin's rights away. One part of its self-removal point is left: if another admin removes you from a private org while you have its page open, the admin controls stay until a reload, and the API refuses each one with its reason.
|
snyaggarwal
left a comment
There was a problem hiding this comment.
Approving at 0fb84e6. Everything from my Nov 18 review is answered as your replies describe:
- Saving: a change saves one at a time behind
busy/saving. Every control and the dialog's close stay off until the org and its members are fetched again, so a double click or a second change can't race. - Removing yourself goes the Leave way (
onSaved({left})), and the Leave button is disabled while its DELETE runs. - Manage follows the API:
isAdminUser() || org.user_role. - Roles have one home in
orgRoles.js:getRoleLabel,getRoleOptions(an unknown role shows as sent and can't be picked) anddemotesSelf, which asks first. - Small fixes:
getErrorDetailis shared incommon/utils, andgetMemberNameguards a null name.
Against my screenshots of Nov 18:
- Removing superuser and staff members: kept as it works today, by Jon's decision, since the API allows it.
- The role control is now an outlined
Select. - User chips: the rows show the user's avatar, name and username, like Browse members, rather than
UserChip. That's fine with Jon's redesign. - Leave has a red (
error) button, and the org name is in bold in all four locales. - Browse members: Admin is a primary outlined chip, and Member a default outlined one.
Nit, pre-existing: the Add Member search box's texts are hard-coded English ('Loading...', 'Type atleast 2 characters to search', 'No results', 'Start typing...'), with "atleast" for "at least". This PR moves those lines, so translating them here would be cheap.
I haven't run it in a browser. CI's lint and tests pass, and it merges cleanly with main.



The TBv3 side of organization roles, part of OpenConceptLab/ocl_online#648. The API enforces every permission; this shows each role and gives admins the controls.
This needs OpenConceptLab/oclapi2#983, which has been on production since Nov 11. Against an older API,
user_roleis missing, so anyone who isn't staff loses Edit Members, Edit and Delete until the API is upgraded.What changes
New strings are in en, es, pt-BR and zh. It also adds the Spanish for "Member", which was missing.
Design system: no gap. This reuses the existing dialogs, buttons and user search,
ChipasAccessChipuses it, and MUI'sSelect.Tested
npm testgives 158 OK, and the production build (npm run build, as the Dockerfile runs it) compiles.admin), promoting, removing through the confirm, removing yourself, Leave, and changing your own role (Cancel sends nothing, the only admin is refused with the API's reason, and with a second admin it goes through and Edit Members closes). At 360 px the add row and long names wrap. Each confirm's warning is its dialog's accessible description. No page errors.Reviews
Codex passes, checks and simplification reviews, in full on the ticket, for the first version, for the fixes from review, and for the new Edit Members, plus a Claude review with a Codex second opinion of 0c362ec, whose fixes are in. No P0 or P1 is open. Four edge cases are accepted: a refresh that fails after a save leaves the list as it was until a reload; a self-removal whose response is lost doesn't run the Leave steps until a reload; if another admin removes you from a private org while its page is open, its admin controls stay until a reload, and the API refuses each one; and if two admins add the same person at the same moment, the later role wins, because the members PUT both adds and changes a role (OpenConceptLab/ocl_online#712). There's no adversarial pass on this side, since it only hides controls and the API enforces them.
🤖 Generated with Claude Code
https://claude.ai/code/session_01AaZ4qUSJnKeDYRubKa6DYK