feat(desktop): push user roles to the desktop app - #41056
Conversation
Add a setUserRoles method to the desktop API bridge and push the logged-in user's roles to the desktop app reactively. This lets the desktop client restrict supportedVersions messages (e.g. version-expiration warnings) to specific roles such as admins instead of showing them to every user. The call is optional so desktop builds without the bridge method keep working and fall back to their own role lookup.
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
🦋 Changeset detectedLatest commit: c42e8f1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughAdds ChangesDesktop User Roles Bridge
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts (1)
4-9: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDrop the new JSDoc block.
The repo guideline for TypeScript files says to avoid code comments in implementation, and this block doesn’t add enough value to keep.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts` around lines 4 - 9, Remove the entire JSDoc comment block that describes the purpose of pushing logged-in user roles to the desktop app. According to the repository guidelines for TypeScript files, implementation comments should be avoided when they don't provide substantial value. Delete the multi-line comment block (starting with /** and ending with */) that precedes the function definition.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts`:
- Around line 10-19: The useEffect in useDesktopUserRoles returns early when
userId is not available, which leaves the previous user's roles cached on
window.RocketChatDesktop during logout or account switching. Remove the early
return on !userId and instead ensure that
window.RocketChatDesktop?.setUserRoles?. is always called with either the
current user's roles (if userId exists) or an empty array (if userId is
null/undefined). This way the cached roles will be properly cleared when a user
logs out or switches accounts.
---
Nitpick comments:
In `@apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts`:
- Around line 4-9: Remove the entire JSDoc comment block that describes the
purpose of pushing logged-in user roles to the desktop app. According to the
repository guidelines for TypeScript files, implementation comments should be
avoided when they don't provide substantial value. Delete the multi-line comment
block (starting with /** and ending with */) that precedes the function
definition.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 55a81297-fb06-45fb-af76-d87e28eeacb7
📒 Files selected for processing (4)
.changeset/desktop-set-user-roles.mdapps/meteor/client/views/root/AppLayout.tsxapps/meteor/client/views/root/hooks/useDesktopUserRoles.tspackages/desktop-api/src/index.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (5)
- GitHub Check: 📦 Build Packages
- GitHub Check: cubic · AI code reviewer
- GitHub Check: CodeQL-Build
- GitHub Check: Hacktron Security Check
- GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
apps/meteor/client/views/root/hooks/useDesktopUserRoles.tsapps/meteor/client/views/root/AppLayout.tsxpackages/desktop-api/src/index.ts
🧠 Learnings (7)
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.
Applied to files:
apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.
Applied to files:
apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
apps/meteor/client/views/root/hooks/useDesktopUserRoles.tspackages/desktop-api/src/index.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
apps/meteor/client/views/root/hooks/useDesktopUserRoles.tspackages/desktop-api/src/index.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
apps/meteor/client/views/root/hooks/useDesktopUserRoles.tsapps/meteor/client/views/root/AppLayout.tsxpackages/desktop-api/src/index.ts
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.
Applied to files:
.changeset/desktop-set-user-roles.md
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.
Applied to files:
apps/meteor/client/views/root/AppLayout.tsx
🔇 Additional comments (4)
packages/desktop-api/src/index.ts (1)
41-41: LGTM!apps/meteor/client/views/root/AppLayout.tsx (2)
21-21: LGTM!
77-77: LGTM!.changeset/desktop-set-user-roles.md (1)
2-6: LGTM!
There was a problem hiding this comment.
1 issue found across 4 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #41056 +/- ##
===========================================
- Coverage 70.14% 70.14% -0.01%
===========================================
Files 3361 3361
Lines 129698 129699 +1
Branches 22483 22489 +6
===========================================
Hits 90980 90980
- Misses 35405 35412 +7
+ Partials 3313 3307 -6
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
Reviewed alongside the desktop consumer (RocketChat/Rocket.Chat.Electron#3371). The contract lines up exactly: Looks good
Notes (non-blocking)
Approving. |
Push an empty roles array when there is no logged-in user so the desktop app clears previously-pushed roles on logout or account switch, instead of keeping stale ones cached.
Collapse the role push to one canonical key derived from the reactive user and push only when it changes. Logout, login and account switch all surface as a change to that key, so stale roles are cleared without a userId branch or an effect cleanup.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts (1)
11-16: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove the implementation comment block in this hook.
This inline rationale comment violates the repo rule for TS/JS implementation code; keep this context in PR/commit docs instead.
Proposed change
export const useDesktopUserRoles = () => { - // A single canonical value derived from the reactive user. Logout, login and - // account switch all surface as a change to this key, so the effect re-runs - // and re-pushes only when the roles actually change — no userId branch and no - // effect cleanup (which would fire on every deps change and flicker - // role-targeted UI). Logged-out and "logged in with no roles" both resolve to - // an empty list, which is the correct signal for the desktop either way. const rolesKey = (useUser()?.roles ?? []).join(',');As per coding guidelines: "
**/*.{ts,tsx,js}: ... Avoid code comments in the implementation".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts` around lines 11 - 16, The inline rationale comment in useDesktopUserRoles should be removed because implementation comments are disallowed in TS/JS code. Delete the comment block near the hook logic and keep any rationale in PR/commit docs instead, without changing the hook’s behavior or surrounding reactive role handling.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts`:
- Around line 11-16: The inline rationale comment in useDesktopUserRoles should
be removed because implementation comments are disallowed in TS/JS code. Delete
the comment block near the hook logic and keep any rationale in PR/commit docs
instead, without changing the hook’s behavior or surrounding reactive role
handling.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e30bf5c8-2960-438d-acf6-be4ffe664bb4
📒 Files selected for processing (1)
apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
- GitHub Check: 📦 Build Packages
- GitHub Check: cubic · AI code reviewer
- GitHub Check: CodeQL-Build
- GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts
🧠 Learnings (5)
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.
Applied to files:
apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.
Applied to files:
apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
apps/meteor/client/views/root/hooks/useDesktopUserRoles.ts
Jira: ARCH-2192
Proposal
Expose the logged-in user's roles to the desktop app so it can decide which
supportedVersionsmessages to show — e.g. restrict version-expiration warnings to admins (the only ones who can act on them) instead of showing them to every user.Changes
@rocket.chat/desktop-api: addsetUserRoles(roles: string[])toIRocketChatDesktop.useDesktopUserRoleshook that reads the current user's roles viauseUser()and pushes them throughwindow.RocketChatDesktop?.setUserRoles?.(...). Mounted inAppLayoutalongside the otheruseDesktop*hooks. The push is reactive — role changes propagate live.The call is optional (
?.) so a web client running inside an older desktop build without the bridge method keeps working; that desktop falls back to its own role lookup.Desktop side
Pairs with the desktop change that consumes this bridge and filters role-targeted
supportedVersionsmessages: RocketChat/Rocket.Chat.Electron#3371. The desktop uses a hybrid acquisition — bridge push (this PR) takes precedence, with a/api/v1/meREST fallback for clients that predate this change.Notes
supportedVersionsmessages are a shared contract (desktop + mobile, produced by cloud). The role-targeting field (Message.roles) is added on the desktop side; this PR provides the role signal the desktop needs.Summary by CodeRabbit
Release Notes