Skip to content

Commit

Permalink
[5.x] Fix REST API errors when CP route is empty (#11213)
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean authored Dec 4, 2024
1 parent 67463fe commit 5bc33bf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ private function needsEntryBinding(?Route $route): bool
return false;
}

if ($this->isCpRoute($route)) {
return true;
}

if ($this->isApiRoute($route)) {
return false;
}

if ($this->isCpRoute($route)) {
return true;
}

return $this->isFrontendBindingEnabled();
}

Expand Down Expand Up @@ -191,14 +191,14 @@ private function needsTermBinding(?Route $route): bool
return false;
}

if ($this->isCpRoute($route)) {
return true;
}

if ($this->isApiRoute($route)) {
return false;
}

if ($this->isCpRoute($route)) {
return true;
}

return $this->isFrontendBindingEnabled();
}

Expand Down Expand Up @@ -382,14 +382,14 @@ private function needsRevisionBinding(?Route $route): bool
return false;
}

if ($this->isCpRoute($route)) {
return true;
}

if ($this->isApiRoute($route)) {
return false;
}

if ($this->isCpRoute($route)) {
return true;
}

return $this->isFrontendBindingEnabled();
}

Expand Down
32 changes: 32 additions & 0 deletions tests/API/APITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,22 @@ public function relationships_are_shallow_augmented()
]);
}

#[Test]
public function can_view_entries_when_cp_route_is_empty()
{
Facades\Config::set('statamic.cp.route', '');
Facades\Config::set('statamic.api.resources.collections', true);

Facades\Collection::make('pages')->save();
Facades\Entry::make()->collection('pages')->id('home')->data(['title' => 'Home'])->save();

$this->get('/api/collections/pages/entries/home')->assertJson([
'data' => [
'title' => 'Home',
],
]);
}

#[Test]
#[DataProvider('userPasswordFilterProvider')]
public function it_never_allows_filtering_users_by_password($filter)
Expand Down Expand Up @@ -528,6 +544,22 @@ public static function termNotFoundProvider()
];
}

#[Test]
public function can_view_terms_when_cp_route_is_empty()
{
Facades\Config::set('statamic.cp.route', '');
Facades\Config::set('statamic.api.resources.taxonomies', true);

Facades\Taxonomy::make('topics')->save();
Facades\Term::make()->taxonomy('topics')->inDefaultLocale()->slug('dance')->data(['title' => 'Dance'])->save();

$this->get('/api/taxonomies/topics/terms/dance')->assertJson([
'data' => [
'title' => 'Dance',
],
]);
}

private function makeCollection($handle)
{
return Facades\Collection::make($handle);
Expand Down

0 comments on commit 5bc33bf

Please sign in to comment.