Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function show(Request $request, $collection, $entry, $revision)
'readOnly' => true,
'published' => $entry->published(),
'locale' => $entry->locale(),
'localizations' => $entry->collection()->sites()->map(function ($handle) use ($entry) {
'localizations' => $this->getAuthorizedSitesForCollection($entry->collection())->map(function ($handle) use ($entry) {
$localized = $entry->in($handle);
$exists = $localized !== null;

Expand Down Expand Up @@ -120,4 +120,11 @@ protected function collectionToArray($collection)
'url' => cp_route('collections.show', $collection->handle()),
];
}

private function getAuthorizedSitesForCollection($collection)
{
return $collection
->sites()
->filter(fn ($handle) => User::current()->can('view', Site::get($handle)));
}
}
51 changes: 51 additions & 0 deletions tests/Feature/Entries/EntryRevisionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,57 @@ public function localized_entry_with_localizable_date_keeps_its_own_date_when_re
);
}

#[Test]
public function revision_localizations_only_includes_authorized_sites()
{
$this->setSites([
'en' => ['url' => 'http://localhost/', 'locale' => 'en'],
'fr' => ['url' => 'http://localhost/fr/', 'locale' => 'fr'],
'de' => ['url' => 'http://localhost/de/', 'locale' => 'de'],
]);

$this->setTestBlueprint('test', ['foo' => ['type' => 'text']]);
$this->setTestRoles(['test' => [
'access cp',
'view blog entries',
'access en site',
'access fr site',
// Note: no 'access de site' permission
]]);
$user = User::make()->id('user-1')->assignRole('test')->save();

$this->collection->sites(['en', 'fr', 'de'])->save();

$entry = EntryFactory::id('1')
->slug('test')
->collection('blog')
->locale('en')
->published(true)
->date('2010-12-25')
->data([
'blueprint' => 'test',
'title' => 'Original title',
'foo' => 'bar',
])->create();

$revision = tap($entry->makeRevision(), function ($copy) {
$copy->message('Revision one');
$copy->date(Carbon::parse('2017-02-01'));
});
$revision->save();

$response = $this
->actingAs($user)
->getJson($entry->revisionsUrl().'/'.$revision->date()->timestamp)
->assertOk();

$localizations = $response->json('localizations');

// User should only see en and fr sites, not de
$this->assertCount(2, $localizations);
$this->assertEquals(['en', 'fr'], array_column($localizations, 'handle'));
}

private function setTestBlueprint($handle, $fields)
{
$blueprint = Blueprint::makeFromFields($fields)->setHandle($handle);
Expand Down
Loading