Commit b82e85c2 authored by Nicolas Widart's avatar Nicolas Widart

Merge branch 'feature/new-sidebar-group-permissions' of...

Merge branch 'feature/new-sidebar-group-permissions' of https://github.com/mikemand/Platform into mikemand-feature/new-sidebar-group-permissions

* 'feature/new-sidebar-group-permissions' of https://github.com/mikemand/Platform:
  Fix namespace for Core sidebar extender
  Add sidebar permissions to allow turning groups on/off globally Closes #276
parents 0e0719dc 4a328c34
<?php
return [
'core.sidebar' => [
'group' => 'core::sidebar.show group',
],
];
<?php
namespace Modules\Core\Sidebar;
use Maatwebsite\Sidebar\Badge;
use Maatwebsite\Sidebar\Group;
use Maatwebsite\Sidebar\Item;
use Maatwebsite\Sidebar\Menu;
use Modules\User\Contracts\Authentication;
class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
{
/**
* @var Authentication
*/
protected $auth;
/**
* @param Authentication $auth
*
* @internal param Guard $guard
*/
public function __construct(Authentication $auth)
{
$this->auth = $auth;
}
/**
* @param Menu $menu
*
* @return Menu
*/
public function extendWith(Menu $menu)
{
$menu->group(trans('core::sidebar.content'), function (Group $group) {
$group->weight(50);
$group->authorize(
$this->auth->hasAccess('core.sidebar.group')
);
});
return $menu;
}
}
...@@ -46,10 +46,6 @@ class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender ...@@ -46,10 +46,6 @@ class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
$this->auth->hasAccess('page.pages.index') $this->auth->hasAccess('page.pages.index')
); );
}); });
$group->authorize(
$this->auth->hasAccess('page.*')
);
}); });
return $menu; return $menu;
......
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
return [ return [
'content' => 'Content', 'content' => 'Content',
'show group' => 'Show sidebar group',
]; ];
...@@ -10,4 +10,5 @@ return [ ...@@ -10,4 +10,5 @@ return [
'type' => 'Type', 'type' => 'Type',
'list resource' => 'List themes', 'list resource' => 'List themes',
'show resource' => 'View themes', 'show resource' => 'View themes',
'publish assets' => 'Publish assets',
]; ];
...@@ -4,4 +4,5 @@ return [ ...@@ -4,4 +4,5 @@ return [
'title' => 'Workshop', 'title' => 'Workshop',
'modules' => 'Modules', 'modules' => 'Modules',
'themes' => 'Themes', 'themes' => 'Themes',
'show sidebar group' => 'See sidebar group',
]; ];
...@@ -38,17 +38,22 @@ class SentinelGroupSeedTableSeeder extends Seeder ...@@ -38,17 +38,22 @@ class SentinelGroupSeedTableSeeder extends Seeder
// Save the permissions // Save the permissions
$group = Sentinel::findRoleBySlug('admin'); $group = Sentinel::findRoleBySlug('admin');
$group->permissions = [ $group->permissions = [
'core.sidebar.group' => true,
/* Dashboard */
'dashboard.index' => true, 'dashboard.index' => true,
'dashboard.update' => true, 'dashboard.update' => true,
'dashboard.reset' => true, 'dashboard.reset' => true,
/* Workbench */ /* Workbench */
'workshop.sidebar.group' => true,
'workshop.modules.index' => true, 'workshop.modules.index' => true,
'workshop.modules.show' => true, 'workshop.modules.show' => true,
'workshop.modules.update' => true,
'workshop.modules.disable' => true, 'workshop.modules.disable' => true,
'workshop.modules.enable' => true, 'workshop.modules.enable' => true,
'workshop.modules.update' => true, 'workshop.modules.publish' => true,
'workshop.themes.index' => true, 'workshop.themes.index' => true,
'workshop.themes.show' => true, 'workshop.themes.show' => true,
'workshop.themes.publish' => true,
/* Roles */ /* Roles */
'user.roles.index' => true, 'user.roles.index' => true,
'user.roles.create' => true, 'user.roles.create' => true,
......
<?php <?php
return [ return [
'workshop.sidebar' => [
'group' => 'workshop::workshop.show sidebar group',
],
'workshop.modules' => [ 'workshop.modules' => [
'index' => 'workshop::modules.list resource', 'index' => 'workshop::modules.list resource',
'show' => 'workshop::modules.show resource', 'show' => 'workshop::modules.show resource',
'update' => 'workshop::modules.update resource', 'update' => 'workshop::modules.update resource',
'disable' => 'workshop::modules.disable resource', 'disable' => 'workshop::modules.disable resource',
'enable' => 'workshop::modules.enable resource', 'enable' => 'workshop::modules.enable resource',
'publish' => 'workshop::modules.publish assets' 'publish' => 'workshop::modules.publish assets',
], ],
'workshop.themes' => [ 'workshop.themes' => [
'index' => 'workshop::themes.list resource', 'index' => 'workshop::themes.list resource',
'show' => 'workshop::themes.show resource', 'show' => 'workshop::themes.show resource',
'publish' => 'workshop::themes.publish assets' 'publish' => 'workshop::themes.publish assets',
], ],
]; ];
...@@ -33,6 +33,9 @@ class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender ...@@ -33,6 +33,9 @@ class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
{ {
$menu->group(trans('workshop::workshop.title'), function (Group $group) { $menu->group(trans('workshop::workshop.title'), function (Group $group) {
$group->weight(100); $group->weight(100);
$group->authorize(
$this->auth->hasAccess('workshop.sidebar.group')
);
$group->item(trans('workshop::workshop.modules'), function (Item $item) { $group->item(trans('workshop::workshop.modules'), function (Item $item) {
$item->icon('fa fa-cogs'); $item->icon('fa fa-cogs');
$item->weight(100); $item->weight(100);
...@@ -49,10 +52,6 @@ class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender ...@@ -49,10 +52,6 @@ class SidebarExtender implements \Maatwebsite\Sidebar\SidebarExtender
$this->auth->hasAccess('workshop.themes.index') $this->auth->hasAccess('workshop.themes.index')
); );
}); });
$group->authorize(
$this->auth->hasAccess('workshop.*') or $this->auth->hasAccess('user.*') or $this->auth->hasAccess('setting.*')
);
}); });
return $menu; return $menu;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment