From f0e851cbfb58a16fd50635b489adc46f318fde8c Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Tue, 15 Dec 2020 11:08:13 +1100 Subject: [PATCH 1/4] fix use statements --- src/Model/MenuItem.php | 7 +++---- src/Model/MenuItemSiteTree.php | 3 --- src/Model/MenuSet.php | 11 ++++++----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Model/MenuItem.php b/src/Model/MenuItem.php index 25d3a5a..6490bfc 100644 --- a/src/Model/MenuItem.php +++ b/src/Model/MenuItem.php @@ -8,6 +8,9 @@ use SilverStripe\Control\Controller; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\FieldGroup; +use SilverStripe\Forms\HeaderField; +use SilverStripe\Forms\OptionsetField; +use SilverStripe\Forms\TreeDropdownField; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; use SilverStripe\Forms\GridField\GridFieldAddNewButton; @@ -15,10 +18,6 @@ use SilverStripe\Forms\GridField\GridFieldPageCount; use SilverStripe\Forms\GridField\GridFieldPaginator; use SilverStripe\Forms\GridField\GridFieldToolbarHeader; -use SilverStripe\Forms\HeaderField; -use SilverStripe\Forms\OptionsetField; -use SilverStripe\Forms\Tab; -use SilverStripe\Forms\TreeDropdownField; use SilverStripe\Versioned\Versioned; use Symbiote\GridFieldExtensions\GridFieldAddNewMultiClass; use Symbiote\GridFieldExtensions\GridFieldOrderableRows; diff --git a/src/Model/MenuItemSiteTree.php b/src/Model/MenuItemSiteTree.php index dc6b3b0..7406a45 100644 --- a/src/Model/MenuItemSiteTree.php +++ b/src/Model/MenuItemSiteTree.php @@ -3,9 +3,6 @@ namespace Fromholdio\SuperLinkerMenus\Model; use Fromholdio\SuperLinker\Extensions\SiteTreeLink; -use SilverStripe\Forms\CheckboxField; -use SilverStripe\Forms\FieldGroup; -use UncleCheese\DisplayLogic\Forms\Wrapper; class MenuItemSiteTree extends MenuItem { diff --git a/src/Model/MenuSet.php b/src/Model/MenuSet.php index 5d8ddcb..9cd3e0b 100644 --- a/src/Model/MenuSet.php +++ b/src/Model/MenuSet.php @@ -8,6 +8,11 @@ use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Config\Config; use SilverStripe\Forms\FieldList; +use SilverStripe\Forms\HeaderField; +use SilverStripe\Forms\HiddenField; +use SilverStripe\Forms\Tab; +use SilverStripe\Forms\TabSet; +use SilverStripe\Forms\TextField; use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; use SilverStripe\Forms\GridField\GridFieldAddNewButton; @@ -15,11 +20,7 @@ use SilverStripe\Forms\GridField\GridFieldPageCount; use SilverStripe\Forms\GridField\GridFieldPaginator; use SilverStripe\Forms\GridField\GridFieldToolbarHeader; -use SilverStripe\Forms\HeaderField; -use SilverStripe\Forms\HiddenField; -use SilverStripe\Forms\Tab; -use SilverStripe\Forms\TabSet; -use SilverStripe\Forms\TextField; +use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\DataObject; use SilverStripe\Versioned\Versioned; use SilverStripe\View\SSViewer; From 6c5b67baf5905ffe9493421766e193366d7ff9d7 Mon Sep 17 00:00:00 2001 From: Florian Thoma Date: Tue, 23 Mar 2021 12:45:04 +1100 Subject: [PATCH 2/4] add cascade_duplicates to relations --- src/Extensions/MenuSetParentExtension.php | 4 ++++ src/Model/MenuItem.php | 4 ++++ src/Model/MenuSet.php | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/Extensions/MenuSetParentExtension.php b/src/Extensions/MenuSetParentExtension.php index 59b5672..0af1c1e 100644 --- a/src/Extensions/MenuSetParentExtension.php +++ b/src/Extensions/MenuSetParentExtension.php @@ -31,6 +31,10 @@ class MenuSetParentExtension extends DataExtension 'MenuSets' ]; + private static $cascade_duplicates = [ + 'MenuSets' + ]; + public function updateCMSFields(FieldList $fields) { $fields->removeByName('MenuSets'); diff --git a/src/Model/MenuItem.php b/src/Model/MenuItem.php index 25d3a5a..2d06e47 100644 --- a/src/Model/MenuItem.php +++ b/src/Model/MenuItem.php @@ -70,6 +70,10 @@ class MenuItem extends SuperLink 'Children' ]; + private static $cascade_duplicates = [ + 'Children' + ]; + private static $field_labels = [ 'SubmenuMode' => 'Submenu', 'SubmenuSiteTree' => 'Select Page' diff --git a/src/Model/MenuSet.php b/src/Model/MenuSet.php index 5d8ddcb..5c36395 100644 --- a/src/Model/MenuSet.php +++ b/src/Model/MenuSet.php @@ -59,6 +59,10 @@ class MenuSet extends DataObject 'Items' ]; + private static $cascade_duplicates = [ + 'Items' + ]; + private static $defaults = [ 'IsTitleEnabled' => false, 'IsHighlightEnabled' => false, From 60b3d218536424ae274bd049fd3fa1ea18f1be41 Mon Sep 17 00:00:00 2001 From: Luke Fromhold Date: Tue, 29 Jun 2021 23:01:01 +1000 Subject: [PATCH 3/4] Add cascade_duplicates config --- src/Model/MenuItem.php | 4 ++++ src/Model/MenuSet.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/Model/MenuItem.php b/src/Model/MenuItem.php index 25d3a5a..2d06e47 100644 --- a/src/Model/MenuItem.php +++ b/src/Model/MenuItem.php @@ -70,6 +70,10 @@ class MenuItem extends SuperLink 'Children' ]; + private static $cascade_duplicates = [ + 'Children' + ]; + private static $field_labels = [ 'SubmenuMode' => 'Submenu', 'SubmenuSiteTree' => 'Select Page' diff --git a/src/Model/MenuSet.php b/src/Model/MenuSet.php index 5d8ddcb..5c36395 100644 --- a/src/Model/MenuSet.php +++ b/src/Model/MenuSet.php @@ -59,6 +59,10 @@ class MenuSet extends DataObject 'Items' ]; + private static $cascade_duplicates = [ + 'Items' + ]; + private static $defaults = [ 'IsTitleEnabled' => false, 'IsHighlightEnabled' => false, From 7f510aa4d366cb40e2a4f73bca9aa3b010eb9400 Mon Sep 17 00:00:00 2001 From: Luke Fromhold Date: Sun, 4 Jul 2021 00:17:30 +1000 Subject: [PATCH 4/4] Improve permissions flexibility --- src/Model/MenuItem.php | 57 ++++++++++++++++++++++++++++++++---------- src/Model/MenuSet.php | 41 ++++++++++++++++++++++-------- 2 files changed, 74 insertions(+), 24 deletions(-) diff --git a/src/Model/MenuItem.php b/src/Model/MenuItem.php index 2d06e47..6b117fb 100644 --- a/src/Model/MenuItem.php +++ b/src/Model/MenuItem.php @@ -19,12 +19,14 @@ use SilverStripe\Forms\OptionsetField; use SilverStripe\Forms\Tab; use SilverStripe\Forms\TreeDropdownField; +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'; @@ -308,33 +310,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', + ) + ]; } } diff --git a/src/Model/MenuSet.php b/src/Model/MenuSet.php index 5c36395..5ca71a7 100644 --- a/src/Model/MenuSet.php +++ b/src/Model/MenuSet.php @@ -21,12 +21,14 @@ use SilverStripe\Forms\TabSet; use SilverStripe\Forms\TextField; 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'; @@ -447,29 +449,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', + ) + ]; } }