Skip to content

Commit

Permalink
Merge branch '4.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Apr 26, 2024
2 parents 13db0d2 + 7fb6a4f commit 9ae6339
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function edit($nav)
{
$nav = Nav::find($nav);

$this->authorize('edit', $nav, __('You are not authorized to configure navs.'));
$this->authorize('configure', $nav, __('You are not authorized to configure navs.'));

$values = [
'title' => $nav->title(),
Expand Down
5 changes: 5 additions & 0 deletions src/Policies/NavPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function store($user)
// handled by before()
}

public function configure($user)
{
// handled by before()
}

public function view($user, $nav)
{
$user = User::fromUser($user);
Expand Down
8 changes: 4 additions & 4 deletions src/Routing/ResolveRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public function item($redirect, $parent = null, $localize = false)
return null;
}

if ($redirect === '@child') {
return $this->firstChild($parent);
}

if (is_array($redirect)) {
$redirect = $redirect['url'];
}

if ($redirect === '@child') {
return $this->firstChild($parent);
}

if ($redirect instanceof Values) {
// Assume it's a `group` fieldtype with a `url` subfield.
return $redirect->url->value();
Expand Down
20 changes: 16 additions & 4 deletions tests/Data/Entries/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,12 @@ public function a_localized_entry_in_a_structured_collection_without_a_route_for
$this->assertNull($entry->url());
}

/** @test */
public function it_gets_urls_for_first_child_redirects()
/**
* @test
*
* @dataProvider firstChildRedirectProvider
*/
public function it_gets_urls_for_first_child_redirects($value)
{
\Event::fake(); // Don't invalidate static cache etc when saving entries.

Expand All @@ -641,9 +645,9 @@ public function it_gets_urls_for_first_child_redirects()

$collection = tap((new Collection)->handle('pages')->routes('{parent_uri}/{slug}'))->save();

$parent = tap((new Entry)->id('1')->locale('en')->collection($collection)->slug('parent')->set('redirect', '@child'))->save();
$parent = tap((new Entry)->id('1')->locale('en')->collection($collection)->slug('parent')->set('redirect', $value))->save();
$child = tap((new Entry)->id('2')->locale('en')->collection($collection)->slug('child'))->save();
$noChildren = tap((new Entry)->id('3')->locale('en')->collection($collection)->slug('nochildren')->set('redirect', '@child'))->save();
$noChildren = tap((new Entry)->id('3')->locale('en')->collection($collection)->slug('nochildren')->set('redirect', $value))->save();

$collection->structureContents([
'expects_root' => false, // irrelevant. just can't pass an empty array at the moment.
Expand Down Expand Up @@ -684,6 +688,14 @@ public function it_gets_urls_for_first_child_redirects()
$this->assertEquals(404, $noChildren->redirectUrl());
}

public static function firstChildRedirectProvider()
{
return [
'string' => ['@child'],
'array' => [['url' => '@child']],
];
}

/** @test */
public function it_gets_and_sets_supplemental_data()
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Feature/Navigation/EditNavigationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class EditNavigationTest extends TestCase
use PreventSavingStacheItemsToDisk;

/** @test */
public function it_shows_the_edit_form_if_user_has_edit_permission()
public function it_shows_the_edit_form_if_user_has_configure_permission()
{
$nav = $this->createNav('foo');
Nav::shouldReceive('all')->andReturn(collect([$nav]));
Nav::shouldReceive('find')->andReturn($nav);

$this->setTestRoles(['test' => ['access cp', 'edit foo nav']]);
$this->setTestRoles(['test' => ['access cp', 'configure navs']]);
$user = Facades\User::make()->assignRole('test')->save();

$response = $this
Expand All @@ -32,7 +32,7 @@ public function it_shows_the_edit_form_if_user_has_edit_permission()
}

/** @test */
public function it_denies_access_if_user_doesnt_have_edit_permission()
public function it_denies_access_if_user_doesnt_have_configure_permission()
{
$nav = $this->createNav('foo');
Nav::shouldReceive('all')->andReturn(collect([$nav]));
Expand Down

0 comments on commit 9ae6339

Please sign in to comment.