-
Notifications
You must be signed in to change notification settings - Fork 19
Bulk-Update issue Fix #840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bulk-Update issue Fix #840
Conversation
WalkthroughAdds transformUser usage, conditional user fetching, metadata parsing/merging, and decryption of sensitive fields in Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller as Invoker
participant U as userInvite helper
participant DB as User DB
participant Utils as utils.parseMetaData
participant Crypt as Decryptor
participant Emitter as EventEmitter
participant Subs as Subscribers
Caller->>U: invoke invite/update flow
alt needs consolidated user data (org/role/meta/CSV)
U->>DB: fetch existing user with orgs -> userFetch
else reuse existing user data
note right of U: use existingUser.dataValues
end
U->>U: oldValues <- transformUser(existingUser.dataValues)
U->>Utils: parse meta -> userMeta
U->>U: merge userMeta into oldValues (delete raw meta)
U->>Crypt: decrypt oldValues.email / oldValues.phone (if present)
U->>U: build newValues from modified keys (special meta handling)
U->>Emitter: emit({ eventType, entityId, args: { oldValues, newValues, phone_code, email } })
Emitter-->>Subs: dispatch enriched event
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ 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 |
…o event-update-tenant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/helpers/userInvite.js(3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-12T11:02:51.008Z
Learnt from: praveenKDass
PR: ELEVATE-Project/user#816
File: src/dtos/organizationDTO.js:14-43
Timestamp: 2025-09-12T11:02:51.008Z
Learning: In the ELEVATE-Project/user codebase, oldValue and newValue in the changedValues array for organizationDTO.eventBodyDTO are guaranteed to not be undefined by the business logic, and filtering out falsy values (0, false, '') from changes is the intended behavior.
Applied to files:
src/helpers/userInvite.js
🧬 Code graph analysis (1)
src/helpers/userInvite.js (2)
src/services/user.js (10)
modifiedKeys(129-133)userQueries(11-11)user(48-51)user(319-319)user(440-440)user(490-490)user(525-525)oldValues(164-165)userMeta(163-163)emailEncryption(21-21)src/database/queries/users.js (1)
emailEncryption(6-6)
🔇 Additional comments (2)
src/helpers/userInvite.js (2)
1142-1144: LGTM: Good defensive null guards for event payload.The null guards for
phone_codeensure consistent, well-defined event payload structure and prevent downstream issues with undefined values.
844-856: Conditional fetch consolidation is safe and covers all uses. Verified that every reference touserFetchandexistingUser.organizationsoccurs within the branches guarded by the same conditions.
|
@CodeRabbit summary |
✅ Actions performedSummary regeneration triggered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (1)
src/helpers/userInvite.js (1)
902-907: Fix decryption logic to prevent false positive event emissions.The ternary operator still creates
phoneproperties onoldValueseven when they don't exist (assigningundefined). This was flagged in a previous review but remains unfixed.This causes
Object.keys(oldValues).lengthat line 908 to be non-zero even when there are no actual changes, potentially emitting spurious events.Apply this diff to decrypt only existing properties:
- if (oldValues?.email) { - oldValues.email = emailEncryption.decrypt(oldValues.email) - } - if (oldValues?.phone) { - oldValues.phone = emailEncryption.decrypt(oldValues.phone) - } + if (oldValues.email) { + oldValues.email = emailEncryption.decrypt(oldValues.email) + } + if (oldValues.phone) { + oldValues.phone = emailEncryption.decrypt(oldValues.phone) + }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/helpers/userInvite.js(4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/helpers/userInvite.js (1)
src/services/user.js (19)
require(17-17)require(19-19)require(20-20)require(24-24)require(26-26)modifiedKeys(129-133)_(18-18)oldValues(164-165)userQueries(11-11)user(48-51)user(319-319)user(440-440)user(490-490)user(525-525)utils(12-12)prunedEntities(72-72)prunedEntities(361-361)prunedEntities(466-466)prunedEntities(544-544)
🔇 Additional comments (5)
src/helpers/userInvite.js (5)
27-27: LGTM!The addition of
transformUserto the imports is appropriate and aligns with its usage at line 840 for transforming previous data values.
830-837: LGTM!The modified keys computation correctly identifies changed fields by comparing current and previous data values, and appropriately filters out sensitive fields using
keysFilter.
1119-1121: LGTM!The null-safe assignments for
phone_codeproperly handle missing values by explicitly assigningnullinstead ofundefined, which is good practice for event payloads.
839-853: ThetransformUserimplementation is safe for handling old state.I've verified that
transformUser(imported from@dtos/userDTO.js) is a static method that explicitly maps specific user fields (id, email, name, username, phone, status, image, timestamps, organizations, etc.) from the input object. When called onuserUpdate[0]?._previousDataValues, it correctly extracts these fields from the previous state without inadvertently including new state. The selective field mapping appears intentional for DTO consistency and should work properly for change tracking purposes.The conditional fetching logic on lines 842-852 is complex but appears necessary to optimize database queries based on whether critical fields were modified. Consider documenting the purpose of each condition to aid maintainability.
856-859: No action required:userFetchis fetched for organization/role updates The ternary at line 842 includesisOrgUpdate || isRoleUpdated, souserFetchis always populated (and unwrapped) before assigningnewValues.organizations.Likely an incorrect or invalid review comment.
Summary by CodeRabbit
Chores
Bug Fixes