Skip to content

Conversation

@ggazzo
Copy link
Member

@ggazzo ggazzo commented Sep 16, 2025

https://rocketchat.atlassian.net/browse/FDR-142

Proposed changes (including videos or screenshots)

Issue(s)

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Bug Fixes

    • Room editing controls (avatar, description, announcement, type, read-only, reactions, archived, default, featured, delete) are consistently disabled for federated rooms.
    • User management actions (add, remove, change owner/moderator) now consistently respect federation restrictions.
  • Refactor

    • Internal checks for federated rooms streamlined for consistent behavior across admin and room views.
    • Member-navigation handling refined for reliability.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Sep 16, 2025

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Sep 16, 2025

⚠️ No Changeset found

Latest commit: 6c43041

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 16, 2025

Walkthrough

Refactors multiple React components to compute isRoomFederated once per render via a local roomIsFederated constant and replace inline calls; adjusts some memo/use-* dependencies. One handler switched from useCallback to useEffectEvent. No exported/public signatures changed.

Changes

Cohort / File(s) Summary of changes
Admin room editor
apps/meteor/client/views/admin/rooms/EditRoom.tsx
Added roomIsFederated = isRoomFederated(room) and replaced inline isRoomFederated(room) checks across avatar, description/announcement inputs, toggles, and delete button.
Room info panel
apps/meteor/client/views/room/contextualBar/Info/EditRoomInfo/EditRoomInfo.tsx
Removed useMemo around federated check; now calls isRoomFederated(room) directly each render.
Room members contextual bar
apps/meteor/client/views/room/contextualBar/RoomMembers/RoomMembersWithData.tsx
Replaced useCallback-based handleBack with useEffectEvent-based handler; behavior unchanged.
User action hooks (federation guard refactor)
apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useAddUserAction.tsx, .../useChangeModeratorAction.tsx, .../useChangeOwnerAction.tsx, .../useRemoveUserAction.tsx
Introduced roomIsFederated = isRoomFederated(room) and replaced inline checks; updated relevant useMemo deps to depend on roomIsFederated. No signature changes.

Sequence Diagram(s)

sequenceDiagram
  participant UI as Component
  participant Fed as isRoomFederated
  participant State as Local State

  note over UI,Fed: federated check computed once per render (roomIsFederated)
  UI->>Fed: isRoomFederated(room)
  Fed-->>UI: roomIsFederated (boolean)

  alt roomIsFederated == true
    UI->>State: disable inputs/toggles, adjust options
  else roomIsFederated == false
    UI->>State: enable inputs/toggles, standard options
  end

  note over UI: Navigation handler change
  UI->>UI: handleBack via useEffectEvent -> setState({ tab: LIST })
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • ricardogarim

Poem

Thump-thump, I cached the federate flag,
One gentle hop, no repeated drag.
Toggles hush and edits rest,
Back-handler bounces—simple quest.
Carrots saved for code that’s glad. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "refactor: better isRoomFederated usage" is concise, clearly indicates a refactor, and accurately summarizes the primary change (centralizing/improving isRoomFederated usage) present across the modified files in the changeset. It is specific enough for a reviewer scanning PR history to understand the main intent without listing files or extraneous details.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/fed

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cae29f6 and 6c43041.

📒 Files selected for processing (2)
  • apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useChangeModeratorAction.tsx (1 hunks)
  • apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useRemoveUserAction.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useRemoveUserAction.tsx
  • apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useChangeModeratorAction.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Comment @coderabbitai help to get the list of available commands and usage tips.

@ggazzo ggazzo added this to the 7.11.0 milestone Sep 16, 2025
@ggazzo ggazzo marked this pull request as ready for review September 16, 2025 17:18
@ggazzo ggazzo requested a review from a team as a code owner September 16, 2025 17:18
tassoevan
tassoevan previously approved these changes Sep 16, 2025
@ggazzo ggazzo added the stat: QA assured Means it has been tested and approved by a company insider label Sep 16, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Sep 16, 2025
@codecov
Copy link

codecov bot commented Sep 16, 2025

Codecov Report

❌ Patch coverage is 76.19048% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.59%. Comparing base (a087f72) to head (6c43041).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #36952      +/-   ##
===========================================
+ Coverage    66.58%   66.59%   +0.01%     
===========================================
  Files         3346     3346              
  Lines       114661   114666       +5     
  Branches     21097    21102       +5     
