chore: migrate roles.sync endpoint to chained API pattern with AJV validation#39196
chore: migrate roles.sync endpoint to chained API pattern with AJV validation#39196NAME-ASHWANIYADAV wants to merge 3 commits intoRocketChat:developfrom
roles.sync endpoint to chained API pattern with AJV validation#39196Conversation
|
|
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 infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
📜 Recent review details⏰ 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). (1)
🧰 Additional context used📓 Path-based instructions (1)**/*.{ts,tsx,js}📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
Files:
🧠 Learnings (9)📓 Common learnings📚 Learning: 2026-02-24T19:09:01.522ZApplied to files:
📚 Learning: 2026-02-25T20:10:16.987ZApplied to files:
📚 Learning: 2026-01-17T01:51:47.764ZApplied to files:
📚 Learning: 2026-01-26T18:26:01.279ZApplied to files:
📚 Learning: 2025-11-04T16:49:19.107ZApplied to files:
📚 Learning: 2026-02-23T17:53:06.802ZApplied to files:
📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
📚 Learning: 2026-02-26T19:25:44.063ZApplied to files:
🧬 Code graph analysis (1)apps/meteor/app/api/server/v1/roles.ts (3)
🔇 Additional comments (2)
WalkthroughReplaced the standalone Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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/app/api/server/v1/roles.ts (1)
251-264: Tightenroles.syncremoveresponse typing/schema.
remove: object[]plusitems: { type: 'object' }is too permissive and dilutes the response contract for generated typings.💡 Suggested direction
roles: { update: IRole[]; - remove: object[]; + remove: { _id: string }[]; }; }>({ @@ update: { type: 'array', items: { type: 'object' } }, - remove: { type: 'array', items: { type: 'object' } }, + remove: { + type: 'array', + items: { + type: 'object', + properties: { _id: { type: 'string' } }, + required: ['_id'], + additionalProperties: true, + }, + }, }, required: ['update', 'remove'], },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/meteor/app/api/server/v1/roles.ts` around lines 251 - 264, Tighten the permissive remove typing by replacing the generic object[] with a concrete shape: update the ajv.compile generic to { roles: { update: IRole[]; remove: { _id: string }[] } } (or your actual removed-role identifier field) and replace the schema for remove under roles with an array item schema that defines the expected properties (e.g., items: { type: "object", properties: { _id: { type: "string" } }, required: ["_id"] }). Update any other places that rely on the old remove shape to use the new { _id: string }[] type; locate the change at the ajv.compile call and the nested roles -> remove schema in roles.ts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/meteor/app/api/server/v1/roles.ts`:
- Around line 240-245: The schema for the query compiled with ajv.compile<{
updatedSince: string }> should enforce an RFC3339 datetime: add "format":
"date-time" to the updatedSince property and recompile the schema; additionally,
after parsing the string into a Date in the request handler (the code that
currently does new Date(updatedSince)), add the same runtime validation pattern
used by validateDateParam in emoji-custom.ts — i.e. check isNaN(date.getTime())
and return/throw a clear bad-request error if invalid — and apply the same
schema+runtime validation for the second occurrence around the block at lines
referenced 273-279 (the other updatedSince handler).
---
Nitpick comments:
In `@apps/meteor/app/api/server/v1/roles.ts`:
- Around line 251-264: Tighten the permissive remove typing by replacing the
generic object[] with a concrete shape: update the ajv.compile generic to {
roles: { update: IRole[]; remove: { _id: string }[] } } (or your actual
removed-role identifier field) and replace the schema for remove under roles
with an array item schema that defines the expected properties (e.g., items: {
type: "object", properties: { _id: { type: "string" } }, required: ["_id"] }).
Update any other places that rely on the old remove shape to use the new { _id:
string }[] type; locate the change at the ajv.compile call and the nested roles
-> remove schema in roles.ts.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/meteor/app/api/server/v1/roles.tspackages/rest-typings/src/v1/roles.ts
📜 Review details
⏰ 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). (1)
- GitHub Check: cubic · AI code reviewer
🧰 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:
packages/rest-typings/src/v1/roles.tsapps/meteor/app/api/server/v1/roles.ts
🧠 Learnings (8)
📓 Common learnings
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
📚 Learning: 2026-02-24T19:09:09.561Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:09.561Z
Learning: In RocketChat/Rocket.Chat OpenAPI migration PRs for apps/meteor/app/api/server/v1 endpoints, maintainers prefer to avoid any logic changes; style-only cleanups (like removing inline comments) may be deferred to follow-ups to keep scope tight.
Applied to files:
packages/rest-typings/src/v1/roles.ts
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.
Applied to files:
packages/rest-typings/src/v1/roles.tsapps/meteor/app/api/server/v1/roles.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:
packages/rest-typings/src/v1/roles.tsapps/meteor/app/api/server/v1/roles.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:
packages/rest-typings/src/v1/roles.tsapps/meteor/app/api/server/v1/roles.ts
📚 Learning: 2026-02-24T19:09:01.522Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38974
File: apps/meteor/app/api/server/v1/im.ts:220-221
Timestamp: 2026-02-24T19:09:01.522Z
Learning: In Rocket.Chat OpenAPI migration PRs for endpoints under apps/meteor/app/api/server/v1, avoid introducing logic changes. Only perform scope-tight changes that preserve behavior; style-only cleanups (e.g., removing inline comments) may be deferred to follow-ups to keep the migration PR focused.
Applied to files:
apps/meteor/app/api/server/v1/roles.ts
📚 Learning: 2025-11-04T16:49:19.107Z
Learnt from: ricardogarim
Repo: RocketChat/Rocket.Chat PR: 37377
File: apps/meteor/ee/server/hooks/federation/index.ts:86-88
Timestamp: 2025-11-04T16:49:19.107Z
Learning: In Rocket.Chat's federation system (apps/meteor/ee/server/hooks/federation/), permission checks follow two distinct patterns: (1) User-initiated federation actions (creating rooms, adding users to federated rooms, joining from invites) should throw MeteorError to inform users they lack 'access-federation' permission. (2) Remote server-initiated federation events should silently skip/ignore when users lack permission. The beforeAddUserToRoom hook only executes for local user-initiated actions, so throwing an error there is correct. Remote federation events are handled separately by the federation Matrix package with silent skipping logic.
Applied to files:
apps/meteor/app/api/server/v1/roles.ts
📚 Learning: 2026-02-23T17:53:06.802Z
Learnt from: ggazzo
Repo: RocketChat/Rocket.Chat PR: 35995
File: apps/meteor/app/api/server/v1/rooms.ts:1107-1112
Timestamp: 2026-02-23T17:53:06.802Z
Learning: During PR reviews that touch endpoint files under apps/meteor/app/api/server/v1, enforce strict scope: if a PR targets a specific endpoint (e.g., rooms.favorite), do not propose changes to unrelated endpoints (e.g., rooms.invite) unless maintainers explicitly request them. Focus feedback on the touched endpoint's behavior, API surface, and related tests; avoid broad cross-endpoint changes in the same PR unless requested.
Applied to files:
apps/meteor/app/api/server/v1/roles.ts
🧬 Code graph analysis (1)
apps/meteor/app/api/server/v1/roles.ts (6)
apps/meteor/app/api/server/index.ts (1)
API(51-51)packages/apps/src/AppsEngine.ts (1)
IRole(15-15)packages/models/src/index.ts (1)
Roles(180-180)packages/rest-typings/src/v1/roles.ts (1)
RolesEndpoints(116-145)apps/meteor/app/api/server/ApiClass.ts (1)
ExtractRoutesFromAPI(74-78)packages/rest-typings/src/index.ts (1)
Endpoints(48-93)
🔇 Additional comments (2)
apps/meteor/app/api/server/v1/roles.ts (1)
204-235: Good scoped migration to chained route registration.The
roles.getUsersInPublicRolesmove to chained.get()with response validation is clean and keeps behavior-focused scope.packages/rest-typings/src/v1/roles.ts (1)
116-145: The removal of/v1/roles.syncfromRolesEndpointsis clean; no remaining references to this endpoint exist in the codebase.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #39196 +/- ##
===========================================
- Coverage 70.76% 70.69% -0.07%
===========================================
Files 3195 3195
Lines 113106 113106
Branches 20522 20517 -5
===========================================
- Hits 80041 79962 -79
- Misses 31018 31100 +82
+ Partials 2047 2044 -3
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
please @NAME-ASHWANIYADAV run lint/typecheck locally before pushing the changes |
|
Hi @ggazzo, lint issues are fixed and CI is green. Could you please review and merge when you get a chance? 🙏 |
Closes #39195
Changes
roles.syncGET endpoint from legacyAPI.v1.addRouteto the new chained.get()API patterncheck/Matchinput validation with AJV schema validation for theupdatedSincequery parameter200response (roles.updateandroles.removearrays)RoleSyncPropstype and'/v1/roles.sync'endpoint definition fromrest-typings(now auto-inferred via ExtractRoutesFromAPI)check/Matchimports frommeteor/checkFiles Changed
No behavioral changes
The endpoint logic remains identical — only the validation and registration pattern has been updated.
Related project
This continues the REST API migration effort described in the GSoC 2026 project: Replace old REST API definitions over the new API.
cc @diego-sampaio @ggazzo
Summary by CodeRabbit
Refactor
Bug Fixes
Chores