chore: remove Meteor user invocation from rest api #38017
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 |
|
WalkthroughRefactors APIClass to replace implicit Meteor context dependency with explicit parameters. Removes safeGetMeteorUser utility, introducing performedBy parameter passing throughout user creation flow. Adds applyMeteorContext option flag and new createMeteorInvocation static helper for conditional Meteor context handling in routes. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #38017 +/- ##
===========================================
- Coverage 70.78% 70.78% -0.01%
===========================================
Files 3159 3159
Lines 109388 109384 -4
Branches 19710 19674 -36
===========================================
- Hits 77429 77423 -6
- Misses 29928 29936 +8
+ Partials 2031 2025 -6
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
c2fea9d to
adde004
Compare
1432e63 to
617afd0
Compare
c0f1958 to
671e348
Compare
617afd0 to
34c0088
Compare
671e348 to
d531c0e
Compare
32d30db to
c203b32
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
apps/meteor/server/lib/rooms/roomTypes/direct.ts (1)
54-72: Markuidparameter as optional in the function signature to match the interface contract.The
roomNamemethod indirect.tsshould mark theuidparameter as optional (uid?) to match theIRoomTypeServerDirectivesinterface definition, which declaresuserId?: string. Currently, the signatureasync roomName(room, uid)doesn't reflect this, even though the implementation handles the undefined case with a fallback (picking any subscription). While the fallback behavior is intentional, the type signature should accurately reflect thatuidis optional.apps/meteor/app/lib/server/functions/saveUser/saveNewUser.ts (1)
15-30: Store only the minimal identifier for audit trail instead of the full user object.
Accounts.createUserAsyncwill persist theperformedByobject directly to the user document, which includes theservicesfield containing sensitive data (OAuth tokens, login tokens, password hashes, 2FA credentials). This risks PII leakage and unnecessarily bloats the user document. SinceperformedByis not queried from user records anywhere, it should store only essential audit information.Follow the codebase pattern (e.g.,
createdByin other domains) and persist a minimal identifier:Suggested fix
- performedBy, + performedBy: { _id: performedBy._id, username: performedBy.username, name: performedBy.name },
🤖 Fix all issues with AI agents
In `@apps/meteor/app/api/server/definition.ts`:
- Line 195: The readonly property twoFactorChecked is declared as a non-optional
boolean but not initialized; set a default (e.g. initialize twoFactorChecked =
false as a property initializer or assign this.twoFactorChecked = false inside
the class constructor) so the non-optional type cannot be undefined at runtime;
ensure you update the class that declares readonly twoFactorChecked accordingly
(initialize in the constructor if readonly must be set there).
In `@apps/meteor/app/authentication/server/startup/index.js`:
- Around line 380-385: The IPostUserCreated event is being called with
performedBy possibly undefined because many callers of Accounts.insertUserDoc
(e.g., SAML.ts, registerUser.ts, createNewUser.ts, UserConverter.ts) don't pass
performedBy; update the insertUserDoc call sites to accept and forward a
required performedBy (or derive a sensible default like the current user id or a
system user id) and ensure the startup code that triggers
Apps.self.triggerEvent(AppEvents.IPostUserCreated, { user, performedBy:
options.performedBy }) always supplies a non-undefined performedBy;
specifically, add performedBy to the insertUserDoc signature/parameters where
missing, propagate it through user creation flows, and/or set
options.performedBy to a default before calling Apps.self?.triggerEvent so
IPostUserCreated receives a valid actor identifier.
| readonly queryOperations: TOptions extends { queryOperations: infer T } ? T : never; | ||
| readonly queryFields: TOptions extends { queryFields: infer T } ? T : never; | ||
|
|
||
| readonly twoFactorChecked: boolean; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
rg -n "twoFactorChecked" -C3 apps/meteor/app/api/serverRepository: RocketChat/Rocket.Chat
Length of output: 1145
Initialize twoFactorChecked with a default boolean
Assign a default value (e.g. this.twoFactorChecked = false; in the class constructor or as a property initializer) so the non-optional type never yields undefined at runtime.
🤖 Prompt for AI Agents
In `@apps/meteor/app/api/server/definition.ts` at line 195, The readonly property
twoFactorChecked is declared as a non-optional boolean but not initialized; set
a default (e.g. initialize twoFactorChecked = false as a property initializer or
assign this.twoFactorChecked = false inside the class constructor) so the
non-optional type cannot be undefined at runtime; ensure you update the class
that declares readonly twoFactorChecked accordingly (initialize in the
constructor if readonly must be set there).
| if (!options.skipAppsEngineEvent) { | ||
| // `post` triggered events don't need to wait for the promise to resolve | ||
| Apps.self?.triggerEvent(AppEvents.IPostUserCreated, { user, performedBy: await safeGetMeteorUser() }).catch((e) => { | ||
| Apps.self?.triggerEvent(AppEvents.IPostUserCreated, { user, performedBy: options.performedBy }).catch((e) => { | ||
| Apps.self?.getRocketChatLogger().error({ msg: 'Error while executing post user created event', err: e }); | ||
| }); | ||
| } |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Search for calls to insertUserDoc and inspect arguments
rg -nP --type=ts --type=js -C3 'insertUserDoc\s*\(' | head -100Repository: RocketChat/Rocket.Chat
Length of output: 3583
🏁 Script executed:
sed -n '350,430p' apps/meteor/app/authentication/server/startup/index.jsRepository: RocketChat/Rocket.Chat
Length of output: 2581
Ensure performedBy is passed to IPostUserCreated event.
Several Accounts.insertUserDoc call sites (e.g. SAML.ts, registerUser.ts, createNewUser.ts, UserConverter.ts) invoke insertUserDoc({…}, user) without supplying performedBy, causing the IPostUserCreated event to receive undefined. Require callers to include a valid performedBy or provide a sensible default before triggering the event.
🤖 Prompt for AI Agents
In `@apps/meteor/app/authentication/server/startup/index.js` around lines 380 -
385, The IPostUserCreated event is being called with performedBy possibly
undefined because many callers of Accounts.insertUserDoc (e.g., SAML.ts,
registerUser.ts, createNewUser.ts, UserConverter.ts) don't pass performedBy;
update the insertUserDoc call sites to accept and forward a required performedBy
(or derive a sensible default like the current user id or a system user id) and
ensure the startup code that triggers
Apps.self.triggerEvent(AppEvents.IPostUserCreated, { user, performedBy:
options.performedBy }) always supplies a non-undefined performedBy;
specifically, add performedBy to the insertUserDoc signature/parameters where
missing, propagate it through user creation flows, and/or set
options.performedBy to a default before calling Apps.self?.triggerEvent so
IPostUserCreated receives a valid actor identifier.
| token?: string, | ||
| ) { | ||
| const invocation = new DDPCommon.MethodInvocation({ | ||
| connection, |
There was a problem hiding this comment.
not totally sure, so maybe worth it for another PR, but I think we can generate the connection only on this context, so we could remove it from:
Rocket.Chat/apps/meteor/app/api/server/ApiClass.ts
Lines 861 to 862 in cc112ef
…Invocation utility
… invocation handling for improved context management
… invocation handling for improved context management
…ext handling in saveUser methods for improved clarity and type safety
c203b32 to
468ab81
Compare
rocketchat.atlassian.net/browse/ARCH-1654
Proposed changes (including videos or screenshots)
Issue(s)
Steps to test or reproduce
Further comments
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.