Skip to content
Merged
2 changes: 1 addition & 1 deletion resources/js/components/collections/Listing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="card overflow-hidden p-0" slot-scope="{ filteredRows: rows }">
<data-list-table :rows="rows">
<template slot="cell-title" slot-scope="{ row: collection }">
<a :href="collection.entries_url">{{ __(collection.title) }}</a>
<a :href="collection.available_in_selected_site ? collection.entries_url : collection.edit_url">{{ __(collection.title) }}</a>
</template>
<template slot="actions" slot-scope="{ row: collection, index }">
<dropdown-list placement="left-start">
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/navigation/Listing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="card p-0" slot-scope="{ filteredRows: rows }">
<data-list-table :rows="rows">
<template slot="cell-title" slot-scope="{ row: structure }">
<a :href="structure.show_url" class="flex items-center" v-text="__(structure.title)" />
<a :href="structure.available_in_selected_site ? structure.show_url : structure.edit_url" class="flex items-center" v-text="__(structure.title)" />
</template>
<template slot="actions" slot-scope="{ row: structure, index }">
<dropdown-list>
Expand Down
57 changes: 41 additions & 16 deletions src/CP/Navigation/CoreNav.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
use Statamic\Facades\GlobalSet as GlobalSetAPI;
use Statamic\Facades\Nav as NavAPI;
use Statamic\Facades\Role as RoleAPI;
use Statamic\Facades\Site;
use Statamic\Facades\Stache;
use Statamic\Facades\Taxonomy as TaxonomyAPI;
use Statamic\Facades\User;
use Statamic\Facades\UserGroup as UserGroupAPI;
use Statamic\Facades\Utility;
use Statamic\Statamic;
Expand Down Expand Up @@ -65,23 +67,41 @@ protected function makeContentSection()
->icon('/content-writing')
->can('index', Collection::class)
->children(function () {
return CollectionAPI::all()->sortBy->title()->map(function ($collection) {
return Nav::item($collection->title())
->url($collection->showUrl())
->can('view', $collection);
});
return CollectionAPI::all()->sortBy->title()
->filter(function ($collection) {
return User::current()->can('configure collections')
|| $collection->sites()->contains(Site::selected()->handle());
})
->map(function ($collection) {
return Nav::item($collection->title())
->url(
$collection->sites()->contains(Site::selected()->handle())
? $collection->showUrl()
: $collection->editUrl()
)
->can('view', $collection);
});
});

Nav::content('Navigation')
->route('navigation.index')
->icon('/hierarchy-files')
->can('index', NavContract::class)
->children(function () {
return NavAPI::all()->sortBy->title()->map(function ($nav) {
return Nav::item($nav->title())
->url($nav->showUrl())
->can('view', $nav);
});
return NavAPI::all()->sortBy->title()
->filter(function ($nav) {
return User::current()->can('configure navs')
|| $nav->sites()->contains(Site::selected()->handle());
})
->map(function ($nav) {
return Nav::item($nav->title())
->url(
$nav->sites()->contains(Site::selected()->handle())
? $nav->showUrl()
: $nav->editUrl()
)
->can('view', $nav);
});
});

Nav::content('Taxonomies')
Expand Down Expand Up @@ -113,13 +133,18 @@ protected function makeContentSection()
->icon('/earth')
->can('index', GlobalSet::class)
->children(function () {
return GlobalSetAPI::all()->sortBy->title()->map(function ($globalSet) {
$localized = $globalSet->inSelectedSite();
return GlobalSetAPI::all()->sortBy->title()
->filter(function ($globalSet) {
return User::current()->can('configure globals')
|| ! is_null($globalSet->inSelectedSite());
})
->map(function ($globalSet) {
$localized = $globalSet->inSelectedSite();

return Nav::item($globalSet->title())
->url($localized ? $localized->editUrl() : $globalSet->editUrl())
->can('view', $globalSet);
})->filter();
return Nav::item($globalSet->title())
->url($localized ? $localized->editUrl() : $globalSet->editUrl())
->can('view', $globalSet);
})->filter();
});

return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public function index()
$this->authorize('index', CollectionContract::class, __('You are not authorized to view collections.'));

$collections = Collection::all()->filter(function ($collection) {
return User::current()->can('view', $collection);
return User::current()->can('configure collections')
|| User::current()->can('view', $collection)
&& $collection->sites()->contains(Site::selected()->handle());
})->map(function ($collection) {
return [
'id' => $collection->handle(),
Expand All @@ -39,6 +41,7 @@ public function index()
'deleteable' => User::current()->can('delete', $collection),
'editable' => User::current()->can('edit', $collection),
'blueprint_editable' => User::current()->can('configure fields'),
'available_in_selected_site' => $collection->sites()->contains(Site::selected()->handle()),
];
})->values();

Expand Down
4 changes: 3 additions & 1 deletion src/Http/Controllers/CP/Navigation/NavigationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public function index()
$this->authorize('index', NavContract::class, __('You are not authorized to view navs.'));

$navs = Nav::all()->filter(function ($nav) {
return User::current()->can('view', $nav);
return User::current()->can('configure navs')
|| ($nav->sites()->contains(Site::selected()->handle()) && User::current()->can('view', $nav));
})->map(function ($structure) {
return [
'id' => $structure->handle(),
Expand All @@ -27,6 +28,7 @@ public function index()
'edit_url' => $structure->editUrl(),
'delete_url' => $structure->deleteUrl(),
'deleteable' => User::current()->can('delete', $structure),
'available_in_selected_site' => $structure->sites()->contains(Site::selected()->handle()),
];
})->values();

Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Collections/ViewCollectionListingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function it_shows_a_list_of_collections()
'deleteable' => true,
'editable' => true,
'blueprint_editable' => true,
'available_in_selected_site' => true,
],
[
'id' => 'bar',
Expand All @@ -56,6 +57,7 @@ public function it_shows_a_list_of_collections()
'deleteable' => true,
'editable' => true,
'blueprint_editable' => true,
'available_in_selected_site' => true,
],
]))
->assertDontSee('no-results');
Expand Down