Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3 #59

Merged
merged 3 commits into from
Jul 10, 2023
Merged

3 #59

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,10 @@ class MenuItem extends DataObject implements PermissionProvider
*/
private static string $table_name = 'MenuItem';

/**
* @var array
*/
private static array $db = [
// If you want to customise the MenuTitle use this field - leaving blank will use MenuTitle of associated Page
'MenuTitle' => 'Varchar(255)',
// This field is used for external links (picking a page from the dropdown will overwrite this link)
'Link' => 'Text',
// Sort order
'Sort' => 'Int',
// Can be used as a check for adding target="_blank"
'IsNewWindow' => 'Boolean'
];

Expand Down Expand Up @@ -84,7 +77,13 @@ public function providePermissions(): array
*/
public function canCreate($member = null, $context = []): bool
{
return Permission::check('MANAGE_MENU_ITEMS');
$extended = $this->extendedCan(__FUNCTION__, $member);

if ($extended !== null) {
return $extended;
}

return Permission::checkMember($member, 'MANAGE_MENU_ITEMS');
}

/**
Expand All @@ -93,6 +92,12 @@ public function canCreate($member = null, $context = []): bool
*/
public function canDelete($member = null): bool
{
$extended = $this->extendedCan(__FUNCTION__, $member);

if ($extended !== null) {
return $extended;
}

return Permission::check('MANAGE_MENU_ITEMS');
}

Expand All @@ -102,6 +107,12 @@ public function canDelete($member = null): bool
*/
public function canEdit($member = null): bool
{
$extended = $this->extendedCan(__FUNCTION__, $member);

if ($extended !== null) {
return $extended;
}

return Permission::check('MANAGE_MENU_ITEMS');
}

Expand All @@ -111,6 +122,12 @@ public function canEdit($member = null): bool
*/
public function canView($member = null): bool
{
$extended = $this->extendedCan(__FUNCTION__, $member);

if ($extended !== null) {
return $extended;
}

return Permission::check('MANAGE_MENU_ITEMS');
}

Expand Down
32 changes: 17 additions & 15 deletions src/MenuSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ public function validate()
*/
public function canCreate($member = null, $context = []): bool
{
if (Permission::check('MANAGE_MENU_SETS')) {
return true;
$extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) {
return $extended;
}

return parent::canCreate($member, $context);
return Permission::check('MANAGE_MENU_SETS');
}

/**
Expand All @@ -104,19 +105,17 @@ public function canCreate($member = null, $context = []): bool
*/
public function canDelete($member = null): bool
{
$canDelete = parent::canDelete($member);

// Backwards compatibility for duplicate default sets
$existing = MenuManagerTemplateProvider::MenuSet($this->Name);
$isDuplicate = $existing && $existing->ID !== $this->ID;

if ($this->isDefaultSet() && !$isDuplicate) {
// Default menu's cannot be deleted
$canDelete = false;
return false;
}

if ($canDelete !== null) {
return $canDelete;
$extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) {
return $extended;
}

return Permission::check('MANAGE_MENU_SETS');
Expand All @@ -128,11 +127,12 @@ public function canDelete($member = null): bool
*/
public function canEdit($member = null): bool
{
if (Permission::check('MANAGE_MENU_SETS') || Permission::check('MANAGE_MENU_ITEMS')) {
return true;
$extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) {
return $extended;
}

return parent::canEdit($member);
return (Permission::check('MANAGE_MENU_SETS') || Permission::check('MANAGE_MENU_ITEMS'));
}

/**
Expand All @@ -141,11 +141,13 @@ public function canEdit($member = null): bool
*/
public function canView($member = null): bool
{
if (Permission::check('MANAGE_MENU_SETS') || Permission::check('MANAGE_MENU_ITEMS')) {
return true;
$extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) {
return $extended;
}

return parent::canView($member);

return (Permission::check('MANAGE_MENU_SETS') || Permission::check('MANAGE_MENU_ITEMS'));
}


Expand Down