Skip to content
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

[Feature] System notifications with notification feature announcement #10570

Merged
merged 10 commits into from
Jun 17, 2024

Conversation

petertgiles
Copy link
Contributor

@petertgiles petertgiles commented May 31, 2024

πŸ€– Resolves #10220

πŸ‘‹ Introduction

This branch sets up a framework for creating one-time system notifications and also adds the first one - a notification feature announcement.

πŸ•΅οΈ Details

This is set up with a mostly-empty GCNotify template. A group of Laravel views with blade templates take the user object and fill in the required data to send to the GCNotify template. (Yo dawg, I heard you like templates...)

The idea is that for future system messages we can just commit some new views and run the existing command pointing at those.

πŸ§ͺ Testing

  1. Add the GNotify "team" API key and the new template IDs
  2. Start the queue worker in the webserver (see the new makefile shortcut)
  3. Set up a user with your whitelisted email address
  4. ./artisan send-notifications:system notification_announcement (myemailaddress)
    • Observe the email received
    • Observe the in-app notification
  5. ./artisan send-notifications:system notification_announcement
    • Observe that in-app notifications are sent to every user.
    • Observe that emails are queued for every user but most will fail since they are not whitelisted.

πŸ“Έ Screenshot

image

image

🚚 Deployment

New environment variables:
GCNOTIFY_TEMPLATE_SYSTEM_NOTIFICATION_EN=a4f234a4-34bd-4ccd-9ade-8c6e265e134e
GCNOTIFY_TEMPLATE_SYSTEM_NOTIFICATION_FR=f579056c-a183-4517-bfd5-32544131a545

@petertgiles petertgiles added blocked: copy Blocked by missing copy or translations deployment Requires a change during deployment labels May 31, 2024
@codecov-commenter
Copy link

codecov-commenter commented May 31, 2024

Codecov Report

Attention: Patch coverage is 0% with 89 lines in your changes missing coverage. Please review.

Project coverage is 37.98%. Comparing base (5253b77) to head (8ea72ee).
Report is 18 commits behind head on main.

Files Patch % Lines
...i/app/Console/Commands/SendNotificationsSystem.php 0.00% 54 Missing ⚠️
api/app/Notifications/System.php 0.00% 28 Missing ⚠️
apps/web/src/hooks/useNotificationInfo.ts 0.00% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #10570      +/-   ##
============================================
- Coverage     38.59%   37.98%   -0.62%     
- Complexity     1455     1467      +12     
============================================
  Files          1013     1015       +2     
  Lines         30899    30988      +89     
  Branches       6632     6621      -11     
============================================
- Hits          11926    11770     -156     
- Misses        18809    19183     +374     
+ Partials        164       35     -129     
Flag Coverage Ξ”
integrationtests 68.12% <0.00%> (-3.80%) ⬇️
unittests 31.24% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@petertgiles petertgiles removed the blocked: copy Blocked by missing copy or translations label Jun 3, 2024
@brindasasi brindasasi self-assigned this Jun 12, 2024
if (! is_null($singleEmailAddress)) {
// single email address provided
$recipientUsers = [
User::where('email', $singleEmailAddress)->sole(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this for testing purpose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, exactly. You can try sending yourself the email first, before sending it to every single user.

Copy link
Contributor

@brindasasi brindasasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the code level , this is looking great to me. Nice work. Just few questions on perf. consideration.
Will check it out in dev in a bit.


return Command::SUCCESS;
}
$recipientUsers = User::all()->all();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it include soft deleted users as well? Can we exclude them?
Also can we select only the necessary columns in the user object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To query deleted users you'd need to use the withTrashed scope.
https://laravel.com/docs/10.x/eloquent#querying-soft-deleted-models
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding selecting necessary columns, this command is supposed to be generic and used without modification for any templates we want to add. So, we don't really know what the necessary columns are. I'm not too worried about perf here since this is being run from the console. If it takes a few minutes to complete it shouldn't bother any users.

{
$locale = $this->locale ?? $notifiable->preferredLocale();

if ($locale == Language::EN->value) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bilingual notification could have been easier in this case. No need to check every user's preferred locale.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I remember talking about bilingual notifications for the talent search request notification. We did a bilingual one there because the user wasn't logged in but there was a strong preference for localized notifications when possible.

@brindasasi brindasasi removed their assignment Jun 12, 2024
Copy link
Contributor

@brindasasi brindasasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The email I received got (no subject) in the subject field . Please fix that.
Also it just spammed me 725 emails instead of a single email and crashed the dev.

image (11)

@petertgiles
Copy link
Contributor Author

OK, I think the problem in Azure was fixed with create cache directory.

I think that solved the problem with the rate limiter too. I intentionally broke it with intentionally break notifications and wasn't able to replicate the spamming.

Here it is, waiting 300 seconds before trying again:
image

Copy link
Contributor

@brindasasi brindasasi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great. I received the email as expected. Good to go! πŸ₯³

@petertgiles petertgiles added this pull request to the merge queue Jun 17, 2024
Merged via the queue into main with commit 88b8489 Jun 17, 2024
10 checks passed
@petertgiles petertgiles deleted the 10220-notification-notification branch June 17, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployment Requires a change during deployment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

❗ [Notification] New notification feature
3 participants