-
-
Notifications
You must be signed in to change notification settings - Fork 40
Sohail and Anthony - BLUE SQUARE EMAIL AUTOMATION #1788
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
Sohail and Anthony - BLUE SQUARE EMAIL AUTOMATION #1788
Conversation
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.
Pull request overview
This PR implements automated blue square email notifications with intelligent email threading to reduce inbox clutter. The system groups weekly reminder emails into single conversation threads using RFC-compliant Message-ID headers and introduces safe testing infrastructure to prevent accidental production emails.
Key Changes:
- Email threading system using
EmailThreadandEmailHistorymodels with RFC-compliant headers - Four new automated email functions for different blue square scenarios (time not met, missed summary, incomplete hours, weekly reminders)
- Parameterized testing infrastructure via
testEmailJobs.jsto safely test email functions without spamming production users - Updated cron schedule to run blue square checks at 4 AM PST on Sundays, after time-logging completion
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 26 comments.
Show a summary per file
| File | Description |
|---|---|
src/utilities/timeUtils.js |
Enhanced timezone consistency by explicitly using Pacific time for all date formatting functions |
src/utilities/emailSender.js |
Implemented email threading with Message-ID generation, thread tracking via EmailThread model, and promise-based queue processing |
src/utilities/__tests__/timeUtils.test.js |
Added comprehensive unit tests for time utility functions |
src/utilities/__tests__/objectUtils.test.js |
Added unit tests for object manipulation utilities |
src/scripts/testEmailJobs.js |
Created testing script with safety checks to test email functions without affecting production users |
src/models/emailThread.js |
New model to track email thread roots by user and week for proper conversation threading |
src/models/emailHistory.js |
Extended with threading fields (messageId, threadRootMessageId, references) and metadata for RFC compliance |
src/models/emailModels.spec.js |
Comprehensive validation tests for EmailThread and EmailHistory schemas |
src/helpers/userHelper.js |
Refactored blue square functions to support testing parameters and added three new email automation functions |
src/helpers/__tests__/getInfringementEmailBody.test.js |
Unit tests for infringement email body generation logic |
src/cronjobs/userProfileJobs.js |
Added new cron job at 4 AM PST for summary-related emails and updated existing job schedule |
Comments suppressed due to low confidence (2)
src/helpers/userHelper.js:1359
- Unused variable numMonthsOriginal.
const numMonthsOriginal = currentMonthStart.diff(startOfMonth, 'months');
src/helpers/userHelper.js:1498
- Unused variable numMonthsOriginal.
const numMonthsOriginal = currentMonthStart.diff(startOfMonth, 'months');
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Tested all functions and they work as expected.
Anusha-Gali
left a comment
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.
Backend Release to Main [2.80]
Backend Release to Main [2.81]
|
Thank you all, merging! |











Description
Continues off of PR#1104 and PR#1334
Task: (PRIORITY HIGH) Jae: New Email function: Auto-reply for people who just forgot their summary on HGN Phase I Bugs and Needed Functionalities
Related PRs:
No frontend PR needed.
Main changes explained:
1. Robust Email Threading
emailSender.js.recipientUserIdandweekStart. The system checks for an existing thread in theEmailThreadcollection.In-Reply-ToandReferencesheaders), significantly reducing inbox clutter for users and admins.2. Safe & Parameterized Testing
src/scripts/testEmailJobs.jsfor safe, isolated testing.userHelper.js, the functions now accept an optionalemailConfigobject.{ targetUserId, emailOverride, ccOverride, bccOverride }. The system guarantees 0 emails go to production users or lists when this mode is active.3. Automated Email Functions (
userHelper.js)We significantly refactored/created these 4 functions to support the new features:
assignBlueSquareForTimeNotMet: Checks if a user failed to meet their weekly committed hours. If so, assigns a blue square and sends a notification.completeHoursAndMissedSummary: Identifies users who met their hours but forgot to submit their weekly summary, sending a specific reminder to "Reply All".inCompleteHoursEmailFunction: detailed checks for users who are partially complete (e.g., <85% or <65% of hours), sending tailored warnings based on how much they missed.weeklyBlueSquareReminderFunction: audits the user's total blue squares (e.g., "2 in 2 months" or "4th Blue Square"), alerting them if they are close to the 5-strike limit.4. Database Collection Updates
To enable the threading logic, we utilized
EmailThreadand optimizedEmailHistory:EmailThreadCollection: Stores distinct conversation threads keyed byrecipientUserId+weekStart. This allows us to look up thethreadRootMessageIdfor any given week.EmailHistoryCollection: Updated to store RFC-compliant threading headers (Message-ID,In-Reply-To,References). This safeguards our ability to debug email chains if providers (Gmail/Outlook) behave unexpectedly.5. Cron Job Updates (
userProfileJobs.js)How to test:
We have introduced a dedicated test script so you do NOT need to modify the code to test it.
git checkout <branch-name>src/scripts/testEmailJobs.jsand update the constants at the top:threadRootMessageIdandweekStartfields in 'emailThreads' to uniquely filter entries in the 'emailHistory' collection.Safety Features Implemented:
Note:
The expected flow of executions in prod is something like this:
assignBlueSquareForTimeNotMetwill run at the start of every week, i.e. Sunday 12 AM PST.completeHoursAndMissedSummary,inCompleteHoursEmailFunction, andweeklyBlueSquareReminderFunctionwill run 4 hours later. i.e. Sunday 4 am PST.Important
assignBlueSquareForTimeNotMetandcompleteHoursAndMissedSummary. You can uncomment other function calls in src/scripts/testEmailJobs.js to test them individually.