Skip to content

Commit 7b40861

Browse files
committed
Added parent context to recently updated items
- Includes tests to cover For #3183
1 parent 585bd0c commit 7b40861

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

app/Http/Controllers/PageController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use BookStack\Exceptions\NotFoundException;
1515
use BookStack\Exceptions\PermissionsException;
1616
use Exception;
17+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1718
use Illuminate\Http\Request;
1819
use Illuminate\Validation\ValidationException;
1920
use Throwable;
@@ -364,7 +365,11 @@ public function destroyDraft(string $bookSlug, int $pageId)
364365
*/
365366
public function showRecentlyUpdated()
366367
{
367-
$pages = Page::visible()->with('updatedBy')
368+
$visibleBelongsScope = function (BelongsTo $query) {
369+
$query->scopes('visible');
370+
};
371+
372+
$pages = Page::visible()->with(['updatedBy', 'book' => $visibleBelongsScope, 'chapter' => $visibleBelongsScope])
368373
->orderBy('updated_at', 'desc')
369374
->paginate(20)
370375
->setPath(url('/pages/recently-updated'));
@@ -375,6 +380,7 @@ public function showRecentlyUpdated()
375380
'title' => trans('entities.recently_updated_pages'),
376381
'entities' => $pages,
377382
'showUpdatedBy' => true,
383+
'showPath' => true,
378384
]);
379385
}
380386

tests/Entity/PageTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,42 @@ public function test_recently_updated_pages_view_shows_updated_by_details()
276276
$resp->assertElementContains('.entity-list .page:nth-child(1)', 'Updated 1 second ago by ' . $user->name);
277277
}
278278

279+
public function test_recently_updated_pages_view_shows_parent_chain()
280+
{
281+
$user = $this->getEditor();
282+
/** @var Page $page */
283+
$page = Page::query()->whereNotNull('chapter_id')->first();
284+
285+
$this->actingAs($user)->put($page->getUrl(), [
286+
'name' => 'Updated title',
287+
'html' => '<p>Updated content</p>',
288+
]);
289+
290+
$resp = $this->asAdmin()->get('/pages/recently-updated');
291+
$resp->assertElementContains('.entity-list .page:nth-child(1)', $page->chapter->getShortName(42));
292+
$resp->assertElementContains('.entity-list .page:nth-child(1)', $page->book->getShortName(42));
293+
}
294+
295+
public function test_recently_updated_pages_view_does_not_show_parent_if_not_visible()
296+
{
297+
$user = $this->getEditor();
298+
/** @var Page $page */
299+
$page = Page::query()->whereNotNull('chapter_id')->first();
300+
301+
$this->actingAs($user)->put($page->getUrl(), [
302+
'name' => 'Updated title',
303+
'html' => '<p>Updated content</p>',
304+
]);
305+
306+
$this->setEntityRestrictions($page->book);
307+
$this->setEntityRestrictions($page, ['view'], [$user->roles->first()]);
308+
309+
$resp = $this->get('/pages/recently-updated');
310+
$resp->assertDontSee($page->book->getShortName(42));
311+
$resp->assertDontSee($page->chapter->getShortName(42));
312+
$resp->assertElementContains('.entity-list .page:nth-child(1)', 'Updated title');
313+
}
314+
279315
public function test_recently_updated_pages_on_home()
280316
{
281317
/** @var Page $page */

0 commit comments

Comments
 (0)