diff --git a/src/Actions/RenameAsset.php b/src/Actions/RenameAsset.php index bdec021c6c0..0791bc1a139 100644 --- a/src/Actions/RenameAsset.php +++ b/src/Actions/RenameAsset.php @@ -59,6 +59,10 @@ protected function fieldItems() { $asset = $this->items->first(); + // The selected asset may no longer exist (e.g. it was renamed by a + // previous request), in which case there's nothing left to rename. + abort_unless($asset, 404); + return [ 'filename' => [ 'type' => 'text', diff --git a/tests/Actions/RenameAssetTest.php b/tests/Actions/RenameAssetTest.php index dfd5f394ea7..2c21293250d 100644 --- a/tests/Actions/RenameAssetTest.php +++ b/tests/Actions/RenameAssetTest.php @@ -72,6 +72,15 @@ public function it_renames() $this->assertAssetExistsAndHasData('bravo.jpg', ['alt' => 'The alfa alt text']); } + #[Test] + public function it_404s_when_the_selected_asset_does_not_exist() + { + $this + ->actingAs(tap(User::make()->makeSuper())->save()) + ->rename('does-not-exist.jpg', 'bravo') + ->assertNotFound(); + } + #[Test] public function it_fails_validation_if_provided_with_the_current_filename() {