Skip to content

Commit

Permalink
Throw 404 when record does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Sep 28, 2023
1 parent a9a73f5 commit 33fd2d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Http/Controllers/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use DoubleThreeDigital\Runway\Runway;
use DoubleThreeDigital\Runway\Support\Json;
use Statamic\CP\Breadcrumbs;
use Statamic\Exceptions\NotFoundHttpException;
use Statamic\Facades\Scope;
use Statamic\Facades\User;
use Statamic\Fields\Field;
Expand Down Expand Up @@ -170,6 +171,10 @@ public function edit(EditRequest $request, $resourceHandle, $record)
->where($resource->model()->qualifyColumn($resource->routeKey()), $record)
->first();

if (! $record) {
throw new NotFoundHttpException();
}

$values = [];
$blueprintFieldKeys = $resource->blueprint()->fields()->all()->keys()->toArray();

Expand Down
11 changes: 11 additions & 0 deletions tests/Http/Controllers/ResourceControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ public function can_edit_resource()
->assertSee($post->body);
}

/** @test */
public function cant_edit_resource_when_it_does_not_exist()
{
$user = User::make()->makeSuper()->save();

$this->actingAs($user)
->get(cp_route('runway.edit', ['resourceHandle' => 'post', 'record' => 12345]))
->assertNotFound()
->assertSee('Page Not Found');
}

/** @test */
public function can_edit_resource_with_simple_date_field()
{
Expand Down

0 comments on commit 33fd2d7

Please sign in to comment.