]> BookStack Code Mirror - bookstack/commitdiff
Merge branch 'Man-in-Black-patch-1' into development
authorDan Brown <redacted>
Tue, 14 Nov 2023 10:40:30 +0000 (10:40 +0000)
committerDan Brown <redacted>
Tue, 14 Nov 2023 10:40:30 +0000 (10:40 +0000)
1  2 
tests/Activity/WatchTest.php

index 63e51c92e822a82dbff6dd4fa11bdd5092fd8c2e,42216a37960239c655c7e156e9199236e84f9b8e..2bf74c814d72fa9d7b0578e8debc419465452f46
@@@ -12,7 -12,6 +12,6 @@@ use BookStack\Activity\Tools\ActivityLo
  use BookStack\Activity\Tools\UserEntityWatchOptions;
  use BookStack\Activity\WatchLevels;
  use BookStack\Entities\Models\Entity;
- use BookStack\Entities\Tools\TrashCan;
  use BookStack\Settings\UserNotificationPreferences;
  use Illuminate\Support\Facades\Notification;
  use Tests\TestCase;
@@@ -268,6 -267,7 +267,7 @@@ class WatchTest extends TestCas
              return $mail->subject === 'New comment on page: ' . $entities['page']->getShortName()
                  && str_contains($mailContent, 'View Comment')
                  && str_contains($mailContent, 'Page Name: ' . $entities['page']->name)
+                 && str_contains($mailContent, 'Page Path: ' . $entities['book']->getShortName(24) . ' > ' . $entities['chapter']->getShortName(24))
                  && str_contains($mailContent, 'Commenter: ' . $admin->name)
                  && str_contains($mailContent, 'Comment: My new comment response');
          });
          $this->actingAs($admin);
          $this->entities->updatePage($entities['page'], ['name' => 'Updated page', 'html' => 'new page content']);
  
-         $notifications->assertSentTo($editor, function (PageUpdateNotification $notification) use ($editor, $admin) {
+         $notifications->assertSentTo($editor, function (PageUpdateNotification $notification) use ($editor, $admin, $entities) {
              $mail = $notification->toMail($editor);
              $mailContent = html_entity_decode(strip_tags($mail->render()), ENT_QUOTES);
              return $mail->subject === 'Updated page: Updated page'
                  && str_contains($mailContent, 'View Page')
                  && str_contains($mailContent, 'Page Name: Updated page')
+                 && str_contains($mailContent, 'Page Path: ' . $entities['book']->getShortName(24) . ' > ' . $entities['chapter']->getShortName(24))
                  && str_contains($mailContent, 'Updated By: ' . $admin->name)
                  && str_contains($mailContent, 'you won\'t be sent notifications for further edits to this page by the same editor');
          });
          $page = $entities['chapter']->pages()->where('draft', '=', true)->first();
          $this->post($page->getUrl(), ['name' => 'My new page', 'html' => 'My new page content']);
  
-         $notifications->assertSentTo($editor, function (PageCreationNotification $notification) use ($editor, $admin) {
+         $notifications->assertSentTo($editor, function (PageCreationNotification $notification) use ($editor, $admin, $entities) {
              $mail = $notification->toMail($editor);
              $mailContent = html_entity_decode(strip_tags($mail->render()), ENT_QUOTES);
              return $mail->subject === 'New page: My new page'
                  && str_contains($mailContent, 'View Page')
                  && str_contains($mailContent, 'Page Name: My new page')
+                 && str_contains($mailContent, 'Page Path: ' . $entities['book']->getShortName(24) . ' > ' . $entities['chapter']->getShortName(24))
                  && str_contains($mailContent, 'Created By: ' . $admin->name);
          });
      }
          $activities = [
              ActivityType::PAGE_CREATE => $entities['page'],
              ActivityType::PAGE_UPDATE => $entities['page'],
 -            ActivityType::COMMENT_CREATE => (new Comment([]))->forceFill(['entity_id' => $entities['page']->id, 'entity_type' => $entities['page']->getMorphClass()]),
 +            ActivityType::COMMENT_CREATE => Comment::factory()->make([
 +                'entity_id' => $entities['page']->id,
 +                'entity_type' => $entities['page']->getMorphClass(),
 +            ]),
          ];
  
          $notifications = Notification::fake();
  
          $this->assertDatabaseMissing('watches', ['watchable_type' => 'page', 'watchable_id' => $page->id]);
      }
+     public function test_page_path_in_notifications_limited_by_permissions()
+     {
+         $chapter = $this->entities->chapterHasPages();
+         $page = $chapter->pages()->first();
+         $book = $chapter->book;
+         $notification = new PageCreationNotification($page, $this->users->editor());
+         $viewer = $this->users->viewer();
+         $viewerRole = $viewer->roles()->first();
+         $content = html_entity_decode(strip_tags($notification->toMail($viewer)->render()), ENT_QUOTES);
+         $this->assertStringContainsString('Page Path: ' . $book->getShortName(24) . ' > ' . $chapter->getShortName(24), $content);
+         $this->permissions->setEntityPermissions($page, ['view'], [$viewerRole]);
+         $this->permissions->setEntityPermissions($chapter, [], [$viewerRole]);
+         $content = html_entity_decode(strip_tags($notification->toMail($viewer)->render()), ENT_QUOTES);
+         $this->assertStringContainsString('Page Path: ' . $book->getShortName(24), $content);
+         $this->assertStringNotContainsString(' > ' . $chapter->getShortName(24), $content);
+         $this->permissions->setEntityPermissions($book, [], [$viewerRole]);
+         $content = html_entity_decode(strip_tags($notification->toMail($viewer)->render()), ENT_QUOTES);
+         $this->assertStringNotContainsString('Page Path:', $content);
+         $this->assertStringNotContainsString($book->getShortName(24), $content);
+         $this->assertStringNotContainsString($chapter->getShortName(24), $content);
+     }
  }