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

[TM-1423] add conditional to skip recipients to monitoring partners #560

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/Jobs/SendDailyDigestNotificationsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Jobs;

use App\Mail\TaskDigestMail;
use App\Models\Traits\SkipRecipientsTrait;
use App\Models\V2\Tasks\Task;
use App\StateMachines\ReportStatusStateMachine;
use Carbon\Carbon;
Expand All @@ -19,6 +20,7 @@ class SendDailyDigestNotificationsJob implements ShouldQueue
use InteractsWithQueue;
use Queueable;
use SerializesModels;
use SkipRecipientsTrait;

private $task;

Expand All @@ -36,6 +38,7 @@ public function __construct(Task $task)
public function handle(): void
{
$users = $this->task->project->users()->get();
$users = $this->skipRecipients($users);
$usersGroupedByLocale = $users->groupBy('locale');
$taskDueAt = Carbon::parse($this->task->due_at);

Expand Down
12 changes: 5 additions & 7 deletions app/Jobs/V2/SendEntityStatusChangeEmailsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Jobs\V2;

use App\Mail\EntityStatusChange as EntityStatusChangeMail;
use App\Models\Traits\SkipRecipientsTrait;
use App\Models\V2\EntityModel;
use App\StateMachines\EntityStatusStateMachine;
use Illuminate\Bus\Queueable;
Expand All @@ -18,6 +19,7 @@ class SendEntityStatusChangeEmailsJob implements ShouldQueue
use InteractsWithQueue;
use Queueable;
use SerializesModels;
use SkipRecipientsTrait;

private EntityModel $entity;

Expand All @@ -35,18 +37,14 @@ public function handle(): void
}

$usersFromProject = $this->entity->project->users;
// TODO: This is a temporary hack to avoid spamming folks that have a funky role right now. In the future,
// they will have a different role, and we can simply skip sending this email to anybody with that role.
$usersFromProject = $this->skipRecipients($usersFromProject);
if (empty($usersFromProject)) {
return;
}

// TODO: This is a temporary hack to avoid spamming folks that have a funky role right now. In the future,
// they will have a different role, and we can simply skip sending this email to anybody with that role.
$skipRecipients = collect(explode(',', getenv('ENTITY_UPDATE_DO_NOT_EMAIL')));
foreach ($usersFromProject as $user) {
if ($skipRecipients->contains($user['email_address'])) {
continue;
}

Mail::to($user['email_address'])->send(new EntityStatusChangeMail($this->entity, $user));
}
}
Expand Down
4 changes: 4 additions & 0 deletions app/Jobs/V2/SendReportReminderEmailsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Jobs\V2;

use App\Mail\ReportReminder as ReportReminderMail;
use App\Models\Traits\SkipRecipientsTrait;
use App\Models\V2\EntityModel;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand All @@ -17,6 +18,7 @@ class SendReportReminderEmailsJob implements ShouldQueue
use InteractsWithQueue;
use Queueable;
use SerializesModels;
use SkipRecipientsTrait;

private EntityModel $entity;

Expand All @@ -32,6 +34,8 @@ public function handle(): void
{

$users = $this->entity->project->users;
$users = $this->skipRecipients($users);

if (empty($users)) {
return;
}
Expand Down
17 changes: 17 additions & 0 deletions app/Models/Traits/SkipRecipientsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Models\Traits;

use Illuminate\Support\Collection;

trait SkipRecipientsTrait
{
public function skipRecipients(Collection $users): Collection
{
$skipRecipients = collect(explode(',', getenv('ENTITY_UPDATE_DO_NOT_EMAIL')));

return $users->filter(function ($user) use ($skipRecipients) {
return ! $skipRecipients->contains($user->email_address ?? $user['email_address']);
});
}
}
Loading