===========================================
+ Hits         76350    76365      +15     
+ Misses       35615    35605      -10     
  Partials      2696     2696              
Flag Coverage Δ
e2e 57.80% <76.19%> (+0.01%) ⬆️
unit 71.24% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
apps/meteor/client/views/room/contextualBar/Info/EditRoomInfo/EditRoomInfo.tsx (1)

226-233: Avoid name shadowing: rename the retentionIgnoreThreads id

The form field name retentionIgnoreThreads (data) and the DOM id var retentionIgnoreThreads (UI) collide. Rename the id var for clarity.

Apply:

-const retentionIgnoreThreads = useId();
+const retentionIgnoreThreadsField = useId();
...
-<FieldLabel htmlFor={retentionIgnoreThreads}>{t('RetentionPolicy_DoNotPruneThreads')}</FieldLabel>
+<FieldLabel htmlFor={retentionIgnoreThreadsField}>{t('RetentionPolicy_DoNotPruneThreads')}</FieldLabel>
...
-<ToggleSwitch id={retentionIgnoreThreads} {...field} checked={value} />
+<ToggleSwitch id={retentionIgnoreThreadsField} {...field} checked={value} />

Also applies to: 596-603

apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useChangeModeratorAction.tsx (1)

90-101: Use the derived flag in the handler for consistency (and add a return)

Minor polish: reuse roomIsFederated in handleChangeModerator and return the final mutation for uniform control-flow.

+ const roomIsFederated = isRoomFederated(room);
  const handleChangeModerator = useCallback(
    ({ userId }: { userId: string }) => {
-     if (!isRoomFederated(room)) {
-       return toggleModerator.mutateAsync({ roomId: rid, userId: uid });
+     if (!roomIsFederated) {
+       return toggleModerator.mutateAsync({ roomId: rid, userId: uid });
      }
@@
-     toggleModerator.mutateAsync({ roomId: rid, userId: uid });
+     return toggleModerator.mutateAsync({ roomId: rid, userId: uid });
    },
-   [setModal, loggedUserId, loggedUserIsModerator, loggedUserIsOwner, t, rid, uid, toggleModerator, room],
+   [setModal, loggedUserId, loggedUserIsModerator, loggedUserIsOwner, t, rid, uid, toggleModerator, roomIsFederated],
  );
-
- const roomIsFederated = isRoomFederated(room);

Also applies to: 139-141, 146-149

apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useAddUserAction.tsx (2)

66-74: Use the derived flag inside the action for consistency

Not functional, but keeps a single source of truth for the federated check.

-      if (isRoomFederated(room)) {
+      if (roomIsFederated) {
         addClickHandler.mutate({
           users,
           handleSave: handleAddUser,
         });
       } else {
         await handleAddUser({ users });
       }

58-61: Avoid shadowing username

Local const [username] = users; hides the outer username from props. Rename for clarity.

-  const [username] = users;
-  await inviteUser({ roomId: rid, username });
+  const [targetUsername] = users;
+  await inviteUser({ roomId: rid, username: targetUsername });
apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useChangeOwnerAction.tsx (1)

134-147: Use roomIsFederated in the handler and update deps

Align the handler with the new derived flag and drop room from deps to avoid unnecessary re-creations.

-const changeOwnerAction = useEffectEvent(async () => handleChangeOwner());
-
-const roomIsFederated = isRoomFederated(room);
+const roomIsFederated = isRoomFederated(room);
+const changeOwnerAction = useEffectEvent(async () => handleChangeOwner());
@@
-  if (!isRoomFederated(room)) {
+  if (!roomIsFederated) {
     return toggleOwnerMutation.mutateAsync({ roomId: rid, userId: uid });
   }
@@
-}, [room, loggedUserId, loggedUserIsOwner, toggleOwnerMutation, rid, uid, t, setModal]);
+}, [roomIsFederated, loggedUserId, loggedUserIsOwner, toggleOwnerMutation, rid, uid, t, setModal]);

Please confirm no other logic inside handleChangeOwner depends on the full room object; otherwise keep room in deps.

Also applies to: 89-101, 129-131

apps/meteor/client/views/admin/rooms/EditRoom.tsx (1)

274-293: Disable “React when read only” when federated to avoid a non-actionable control

