mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #271 from halkyon/group_changes
BUGFIX Nested Group records should be removed, along with the parent.
This commit is contained in:
commit
d0d23dc591
@ -338,12 +338,16 @@ class Group extends DataObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAfterDelete() {
|
function onBeforeDelete() {
|
||||||
parent::onAfterDelete();
|
parent::onBeforeDelete();
|
||||||
|
|
||||||
|
// if deleting this group, delete it's children as well
|
||||||
|
foreach($this->Groups() as $group) {
|
||||||
|
$group->delete();
|
||||||
|
}
|
||||||
|
|
||||||
// Delete associated permissions
|
// Delete associated permissions
|
||||||
$permissions = $this->Permissions();
|
foreach($this->Permissions() as $permission) {
|
||||||
foreach ( $permissions as $permission ) {
|
|
||||||
$permission->delete();
|
$permission->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,15 +94,6 @@ class GroupTest extends FunctionalTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDelete() {
|
|
||||||
$adminGroup = $this->objFromFixture('Group', 'admingroup');
|
|
||||||
|
|
||||||
$adminGroup->delete();
|
|
||||||
|
|
||||||
$this->assertEquals(0, DataObject::get('Group', "\"ID\"={$adminGroup->ID}")->count(), 'Group is removed');
|
|
||||||
$this->assertEquals(0, DataObject::get('Permission',"\"GroupID\"={$adminGroup->ID}")->count(), 'Permissions removed along with the group');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCollateAncestorIDs() {
|
function testCollateAncestorIDs() {
|
||||||
$parentGroup = $this->objFromFixture('Group', 'parentgroup');
|
$parentGroup = $this->objFromFixture('Group', 'parentgroup');
|
||||||
$childGroup = $this->objFromFixture('Group', 'childgroup');
|
$childGroup = $this->objFromFixture('Group', 'childgroup');
|
||||||
@ -128,6 +119,19 @@ class GroupTest extends FunctionalTest {
|
|||||||
'Orphaned nodes dont contain invalid parent IDs'
|
'Orphaned nodes dont contain invalid parent IDs'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDelete() {
|
||||||
|
$group = $this->objFromFixture('Group', 'parentgroup');
|
||||||
|
$groupID = $group->ID;
|
||||||
|
$childGroupID = $this->idFromFixture('Group', 'childgroup');
|
||||||
|
$group->delete();
|
||||||
|
|
||||||
|
$this->assertEquals(0, DataObject::get('Group', "\"ID\" = {$groupID}")->Count(), 'Group is removed');
|
||||||
|
$this->assertEquals(0, DataObject::get('Permission', "\"GroupID\" = {$groupID}")->Count(), 'Permissions removed along with the group');
|
||||||
|
$this->assertEquals(0, DataObject::get('Group', "\"ParentID\" = {$groupID}")->Count(), 'Child groups are removed');
|
||||||
|
$this->assertEquals(0, DataObject::get('Group', "\"ParentID\" = {$childGroupID}")->Count(), 'Grandchild groups are removed');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class GroupTest_Member extends Member implements TestOnly {
|
class GroupTest_Member extends Member implements TestOnly {
|
||||||
|
@ -6,6 +6,9 @@ Group:
|
|||||||
childgroup:
|
childgroup:
|
||||||
Code: childgroup
|
Code: childgroup
|
||||||
Parent: =>Group.parentgroup
|
Parent: =>Group.parentgroup
|
||||||
|
grandchildgroup:
|
||||||
|
Code: grandchildgroup
|
||||||
|
Parent: =>Group.childgroup
|
||||||
group1:
|
group1:
|
||||||
Title: Group 1
|
Title: Group 1
|
||||||
group2:
|
group2:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user