]> BookStack Code Mirror - bookstack/blob - app/Activity/Notifications/Messages/BaseActivityNotification.php
Fixed notification preferences URL in email
[bookstack] / app / Activity / Notifications / Messages / BaseActivityNotification.php
1 <?php
2
3 namespace BookStack\Activity\Notifications\Messages;
4
5 use BookStack\Activity\Models\Loggable;
6 use BookStack\Activity\Notifications\MessageParts\EntityPathMessageLine;
7 use BookStack\Activity\Notifications\MessageParts\LinkedMailMessageLine;
8 use BookStack\App\MailNotification;
9 use BookStack\Entities\Models\Entity;
10 use BookStack\Entities\Models\Page;
11 use BookStack\Permissions\PermissionApplicator;
12 use BookStack\Translation\LocaleDefinition;
13 use BookStack\Users\Models\User;
14 use Illuminate\Bus\Queueable;
15
16 abstract class BaseActivityNotification extends MailNotification
17 {
18     use Queueable;
19
20     public function __construct(
21         protected Loggable|string $detail,
22         protected User $user,
23     ) {
24     }
25
26     /**
27      * Get the array representation of the notification.
28      *
29      * @param  mixed  $notifiable
30      * @return array
31      */
32     public function toArray($notifiable)
33     {
34         return [
35             'activity_detail' => $this->detail,
36             'activity_creator' => $this->user,
37         ];
38     }
39
40     /**
41      * Build the common reason footer line used in mail messages.
42      */
43     protected function buildReasonFooterLine(LocaleDefinition $locale): LinkedMailMessageLine
44     {
45         return new LinkedMailMessageLine(
46             url('/my-account/notifications'),
47             $locale->trans('notifications.footer_reason'),
48             $locale->trans('notifications.footer_reason_link'),
49         );
50     }
51
52     /**
53      * Build a line which provides the book > chapter path to a page.
54      * Takes into account visibility of these parent items.
55      * Returns null if no path items can be used.
56      */
57     protected function buildPagePathLine(Page $page, User $notifiable): ?EntityPathMessageLine
58     {
59         $permissions = new PermissionApplicator($notifiable);
60
61         $path = array_filter([$page->book, $page->chapter], function (?Entity $entity) use ($permissions) {
62             return !is_null($entity) && $permissions->checkOwnableUserAccess($entity, 'view');
63         });
64
65         return empty($path) ? null : new EntityPathMessageLine($path);
66     }
67 }