Currently it’s always checked if federated but not disabled; users can click yet it won’t uncheck, which is confusing.

-  <ToggleSwitch
+  <ToggleSwitch
     id={reactWhenReadOnly}
     {...field}
-    checked={value || roomIsFederated}
+    checked={value || roomIsFederated}
+    disabled={roomIsFederated}
     aria-describedby={`${reactWhenReadOnly}-hint`}
   />
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a087f72 and cae29f6.

📒 Files selected for processing (7)
  • apps/meteor/client/views/admin/rooms/EditRoom.tsx (11 hunks)
  • apps/meteor/client/views/room/contextualBar/Info/EditRoomInfo/EditRoomInfo.tsx (1 hunks)
  • apps/meteor/client/views/room/contextualBar/RoomMembers/RoomMembersWithData.tsx (1 hunks)
  • apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useAddUserAction.tsx (1 hunks)
  • apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useChangeModeratorAction.tsx (1 hunks)
  • apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useChangeOwnerAction.tsx (1 hunks)
  • apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useRemoveUserAction.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (6)
apps/meteor/client/views/room/contextualBar/Info/EditRoomInfo/EditRoomInfo.tsx (1)
packages/core-typings/src/IRoom.ts (1)
  • isRoomFederated (109-109)
apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useRemoveUserAction.tsx (1)
packages/core-typings/src/IRoom.ts (1)
  • isRoomFederated (109-109)
apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useChangeOwnerAction.tsx (1)
packages/core-typings/src/IRoom.ts (1)
  • isRoomFederated (109-109)
apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useChangeModeratorAction.tsx (2)
packages/core-typings/src/IRoom.ts (1)
  • isRoomFederated (109-109)
apps/meteor/app/utils/lib/i18n.ts (1)
  • t (6-6)
apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useAddUserAction.tsx (1)
packages/core-typings/src/IRoom.ts (1)
  • isRoomFederated (109-109)
apps/meteor/client/views/admin/rooms/EditRoom.tsx (1)
packages/core-typings/src/IRoom.ts (1)
  • isRoomFederated (109-109)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: 🔎 Code Check / TypeScript
  • GitHub Check: 🔎 Code Check / Code Lint
  • GitHub Check: 🔨 Test Storybook / Test Storybook
  • GitHub Check: 🔨 Test Unit / Unit Tests
  • GitHub Check: 📦 Meteor Build - coverage
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🔇 Additional comments (6)
apps/meteor/client/views/room/contextualBar/Info/EditRoomInfo/EditRoomInfo.tsx (1)

82-82: Compute federated flag once per render — LGTM

Using a single isFederated per render simplifies conditions and avoids redundant calls.

apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useChangeModeratorAction.tsx (1)

146-161: Memo predicate switched to roomIsFederated — LGTM

Replacing inline checks with a derived roomIsFederated and updating deps is correct and reduces churn.

apps/meteor/client/views/room/contextualBar/RoomMembers/RoomMembersWithData.tsx (1)

79-81: Switch to useEffectEvent for handleBack — LGTM

Stable identity without stale closures; matches adjacent event handlers.

apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useAddUserAction.tsx (1)

47-53: Derived roomIsFederated for gating — LGTM

The ternary using roomIsFederated reads clearer and avoids re-evaluations.

apps/meteor/client/views/room/hooks/useUserInfoActions/actions/useRemoveUserAction.tsx (1)

44-49: Reuse derived flag for remove permissions — LGTM

roomIsFederated simplifies the userCanRemove branch; deps already include userCanRemove, so memo will refresh as needed.

Also applies to: 113-125

apps/meteor/client/views/admin/rooms/EditRoom.tsx (1)

138-150: Centralized federated gating across form — LGTM

Consolidating to roomIsFederated makes the conditions clearer and consistent.

Also applies to: 199-200, 213-214, 243-244, 265-265, 286-286, 303-303, 317-318, 342-342, 359-359

dougfabris
dougfabris previously approved these changes Sep 16, 2025
@dougfabris dougfabris dismissed stale reviews from tassoevan and themself via 6c43041 September 16, 2025 17:30
@ggazzo ggazzo merged commit 0786c86 into develop Sep 16, 2025
48 of 50 checks passed
@ggazzo ggazzo deleted the chore/fed branch September 16, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants