]> BookStack Code Mirror - bookstack/blobdiff - app/Activity/Notifications/Messages/BaseActivityNotification.php
Perms: Fixed some issues made when adding transactions
[bookstack] / app / Activity / Notifications / Messages / BaseActivityNotification.php
index 285e2803ee77aa591aa003ecc19e1d7127285d5f..067cd8f66e6866fe2900be3e6920543feb49bf71 100644 (file)
@@ -3,12 +3,17 @@
 namespace BookStack\Activity\Notifications\Messages;
 
 use BookStack\Activity\Models\Loggable;
+use BookStack\Activity\Notifications\MessageParts\EntityPathMessageLine;
+use BookStack\Activity\Notifications\MessageParts\LinkedMailMessageLine;
+use BookStack\App\MailNotification;
+use BookStack\Entities\Models\Entity;
+use BookStack\Entities\Models\Page;
+use BookStack\Permissions\PermissionApplicator;
+use BookStack\Translation\LocaleDefinition;
 use BookStack\Users\Models\User;
 use Illuminate\Bus\Queueable;
-use Illuminate\Notifications\Messages\MailMessage;
-use Illuminate\Notifications\Notification;
 
-abstract class BaseActivityNotification extends Notification
+abstract class BaseActivityNotification extends MailNotification
 {
     use Queueable;
 
@@ -19,32 +24,44 @@ abstract class BaseActivityNotification extends Notification
     }
 
     /**
-     * Get the notification's delivery channels.
+     * Get the array representation of the notification.
      *
      * @param  mixed  $notifiable
      * @return array
      */
-    public function via($notifiable)
+    public function toArray($notifiable)
     {
-        return ['mail'];
+        return [
+            'activity_detail' => $this->detail,
+            'activity_creator' => $this->user,
+        ];
     }
 
     /**
-     * Get the mail representation of the notification.
+     * Build the common reason footer line used in mail messages.
      */
-    abstract public function toMail(mixed $notifiable): MailMessage;
+    protected function buildReasonFooterLine(LocaleDefinition $locale): LinkedMailMessageLine
+    {
+        return new LinkedMailMessageLine(
+            url('/my-account/notifications'),
+            $locale->trans('notifications.footer_reason'),
+            $locale->trans('notifications.footer_reason_link'),
+        );
+    }
 
     /**
-     * Get the array representation of the notification.
-     *
-     * @param  mixed  $notifiable
-     * @return array
+     * Build a line which provides the book > chapter path to a page.
+     * Takes into account visibility of these parent items.
+     * Returns null if no path items can be used.
      */
-    public function toArray($notifiable)
+    protected function buildPagePathLine(Page $page, User $notifiable): ?EntityPathMessageLine
     {
-        return [
-            'activity_detail' => $this->detail,
-            'activity_creator' => $this->user,
-        ];
+        $permissions = new PermissionApplicator($notifiable);
+
+        $path = array_filter([$page->book, $page->chapter], function (?Entity $entity) use ($permissions) {
+            return !is_null($entity) && $permissions->checkOwnableUserAccess($entity, 'view');
+        });
+
+        return empty($path) ? null : new EntityPathMessageLine($path);
     }
 }