X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/fef433a9cb1ae8c0daf2444e16e590cd9df114aa..refs/pull/5721/head:/app/Activity/Notifications/Messages/BaseActivityNotification.php diff --git a/app/Activity/Notifications/Messages/BaseActivityNotification.php b/app/Activity/Notifications/Messages/BaseActivityNotification.php index eb6eb0cc8..067cd8f66 100644 --- a/app/Activity/Notifications/Messages/BaseActivityNotification.php +++ b/app/Activity/Notifications/Messages/BaseActivityNotification.php @@ -3,13 +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,22 +23,6 @@ abstract class BaseActivityNotification extends Notification ) { } - /** - * Get the notification's delivery channels. - * - * @param mixed $notifiable - * @return array - */ - public function via($notifiable) - { - return ['mail']; - } - - /** - * Get the mail representation of the notification. - */ - abstract public function toMail(mixed $notifiable): MailMessage; - /** * Get the array representation of the notification. * @@ -52,12 +40,28 @@ abstract class BaseActivityNotification extends Notification /** * Build the common reason footer line used in mail messages. */ - protected function buildReasonFooterLine(): LinkedMailMessageLine + protected function buildReasonFooterLine(LocaleDefinition $locale): LinkedMailMessageLine { return new LinkedMailMessageLine( - url('/http/source.bookstackapp.com/preferences/notifications'), - trans('notifications.footer_reason'), - trans('notifications.footer_reason_link'), + url('/http/source.bookstackapp.com/my-account/notifications'), + $locale->trans('notifications.footer_reason'), + $locale->trans('notifications.footer_reason_link'), ); } + + /** + * 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. + */ + protected function buildPagePathLine(Page $page, User $notifiable): ?EntityPathMessageLine + { + $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); + } }