Skip to content

Commit

Permalink
Merge branch 'master' into fix-use-statements
Browse files Browse the repository at this point in the history
  • Loading branch information
dizzystuff authored Oct 25, 2021
2 parents f0e851c + a5c7d00 commit 3af29c7
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 24 deletions.
4 changes: 4 additions & 0 deletions src/Extensions/MenuSetParentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class MenuSetParentExtension extends DataExtension
'MenuSets'
];

private static $cascade_duplicates = [
'MenuSets'
];

public function updateCMSFields(FieldList $fields)
{
$fields->removeByName('MenuSets');
Expand Down
61 changes: 48 additions & 13 deletions src/Model/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
use SilverStripe\Forms\GridField\GridFieldPageCount;
use SilverStripe\Forms\GridField\GridFieldPaginator;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Versioned\Versioned;
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
use UncleCheese\DisplayLogic\Forms\Wrapper;

class MenuItem extends SuperLink
class MenuItem extends SuperLink implements PermissionProvider
{
const SUBMENU_SITETREE = 'sitetree';
const SUBMENU_MANUAL = 'manual';
Expand Down Expand Up @@ -69,6 +71,10 @@ class MenuItem extends SuperLink
'Children'
];

private static $cascade_duplicates = [
'Children'
];

private static $field_labels = [
'SubmenuMode' => 'Submenu',
'SubmenuSiteTree' => 'Select Page'
Expand Down Expand Up @@ -303,33 +309,62 @@ public function CMSEditLink()

public function canView($member = null)
{
if ($this->ParentID) {
return $this->Parent()->canView($member);
$can = Permission::checkMember($member, 'MANAGE_MENUITEMS');
if ($can) {
if ($this->ParentID) {
$can = $this->Parent()->canView($member, $context);
}
}
return $this->MenuSet()->canView($member);
return $can;
}

public function canEdit($member = null)
{
if ($this->ParentID) {
return $this->Parent()->canEdit($member);
$can = Permission::checkMember($member, 'MANAGE_MENUITEMS');
if ($can) {
if ($this->ParentID) {
$can = $this->Parent()->canEdit($member, $context);
}
}
return $this->MenuSet()->canEdit($member);
return $can;
}

public function canDelete($member = null)
{
if ($this->ParentID) {
return $this->Parent()->canDelete($member);
$can = Permission::checkMember($member, 'DELETE_MENUITEMS');
if ($can) {
if ($this->ParentID) {
$can = $this->Parent()->canDelete($member, $context);
}
}
return $this->MenuSet()->canDelete($member);
return $can;
}

public function canCreate($member = null, $context = [])
{
if ($this->ParentID) {
return $this->Parent()->canCreate($member, $context);
$can = Permission::checkMember($member, 'CREATE_MENUITEMS');
if ($can) {
if ($this->ParentID) {
$can = $this->Parent()->canCreate($member, $context);
}
}
return $this->MenuSet()->canEdit($member);
return $can;
}

public function providePermissions() {
return [
'MANAGE_MENUITEMS' => array(
'name' => 'Manage menu items',
'category' => 'Menus',
),
'CREATE_MENUITEMS' => array(
'name' => 'Create menu items',
'category' => 'Menus',
),
'DELETE_MENUITEMS' => array(
'name' => 'Delete menu items',
'category' => 'Menus',
)
];
}
}
45 changes: 34 additions & 11 deletions src/Model/MenuSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Permission;
use SilverStripe\Security\PermissionProvider;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\SSViewer;
use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;

class MenuSet extends DataObject
class MenuSet extends DataObject implements PermissionProvider
{
private static $table_name = 'MenuSet';
private static $singular_name = 'Menu';
Expand Down Expand Up @@ -60,6 +62,10 @@ class MenuSet extends DataObject
'Items'
];

private static $cascade_duplicates = [
'Items'
];

private static $defaults = [
'IsTitleEnabled' => false,
'IsHighlightEnabled' => false,
Expand Down Expand Up @@ -444,29 +450,46 @@ public function getCMSFields()

public function canCreate($member = null, $context = null)
{
return false;
return Permission::checkMember($member, 'CREATE_MENUSETS');
}

public function canDelete($member = null)
{
return false;
return Permission::checkMember($member, 'DELETE_MENUSETS');
}

public function canEdit($member = null)
{
$can = $this->Parent()->canEdit($member);
if ($can === false) {
return false;
$can = Permission::checkMember($member, 'MANAGE_MENUSETS');
if ($can) {
$can = $this->Parent()->canEdit($member);
}
return parent::canEdit($member);
return $can;
}

public function canView($member = null)
{
$can = $this->Parent()->canView($member);
if ($can === false) {
return false;
$can = Permission::checkMember($member, 'MANAGE_MENUSETS');
if ($can) {
$can = $this->Parent()->canView($member);
}
return parent::canView($member);
return $can;
}

public function providePermissions() {
return [
'MANAGE_MENUSETS' => array(
'name' => 'Manage menu sets',
'category' => 'Menus',
),
'CREATE_MENUSETS' => array(
'name' => 'Create menu sets',
'category' => 'Menus',
),
'DELETE_MENUSETS' => array(
'name' => 'Delete menu sets',
'category' => 'Menus',
)
];
}
}

0 comments on commit 3af29c7

Please sign in to comment.