chore(api): migrate groups.ts to typed HTTP methods - #41422
Conversation
|
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 |
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (5)
WalkthroughPrivate-group management endpoints were migrated from legacy route handlers to schema-driven ChangesPrivate group API
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
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 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #41422 +/- ##
========================================
Coverage 68.73% 68.73%
========================================
Files 4151 4151
Lines 159516 159513 -3
Branches 27957 27978 +21
========================================
+ Hits 109646 109648 +2
Misses 44687 44687
+ Partials 5183 5178 -5
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
🤝 Handoff — continuing in a fresh sessionState: groups.ts is the mirror of channels.ts (#41415) — follow the detailed handoff on #41415 for all conventions/pitfalls (throw→500 + try/catch + Groups specifics: responses use Remaining (16)GET: info, list, listAll, members, moderators, online, counters, roles, getIntegrations, files · IMessage (relax): messages, history · POST: create, delete, invite, convertToTeam ( All mechanical POST actions + setters + role-ops are done; remaining is GET return-schema authoring + IMessage relax + create/convertToTeam. |
|
/jira ARCH-1464 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
apps/meteor/server/api/v1/groups.ts (2)
151-158: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueNit:
ajv.compile<void>and the inline comment.The 200 payload is
{ success: true }, notvoid; considerajv.compile<{ success: boolean }>for accurate typing. Also drop the explanatory comment on Line 158 — the helper name already conveys it.As per coding guidelines: "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/server/api/v1/groups.ts` around lines 151 - 158, Update successResponseSchema to compile against { success: boolean } instead of void, matching the actual { success: true } response payload, and remove the explanatory inline body-validator comment beneath it.Source: Coding guidelines
228-228: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winExtract the repeated body type literal.
The same
{ roomId?: string; roomName?: string; userId?: string; username?: string; user?: string }literal is repeated at Lines 228, 253, 278, 727, 1026, 1051, 1076. A singletype RoomUserBody = ...(or makingroomUserBodyreturn that type by default) removes the duplication.Also applies to: 253-253, 278-278
🤖 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/server/api/v1/groups.ts` at line 228, Extract the repeated optional room/user fields into a shared RoomUserBody type near the existing body definitions, then reuse it at the body declarations currently using the inline literal, including the occurrences around lines 228, 253, 278, 727, 1026, 1051, and 1076. Preserve the existing optional fields and roomUserBody behavior while removing the duplicated type literals.
🤖 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/server/api/v1/groups.ts`:
- Around line 194-210: Update the activeUsersOnly coercion in the action using
findPrivateGroupByIdOrName and addAllUserToRoomFn to recognize boolean true,
string "true" or "1", and numeric 1 as enabled. Preserve false behavior for
other accepted values so only active users are selected when any supported
truthy representation is provided.
---
Nitpick comments:
In `@apps/meteor/server/api/v1/groups.ts`:
- Around line 151-158: Update successResponseSchema to compile against {
success: boolean } instead of void, matching the actual { success: true }
response payload, and remove the explanatory inline body-validator comment
beneath it.
- Line 228: Extract the repeated optional room/user fields into a shared
RoomUserBody type near the existing body definitions, then reuse it at the body
declarations currently using the inline literal, including the occurrences
around lines 228, 253, 278, 727, 1026, 1051, and 1076. Preserve the existing
optional fields and roomUserBody behavior while removing the duplicated type
literals.
🪄 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 Plus
Run ID: 6098601c-a0aa-4597-a70b-73eb0e7fd76f
📒 Files selected for processing (2)
apps/meteor/server/api/v1/groups.tsapps/meteor/tests/end-to-end/api/groups.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Hacktron Security Check
🧰 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/tests/end-to-end/api/groups.tsapps/meteor/server/api/v1/groups.ts
🧠 Learnings (3)
📚 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/tests/end-to-end/api/groups.tsapps/meteor/server/api/v1/groups.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/tests/end-to-end/api/groups.tsapps/meteor/server/api/v1/groups.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/tests/end-to-end/api/groups.tsapps/meteor/server/api/v1/groups.ts
🔇 Additional comments (8)
apps/meteor/server/api/v1/groups.ts (7)
11-18: LGTM!Also applies to: 116-116
299-346: LGTM!
723-772: LGTM!
994-1095: LGTM!
1097-1362: LGTM!
1408-1437: LGTM!
159-170: 🗄️ Data Integrity & IntegrationNo action needed.
apps/meteor/tests/end-to-end/api/groups.ts (1)
2574-2574: LGTM!
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
WIP migrating groups.ts (mirror of channels.ts) from addRoute to typed API.v1 (moderation pattern — keep manual GroupsEndpoints entry, no augment). Batch 1: addAll, addModerator, addOwner, addLeader, archive, close. - Shared groupResponseSchema ($ref IRoom) + successResponseSchema. - Inline ajv body validators (roomTargetBody / roomUserBody) since these endpoints had no validateParams. - getRoomFromParams/findPrivateGroupByIdOrName throw Meteor.Error; the typed router does not map throws to 400, so handlers catch and return API.v1.failure (errorToFailureArgs extracts message/errorType by shape for core-services errors).
…rypted + role-removes (batch 2)
Migrate open, kick, leave, unarchive, rename, setEncrypted and remove{Moderator,
Owner,Leader}. Same pattern as channels: inline ajv body validators, group
response via $ref IRoom, findPrivateGroupByIdOrName throws caught -> failure.
Migrate setCustomFields, setReadOnly, setType (->group) and setDescription,
setPurpose, setTopic, setAnnouncement (->{field}). Inline ajv body validators.
…ranches, enforce room target, fix projection
…boolean param The dead 'bodyParam encrypted is required' branch was removed (schema already marks encrypted required+boolean); a non-boolean value now fails AJV body validation with 'must be boolean'. Update the assertion accordingly.
…et in groups - addAll: accept boolean true for activeUsersOnly (schema allows boolean|string|number) - roomTargetBody: anyOf -> oneOf so exactly one of roomId/roomName is required
b486517 to
492b87c
Compare
Proposed changes
Continues the API endpoint migration (
docs/api-endpoint-migration.md): migratesapps/meteor/server/api/v1/groups.ts(mirror ofchannels.ts, see #41415) from legacyAPI.v1.addRoute()to the typedAPI.v1.get/postpattern with AJV request/response validation.WIP / incremental.
groups.*endpoints are already declared inGroupsEndpoints(rest-typings), so this follows the moderation pattern: convert the registration and add response schemas, keeping the manualEndpointsentry (no augmentation).Migrated so far
groups.addAll,groups.addModerator,groups.addOwner,groups.addLeader,groups.archive,groups.closeNotes
groupResponseSchema($ref IRoom) +successResponseSchema.validateParams, so inlineajvbody validators are used (roomTargetBody/roomUserBody), matching the inline-validator style in rooms.ts/users.ts.getRoomFromParams/findPrivateGroupByIdOrNameand the room methods throwMeteor.Error; the typed router does not convert throws to 400, so each handler catches and returnsAPI.v1.failure(message, errorType). Errors from core-services are notinstanceof Meteor.Error, so message/errorType are extracted by shape.groups.*endpoints follow in subsequent batches;messages/history/filesreturnIMessage(attachmentoneOfvalidation limitation).Testing
tsc --noEmit, eslint and prettier clean for the migrated file.TEST_MODE; the e2egroupssuite exercises them.Task: ARCH-2316
Summary by CodeRabbit
encryptedto be a boolean)./groups.setEncryptedend-to-end test to match the new validation error message.