Skip to content

Commit

Permalink
Merge pull request silverstripe#265 from creative-commoners/pulls/3.0…
Browse files Browse the repository at this point in the history
…/unsaved-fix

FIX Do not try and filter unsaved lists when determining canView permissions
  • Loading branch information
ScopeyNZ authored Jul 18, 2018
2 parents 2d10763 + 85c2e68 commit 5334f57
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Models/ElementalArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use SilverStripe\ORM\FieldType\DBField;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\HasManyList;
use SilverStripe\ORM\UnsavedRelationList;
use SilverStripe\Versioned\Versioned;

/**
Expand Down Expand Up @@ -108,6 +109,11 @@ public function Breadcrumbs()
*/
public function ElementControllers()
{
// Don't try and process unsaved lists
if ($this->Elements() instanceof UnsavedRelationList) {
return ArrayList::create();
}

$controllers = ArrayList::create();
$items = $this->Elements()->filterByCallback(function (BaseElement $item) {
return $item->canView();
Expand Down
16 changes: 16 additions & 0 deletions tests/ElementalAreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use DNADesign\Elemental\Extensions\ElementalPageExtension;
use DNADesign\Elemental\Models\ElementalArea;
use DNADesign\Elemental\Models\ElementContent;
use DNADesign\Elemental\Tests\Src\TestElement;
use DNADesign\Elemental\Tests\Src\TestPage;
use Page;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Versioned\Versioned;

class ElementalAreaTest extends SapphireTest
Expand Down Expand Up @@ -116,4 +118,18 @@ public function testDuplicate()
$this->assertCount(2, $duplicatedAreaIds);
$this->assertNotEquals($areaIds, $duplicatedAreaIds);
}

public function testUnsavedRelationListOfElementsReturnsEmptyArrayList()
{
$area = new ElementalArea();

$element = new ElementContent();
$element->HTML = 'Test';

$area->Elements()->add($element);

$result = $area->ElementControllers();
$this->assertInstanceOf(ArrayList::class, $result);
$this->assertEmpty($result);
}
}

0 comments on commit 5334f57

Please sign in to comment.