mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
parent
a92261cc9b
commit
53a0206b1d
@ -1155,7 +1155,8 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
|||||||
// Check parent (custom canCreate option for SiteTree)
|
// Check parent (custom canCreate option for SiteTree)
|
||||||
// Block children not allowed for this parent type
|
// Block children not allowed for this parent type
|
||||||
$parent = isset($context['Parent']) ? $context['Parent'] : null;
|
$parent = isset($context['Parent']) ? $context['Parent'] : null;
|
||||||
if ($parent && !in_array(static::class, $parent->allowedChildren())) {
|
$strictParentInstance = ($parent && $parent instanceof SiteTree);
|
||||||
|
if ($strictParentInstance && !in_array(static::class, $parent->allowedChildren())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1171,7 +1172,7 @@ class SiteTree extends DataObject implements PermissionProvider, i18nEntityProvi
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fall over to inherited permissions
|
// Fall over to inherited permissions
|
||||||
if ($parent && $parent->exists()) {
|
if ($strictParentInstance && $parent->exists()) {
|
||||||
return $parent->canAddChildren($member);
|
return $parent->canAddChildren($member);
|
||||||
} else {
|
} else {
|
||||||
// This doesn't necessarily mean we are creating a root page, but that
|
// This doesn't necessarily mean we are creating a root page, but that
|
||||||
|
@ -50,6 +50,7 @@ class SiteTreeTest extends SapphireTest
|
|||||||
SiteTreeTest_ClassCext::class,
|
SiteTreeTest_ClassCext::class,
|
||||||
SiteTreeTest_NotRoot::class,
|
SiteTreeTest_NotRoot::class,
|
||||||
SiteTreeTest_StageStatusInherit::class,
|
SiteTreeTest_StageStatusInherit::class,
|
||||||
|
SiteTreeTest_DataObject::class,
|
||||||
);
|
);
|
||||||
|
|
||||||
public function testCreateDefaultpages()
|
public function testCreateDefaultpages()
|
||||||
@ -632,6 +633,9 @@ class SiteTreeTest extends SapphireTest
|
|||||||
// Test creation underneath a parent which doesn't exist in the database. This should
|
// Test creation underneath a parent which doesn't exist in the database. This should
|
||||||
// fall back to checking whether the user can create pages at the root of the site
|
// fall back to checking whether the user can create pages at the root of the site
|
||||||
$this->assertTrue(singleton(SiteTree::class)->canCreate(null, array('Parent' => singleton(SiteTree::class))));
|
$this->assertTrue(singleton(SiteTree::class)->canCreate(null, array('Parent' => singleton(SiteTree::class))));
|
||||||
|
|
||||||
|
//Test we don't check for allowedChildren on parent context if it's not SiteTree instance
|
||||||
|
$this->assertTrue(singleton(SiteTree::class)->canCreate(null, ['Parent' => $this->objFromFixture('SiteTreeTest_DataObject', 'relations')]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testEditPermissionsOnDraftVsLive()
|
public function testEditPermissionsOnDraftVsLive()
|
||||||
|
@ -123,3 +123,8 @@ SilverStripe\CMS\Model\RedirectorPage:
|
|||||||
URLSegment: external
|
URLSegment: external
|
||||||
RedirectionType: External
|
RedirectionType: External
|
||||||
ExternalURL: "http://www.google.com?a&b"
|
ExternalURL: "http://www.google.com?a&b"
|
||||||
|
|
||||||
|
SiteTreeTest_DataObject:
|
||||||
|
relations:
|
||||||
|
Title: 'Linked DataObject'
|
||||||
|
Pages: =>Page.home,=>Page.about,=>Page.staff
|
28
tests/model/SiteTreeTest_DataObject.php
Normal file
28
tests/model/SiteTreeTest_DataObject.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
use SilverStripe\ORM\DataObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class SiteTreeTest_DataObject
|
||||||
|
*
|
||||||
|
* @property string $Title
|
||||||
|
* @method Pages[]|ManyManyList $Pages
|
||||||
|
*/
|
||||||
|
class SiteTreeTest_DataObject extends DataObject implements TestOnly
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $db = [
|
||||||
|
'Title' => 'Varchar',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private static $many_many = [
|
||||||
|
'Pages' => SiteTree::class,
|
||||||
|
];
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user