From 912d0aebc585447bd94978ee3d0f682ef41eeff0 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 7 Apr 2022 08:52:10 +1000 Subject: [PATCH] Do not send notifications to archived/deleted users --- app/Listeners/Invoice/InvoiceCreatedNotification.php | 2 +- app/Utils/Traits/Notifications/UserNotifies.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Listeners/Invoice/InvoiceCreatedNotification.php b/app/Listeners/Invoice/InvoiceCreatedNotification.php index 4f6d117f8176..f85200d5aad3 100644 --- a/app/Listeners/Invoice/InvoiceCreatedNotification.php +++ b/app/Listeners/Invoice/InvoiceCreatedNotification.php @@ -64,7 +64,7 @@ class InvoiceCreatedNotification implements ShouldQueue /* Returns an array of notification methods */ $methods = $this->findUserNotificationTypes($invoice->invitations()->first(), $company_user, 'invoice', ['all_notifications', 'invoice_created', 'invoice_created_all']); /* If one of the methods is email then we fire the EntitySentMailer */ - // if (($key = array_search('mail', $methods))) { + if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); diff --git a/app/Utils/Traits/Notifications/UserNotifies.php b/app/Utils/Traits/Notifications/UserNotifies.php index 5b8d312c843b..f5d8f63adcec 100644 --- a/app/Utils/Traits/Notifications/UserNotifies.php +++ b/app/Utils/Traits/Notifications/UserNotifies.php @@ -32,7 +32,7 @@ trait UserNotifies $notifiable_methods = []; $notifications = $company_user->notifications; - if ($company_user->company->is_disabled && is_array($notifications->email)) { + if ($company_user->company->is_disabled && is_array($notifications->email) || $company_user->trashed() || $company_user->user->trashed()) { return []; } @@ -56,7 +56,7 @@ trait UserNotifies $notifiable_methods = []; $notifications = $company_user->notifications; - if ($company_user->company->is_disabled || ! $notifications) { + if ($company_user->company->is_disabled || ! $notifications || $company_user->trashed() || $company_user->user->trashed()) { return []; } @@ -125,7 +125,7 @@ trait UserNotifies public function findCompanyUserNotificationType($company_user, $required_permissions) :array { - if ($company_user->company->is_disabled) { + if ($company_user->company->is_disabled || $company_user->trashed() || $company_user->user->trashed()) { return []; }