Ks 024 sep 23 email notification 1959#2214
Conversation
- Introduced `sendUserAddedAdminNotification` service to notify users when added as project admins. - Added new MJML email template `user-added-admin.mjml` for notification styling. - Integrated the service into `updateProjectById` to trigger notifications on project owner changes. - Adjusted `projectCreationNotification` path for consistency.
WalkthroughAdds a new "user added as project admin" notification service and MJML template, updates the project controller to detect owner changes and fire the notification (non-blocking with error logging), adjusts several import paths, and makes a minor import formatting change in the UI. No other behavior changes reported. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Client
participant Controller as project.ctrl.updateProjectById
participant DB as Project Store
participant Notify as sendUserAddedAdminNotification
Note over Controller: Update project flow with owner-change detection
Client->>Controller: PUT /projects/:id { ownerId, ... }
Controller->>DB: getProjectById(id)
DB-->>Controller: currentProject
Controller->>DB: updateProjectById(id, payload)
DB-->>Controller: updatedProject
alt owner changed
Note over Controller,Notify: Fire-and-forget notification (non-blocking)
Controller--)Notify: sendUserAddedAdminNotification({ projectId, projectName, adminId, userId })
Note right of Notify: Fetch admin/user → validate email → build project URL → send templated email → log outcome
else no change
Note over Controller: Skip notification
end
Controller-->>Client: 200 OK updatedProject
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (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 |
# Conflicts: # Clients/src/presentation/pages/Framework/index.tsx
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (5)
Servers/services/userNotification/userAddedAdminNotification.ts (2)
31-35: Consider graceful fallback for missing actor name.
If adminUser.name is null/empty, render a generic actor label to avoid a blank in the email body.Apply this minimal guard:
- actor_name: adminUser.name, + actor_name: adminUser.name || 'an administrator',
66-71: Avoid logging full email addresses (PII) in success logs.
Mask or log userId instead to reduce PII in logs.Apply this diff to mask the email:
- await logSuccess({ - eventType: "Update", - description: `Added as Admin notification sent to ${user.email}`, + const masked = user.email.replace(/(.).+(@.*)/, '$1***$2'); + await logSuccess({ + eventType: "Update", + description: `Added as Admin notification sent to ${masked}`, functionName: "sendUserAddedAdminNotification", fileName: "userAddedAdminNotification.ts", });Servers/templates/user-added-admin.mjml (1)
14-23: Nice template; add preview text and use mj-button for better email client support.
Improves inbox preview and button rendering across clients.Apply this diff:
<mj-head> + <mj-preview>You are now a project admin for {{project_name}}</mj-preview> @@ - <p style="margin: 20px 0;"> - <a href="{{project_url}}" style="background-color: #3498db; color: white; padding: 12px 24px; text-decoration: none; border-radius: 4px; display: inline-block;">Open project</a> - </p> + <mj-button href="{{project_url}}" background-color="#3498db" color="#ffffff" font-weight="500" border-radius="4px" padding="20px 0"> + Open project + </mj-button>Optional: add a plaintext fallback link below the button for strict clients.
Servers/services/projectNotification/projectCreationNotification.ts (1)
59-64: Reduce PII in logs by masking admin email.
Align logging hygiene with other services.- await logSuccess({ - eventType: "Create", - description: `Project creation notification sent to ${adminUser.email}`, + const masked = adminUser.email.replace(/(.).+(@.*)/, '$1***$2'); + await logSuccess({ + eventType: "Create", + description: `Project creation notification sent to ${masked}`, functionName: "sendProjectCreatedNotification", fileName: "projectCreationNotification.ts", });Servers/controllers/project.ctrl.ts (1)
254-257: ownerChanged may be non-boolean; coerce explicitly.
Current expression can be null when currentProject is null. Coerce to boolean for clarity.- const ownerChanged = currentProject && currentProject.owner !== updatedProject.owner; + const ownerChanged = !!(currentProject && currentProject.owner !== updatedProject.owner);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
Clients/src/presentation/containers/Dashboard/index.tsx(1 hunks)Servers/controllers/project.ctrl.ts(3 hunks)Servers/services/projectNotification/projectCreationNotification.ts(1 hunks)Servers/services/userNotification/userAddedAdminNotification.ts(1 hunks)Servers/templates/user-added-admin.mjml(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
Servers/services/userNotification/userAddedAdminNotification.ts (3)
Servers/utils/logger/logHelper.ts (3)
logProcessing(22-30)logSuccess(33-49)logFailure(51-68)Servers/utils/user.utils.ts (1)
getUserByIdQuery(137-144)Servers/services/notificationService.ts (1)
notificationService(110-110)
Servers/controllers/project.ctrl.ts (3)
Servers/utils/project.utils.ts (1)
getProjectByIdQuery(114-159)Servers/services/userNotification/userAddedAdminNotification.ts (1)
sendUserAddedAdminNotification(19-84)Servers/utils/logger/logHelper.ts (1)
logFailure(51-68)
🔇 Additional comments (3)
Servers/services/userNotification/userAddedAdminNotification.ts (1)
19-27: Good: non-blocking, structured logging before send.
Pattern matches existing notification flows and keeps the response path clean.Servers/services/projectNotification/projectCreationNotification.ts (1)
1-3: Import path adjustments look correct.
Paths resolve one/two levels up as expected from services/projectNotification.Clients/src/presentation/containers/Dashboard/index.tsx (1)
6-7: Import path and VerifyWiseContext export are correct. No changes needed.
…n` to reference the actor making changes
…n emails - Updated `user-added-admin.mjml` and `project-created-admin.mjml` templates to set body width to 100% and standardize section padding for consistent styling.
MuhammadKhalilzadeh
left a comment
There was a problem hiding this comment.
Thank you @solan117
Describe your changes
feat(notifications): add user-added-as-admin notification flow
sendUserAddedAdminNotificationservice to notify users when added as project admins.user-added-admin.mjmlfor notification styling.updateProjectByIdto trigger notifications on project owner changes.projectCreationNotificationpath for consistency.Write your issue number after "Fixes "
Fixes #1959
Please ensure all items are checked off before requesting a review: