Skip to content

Commit

Permalink
Fix sending email notification to deleted users
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Oct 30, 2023
1 parent a9d76c1 commit 9bae1fe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Changelog
- Enh #353: Tests for `next` version
- Fix #354: Don't display date badge twice after update a message
- Fix #356: Fix visibility of the method `Controller::getAccessRules()`
- Fix #358: Fix sending email notification to deleted users

3.1.1 (September 19, 2023)
---------------------------
Expand Down
16 changes: 11 additions & 5 deletions models/MessageNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public function notify(User $user)
// Backup the flag because it may be forced per user in order to select a proper notification type
$isNewConversation = $this->isNewConversation;

if ($this->isSendMail($user)) {
$this->sendMail($user);
}
$this->sendMail($user);

// Restore the flag
$this->isNewConversation = $isNewConversation;
Expand All @@ -73,8 +71,12 @@ private function sendLiveEvent(User $user)
]));
}

private function isSendMail(User $user): bool
private function canReceiveMail(User $user): bool
{
if ($user->email === null) {
return false;
}

if ($user->is($this->getEntrySender())) {
return false;
}
Expand Down Expand Up @@ -105,6 +107,10 @@ private function getNotificationCategory(): NotificationCategory

private function sendMail(User $user)
{
if (!$this->canReceiveMail($user)) {
return;
}

Yii::$app->i18n->setUserLocale($user);

$mail = Yii::$app->mailer->compose([
Expand Down Expand Up @@ -183,4 +189,4 @@ protected function getSubject(): string
: Yii::t('MailModule.models_Message', 'New message from {senderName}', $params);
}

}
}

0 comments on commit 9bae1fe

Please sign in to comment.