From 09aabff3073f5ef066e1cabf1ee265312d982e30 Mon Sep 17 00:00:00 2001 From: Joachim Date: Wed, 19 Jun 2024 13:07:39 +0200 Subject: [PATCH 1/7] test for broken revision route --- tests/Feature/Entries/EntryRevisionsTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Feature/Entries/EntryRevisionsTest.php b/tests/Feature/Entries/EntryRevisionsTest.php index 1f639e8c72..7f01db60f1 100644 --- a/tests/Feature/Entries/EntryRevisionsTest.php +++ b/tests/Feature/Entries/EntryRevisionsTest.php @@ -156,6 +156,10 @@ public function it_unpublishes_an_entry() $this->assertEquals('user-1', $revision->user()->id()); $this->assertEquals('Test!', $revision->message()); $this->assertEquals('unpublish', $revision->action()); + $this->get(cp_route('collections.entries.revisions.index', [ + 'collection' => 'blog', + 'entry' => '1', + ]))->assertOk(); } /** @test */ From d40e528c7c38f8cede6b1e6b7b225968bcdb72d6 Mon Sep 17 00:00:00 2001 From: Joachim Date: Wed, 19 Jun 2024 13:09:56 +0200 Subject: [PATCH 2/7] fix link of working copy in revision list --- .../Controllers/CP/Collections/EntryRevisionsController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Http/Controllers/CP/Collections/EntryRevisionsController.php b/src/Http/Controllers/CP/Collections/EntryRevisionsController.php index 57d5554984..9a901a5787 100644 --- a/src/Http/Controllers/CP/Collections/EntryRevisionsController.php +++ b/src/Http/Controllers/CP/Collections/EntryRevisionsController.php @@ -18,11 +18,12 @@ public function index(Request $request, $collection, $entry) ->prepend($this->workingCopy($entry)) ->filter() ->each(function ($revision) use ($collection, $entry) { - $revision->attribute('item_url', cp_route('collections.entries.revisions.show', [ + $url = $revision->id() ? cp_route('collections.entries.revisions.show', [ 'collection' => $collection, 'entry' => $entry->id(), 'revision' => $revision->id(), - ])); + ]) : ''; + $revision->attribute('item_url', $url); }); // The first non manually created revision would be considered the "current" From 97d058864ad0ac9b6a0bfb775e3bf40fca25c08c Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 19 Jun 2024 12:56:59 +0100 Subject: [PATCH 3/7] Refactor --- .../CP/Collections/EntryRevisionsController.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Http/Controllers/CP/Collections/EntryRevisionsController.php b/src/Http/Controllers/CP/Collections/EntryRevisionsController.php index 9a901a5787..6eba655e1f 100644 --- a/src/Http/Controllers/CP/Collections/EntryRevisionsController.php +++ b/src/Http/Controllers/CP/Collections/EntryRevisionsController.php @@ -7,6 +7,7 @@ use Statamic\Facades\User; use Statamic\Http\Controllers\CP\CpController; use Statamic\Http\Resources\CP\Entries\Entry as EntryResource; +use Statamic\Revisions\WorkingCopy; class EntryRevisionsController extends CpController { @@ -18,12 +19,13 @@ public function index(Request $request, $collection, $entry) ->prepend($this->workingCopy($entry)) ->filter() ->each(function ($revision) use ($collection, $entry) { - $url = $revision->id() ? cp_route('collections.entries.revisions.show', [ - 'collection' => $collection, - 'entry' => $entry->id(), - 'revision' => $revision->id(), - ]) : ''; - $revision->attribute('item_url', $url); + if (! $revision instanceof WorkingCopy) { + $revision->attribute('item_url', cp_route('collections.entries.revisions.show', [ + 'collection' => $collection, + 'entry' => $entry->id(), + 'revision' => $revision->id(), + ])); + } }); // The first non manually created revision would be considered the "current" From 2344e18be2efaf1bd4f68ef2fba6b12494669fd9 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 19 Jun 2024 12:57:52 +0100 Subject: [PATCH 4/7] Remove assertion from test --- tests/Feature/Entries/EntryRevisionsTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Feature/Entries/EntryRevisionsTest.php b/tests/Feature/Entries/EntryRevisionsTest.php index 7f01db60f1..1f639e8c72 100644 --- a/tests/Feature/Entries/EntryRevisionsTest.php +++ b/tests/Feature/Entries/EntryRevisionsTest.php @@ -156,10 +156,6 @@ public function it_unpublishes_an_entry() $this->assertEquals('user-1', $revision->user()->id()); $this->assertEquals('Test!', $revision->message()); $this->assertEquals('unpublish', $revision->action()); - $this->get(cp_route('collections.entries.revisions.index', [ - 'collection' => 'blog', - 'entry' => '1', - ]))->assertOk(); } /** @test */ From 5611d0106ab18b6d8f517166e03cf9959073dd3d Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 19 Jun 2024 13:11:02 +0100 Subject: [PATCH 5/7] Add a test to cover the revisions index endpoint --- tests/Feature/Entries/EntryRevisionsTest.php | 57 ++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/Feature/Entries/EntryRevisionsTest.php b/tests/Feature/Entries/EntryRevisionsTest.php index 1f639e8c72..30a8b9e64e 100644 --- a/tests/Feature/Entries/EntryRevisionsTest.php +++ b/tests/Feature/Entries/EntryRevisionsTest.php @@ -39,6 +39,63 @@ public function tearDown(): void parent::tearDown(); } + /** @test */ + public function it_gets_revisions() + { + $now = Carbon::parse('2017-02-03'); + Carbon::setTestNow($now); + $this->setTestBlueprint('test', ['foo' => ['type' => 'text']]); + $this->setTestRoles(['test' => ['access cp', 'publish blog entries']]); + $user = User::make()->id('user-1')->assignRole('test')->save(); + + $entry = EntryFactory::id('1') + ->slug('test') + ->collection('blog') + ->published(true) + ->date('2010-12-25') + ->data([ + 'blueprint' => 'test', + 'title' => 'Original title', + 'foo' => 'bar', + ])->create(); + + tap($entry->makeRevision(), function ($copy) { + $copy->message('Revision one'); + $copy->date(Carbon::parse('2017-02-01')); + })->save(); + + tap($entry->makeRevision(), function ($copy) { + $copy->message('Revision two'); + $copy->date(Carbon::parse('2017-02-03')); + })->save(); + + tap($entry->makeWorkingCopy(), function ($copy) { + $attrs = $copy->attributes(); + $attrs['data']['title'] = 'Title modified in working copy'; + $attrs['data']['foo'] = 'baz'; + $copy->attributes($attrs); + })->save(); + + $this + ->actingAs($user) + ->get($entry->revisionsUrl()) + ->assertOk() + ->assertJsonPath('0.revisions.0.action', 'revision') + ->assertJsonPath('0.revisions.0.message', 'Revision one') + ->assertJsonPath('0.revisions.0.attributes.data.title', 'Original title') + ->assertJsonPath('0.revisions.0.attributes.item_url', "http://localhost/cp/collections/blog/entries/1/revisions/".Carbon::parse('2017-02-01')->timestamp) + + ->assertJsonPath('1.revisions.0.action', 'revision') + ->assertJsonPath('1.revisions.0.message', false) + ->assertJsonPath('1.revisions.0.attributes.data.title', 'Title modified in working copy') + ->assertJsonPath('1.revisions.0.attributes.item_url', null) + + ->assertJsonPath('1.revisions.1.action', 'revision') + ->assertJsonPath('1.revisions.1.message', 'Revision two') + ->assertJsonPath('1.revisions.1.attributes.data.title', 'Original title') + ->assertJsonPath('1.revisions.1.attributes.item_url', "http://localhost/cp/collections/blog/entries/1/revisions/".Carbon::parse('2017-02-03')->timestamp); + } + /** @test */ public function it_publishes_an_entry() { From e867b02c9ae47ad777433224de56dde3d24087b6 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 19 Jun 2024 13:15:47 +0100 Subject: [PATCH 6/7] =?UTF-8?q?=F0=9F=8D=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Feature/Entries/EntryRevisionsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Entries/EntryRevisionsTest.php b/tests/Feature/Entries/EntryRevisionsTest.php index 30a8b9e64e..4f7952481b 100644 --- a/tests/Feature/Entries/EntryRevisionsTest.php +++ b/tests/Feature/Entries/EntryRevisionsTest.php @@ -83,7 +83,7 @@ public function it_gets_revisions() ->assertJsonPath('0.revisions.0.action', 'revision') ->assertJsonPath('0.revisions.0.message', 'Revision one') ->assertJsonPath('0.revisions.0.attributes.data.title', 'Original title') - ->assertJsonPath('0.revisions.0.attributes.item_url', "http://localhost/cp/collections/blog/entries/1/revisions/".Carbon::parse('2017-02-01')->timestamp) + ->assertJsonPath('0.revisions.0.attributes.item_url', 'http://localhost/cp/collections/blog/entries/1/revisions/'.Carbon::parse('2017-02-01')->timestamp) ->assertJsonPath('1.revisions.0.action', 'revision') ->assertJsonPath('1.revisions.0.message', false) @@ -93,7 +93,7 @@ public function it_gets_revisions() ->assertJsonPath('1.revisions.1.action', 'revision') ->assertJsonPath('1.revisions.1.message', 'Revision two') ->assertJsonPath('1.revisions.1.attributes.data.title', 'Original title') - ->assertJsonPath('1.revisions.1.attributes.item_url', "http://localhost/cp/collections/blog/entries/1/revisions/".Carbon::parse('2017-02-03')->timestamp); + ->assertJsonPath('1.revisions.1.attributes.item_url', 'http://localhost/cp/collections/blog/entries/1/revisions/'.Carbon::parse('2017-02-03')->timestamp); } /** @test */ From b09b533eb968427430b407f8ca661546f47d1d51 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Thu, 20 Jun 2024 12:38:29 -0400 Subject: [PATCH 7/7] add links before working copy is added rather than using condition --- .../CP/Collections/EntryRevisionsController.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Http/Controllers/CP/Collections/EntryRevisionsController.php b/src/Http/Controllers/CP/Collections/EntryRevisionsController.php index 6eba655e1f..c1ef85e20f 100644 --- a/src/Http/Controllers/CP/Collections/EntryRevisionsController.php +++ b/src/Http/Controllers/CP/Collections/EntryRevisionsController.php @@ -7,7 +7,6 @@ use Statamic\Facades\User; use Statamic\Http\Controllers\CP\CpController; use Statamic\Http\Resources\CP\Entries\Entry as EntryResource; -use Statamic\Revisions\WorkingCopy; class EntryRevisionsController extends CpController { @@ -16,17 +15,13 @@ public function index(Request $request, $collection, $entry) $revisions = $entry ->revisions() ->reverse() + ->each(fn ($revision) => $revision->attribute('item_url', cp_route('collections.entries.revisions.show', [ + 'collection' => $collection, + 'entry' => $entry->id(), + 'revision' => $revision->id(), + ]))) ->prepend($this->workingCopy($entry)) - ->filter() - ->each(function ($revision) use ($collection, $entry) { - if (! $revision instanceof WorkingCopy) { - $revision->attribute('item_url', cp_route('collections.entries.revisions.show', [ - 'collection' => $collection, - 'entry' => $entry->id(), - 'revision' => $revision->id(), - ])); - } - }); + ->filter(); // The first non manually created revision would be considered the "current" // version. It's what corresponds to what's in the content directory.