X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/ecab2c8e42ae11485bb3c0fcce1a51df1bc6b118..refs/pull/5725/head:/app/Activity/Notifications/Handlers/BaseNotificationHandler.php diff --git a/app/Activity/Notifications/Handlers/BaseNotificationHandler.php b/app/Activity/Notifications/Handlers/BaseNotificationHandler.php index e0b3f3ceb..3a9b0c1dc 100644 --- a/app/Activity/Notifications/Handlers/BaseNotificationHandler.php +++ b/app/Activity/Notifications/Handlers/BaseNotificationHandler.php @@ -2,23 +2,20 @@ namespace BookStack\Activity\Notifications\Handlers; +use BookStack\Activity\Models\Loggable; use BookStack\Activity\Notifications\Messages\BaseActivityNotification; use BookStack\Entities\Models\Entity; use BookStack\Permissions\PermissionApplicator; use BookStack\Users\Models\User; +use Illuminate\Support\Facades\Log; abstract class BaseNotificationHandler implements NotificationHandler { - public function __construct( - protected PermissionApplicator $permissionApplicator - ) { - } - /** * @param class-string $notification * @param int[] $userIds */ - protected function sendNotificationToUserIds(string $notification, array $userIds, User $initiator, Entity $relatedModel): void + protected function sendNotificationToUserIds(string $notification, array $userIds, User $initiator, string|Loggable $detail, Entity $relatedModel): void { $users = User::query()->whereIn('id', array_unique($userIds))->get(); @@ -34,12 +31,17 @@ abstract class BaseNotificationHandler implements NotificationHandler } // Prevent sending if the user does not have access to the related content - if (!$this->permissionApplicator->checkOwnableUserAccess($relatedModel, 'view')) { + $permissions = new PermissionApplicator($user); + if (!$permissions->checkOwnableUserAccess($relatedModel, 'view')) { continue; } // Send the notification - $user->notify(new $notification($relatedModel, $initiator)); + try { + $user->notify(new $notification($detail, $initiator)); + } catch (\Exception $exception) { + Log::error("Failed to send email notification to user [id:{$user->id}] with error: {$exception->getMessage()}"); + } } } }