]> BookStack Code Mirror - bookstack/blobdiff - app/Actions/ActivityLogger.php
Fixed failing test after drawio default url change
[bookstack] / app / Actions / ActivityLogger.php
index 3a329387f7d19ab1bef05d689c4fbec1c58134d9..0d1391b43fe254b25a06dff72be446762950604d 100644 (file)
@@ -5,6 +5,7 @@ namespace BookStack\Actions;
 use BookStack\Auth\Permissions\PermissionService;
 use BookStack\Entities\Models\Entity;
 use BookStack\Interfaces\Loggable;
+use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Support\Facades\Log;
 
 class ActivityLogger
@@ -35,6 +36,7 @@ class ActivityLogger
 
         $activity->save();
         $this->setNotification($type);
+        $this->dispatchWebhooks($type, $detail);
     }
 
     /**
@@ -68,7 +70,7 @@ class ActivityLogger
     /**
      * Flashes a notification message to the session if an appropriate message is available.
      */
-    protected function setNotification(string $type)
+    protected function setNotification(string $type): void
     {
         $notificationTextKey = 'activities.' . $type . '_notification';
         if (trans()->has($notificationTextKey)) {
@@ -77,6 +79,24 @@ class ActivityLogger
         }
     }
 
+    /**
+     * @param string|Loggable $detail
+     */
+    protected function dispatchWebhooks(string $type, $detail): void
+    {
+        $webhooks = Webhook::query()
+            ->whereHas('trackedEvents', function (Builder $query) use ($type) {
+                $query->where('event', '=', $type)
+                    ->orWhere('event', '=', 'all');
+            })
+            ->where('active', '=', true)
+            ->get();
+
+        foreach ($webhooks as $webhook) {
+            dispatch(new DispatchWebhookJob($webhook, $type, $detail));
+        }
+    }
+
     /**
      * Log out a failed login attempt, Providing the given username
      * as part of the message if the '%u' string is used.