3 namespace BookStack\Activity\Notifications\Handlers;
5 use BookStack\Activity\Models\Loggable;
6 use BookStack\Activity\Notifications\Messages\BaseActivityNotification;
7 use BookStack\Entities\Models\Entity;
8 use BookStack\Permissions\PermissionApplicator;
9 use BookStack\Users\Models\User;
11 abstract class BaseNotificationHandler implements NotificationHandler
14 * @param class-string<BaseActivityNotification> $notification
15 * @param int[] $userIds
17 protected function sendNotificationToUserIds(string $notification, array $userIds, User $initiator, string|Loggable $detail, Entity $relatedModel): void
19 $users = User::query()->whereIn('id', array_unique($userIds))->get();
21 foreach ($users as $user) {
22 // Prevent sending to the user that initiated the activity
23 if ($user->id === $initiator->id) {
27 // Prevent sending of the user does not have notification permissions
28 if (!$user->can('receive-notifications')) {
32 // Prevent sending if the user does not have access to the related content
33 $permissions = new PermissionApplicator($user);
34 if (!$permissions->checkOwnableUserAccess($relatedModel, 'view')) {
38 // Send the notification
39 $user->notify(new $notification($detail, $initiator));