Repository navigation
fix(roles): show correct Admin/Moderator/Owner badges for server-wide… - #1409
Open
swarnendusahu10-dotcom wants to merge 1 commit into
Conversation
… roles Previously getUserRoles() only fetched admin-role users and merged all roles into a single flat array, causing moderators and owners to never receive a badge, and the partial fix caused everyone to show 'Admin' badge incorrectly. This commit returns separate admins/moderators/owners arrays from getUserRoles(), stores them independently in memberStore, and renders the correct badge label for each role in MessageHeader. Fixes RocketChat#1288
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR fix?
Closes #1288
Problem
getUserRoles()inEmbeddedChatApi.tsonly ever calledgetUsersInRole("admin").Server-wide moderators and owners were completely invisible — they received no badge at all.
A previous partial attempt merged all three roles into a single flat
adminsarray,which caused every moderator and owner to display an incorrect "Admin" badge.
Root cause
The function returned
{ result: response.users }— a flat list of only admin users —and the caller mapped that list into
admins[]in the Zustand store. There were nomoderatorsorownersslots in the store, andMessageHeader.jshad no renderinglogic for those roles.
Fix
Changed
getUserRoles()to fetch all three roles in parallel viaPromise.allandreturn them as separate typed arrays:
{ admins, moderators, owners }.Four files changed:
packages/api/src/EmbeddedChatApi.ts— correct return type + separated arrayspackages/react/src/store/memberStore.js— addsmoderators: [],owners: [],setModerators,setOwnersto the Zustand storepackages/react/src/hooks/useFetchChatData.js— destructures and stores each rolearray independently
packages/react/src/views/Message/MessageHeader.js— renders a correct "Moderator"or "Owner" badge box alongside the existing "Admin" badge box
Why this change is necessary
Role badges are a trust signal. An embedded chat widget that shows the wrong badge
(or no badge) for a server Moderator or Owner undermines moderation visibility and
user trust — especially in support or community chat embeds where knowing who holds
authority matters. This is a correctness bug with a UX and moderation-trust impact.
Edge cases tested (45/45 pass)
success: false→ gracefully returns empty arraysnull/ non-arrayusersfield → handled without crashusernamefield missing on a user object → safely skippedusernamecoerced to string correctlyPromise.allfailure → falls back to{ admins:[], moderators:[], owners:[] }getChannelRoles) → completely unaffectedSecurity
String(u.username)coercion +.filter(u => u?.username)guard → no__proto__injectionroles.getUsersInRoleREST callgetChannelRoles/memberRoles) is untouched