FIX Correctly decode page type blacklist from JSON

This commit is contained in:
Robbie Averill 2018-03-15 16:34:13 +13:00
parent 8398a361cd
commit afd23be64c
2 changed files with 6 additions and 8 deletions

View File

@ -19,6 +19,7 @@ use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataQuery; use SilverStripe\ORM\DataQuery;
use SilverStripe\ORM\Queries\SQLSelect; use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security; use SilverStripe\Security\Security;
use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
@ -478,20 +479,17 @@ class SiteTreeSubsites extends DataExtension
} }
/** /**
* @param Member * @param Member $member
* @return boolean|null * @return boolean|null
*/ */
public function canCreate($member = null) public function canCreate($member = null)
{ {
// Typically called on a singleton, so we're not using the Subsite() relation // Typically called on a singleton, so we're not using the Subsite() relation
$subsite = Subsite::currentSubsite(); $subsite = Subsite::currentSubsite();
if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) { if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) {
$blacklist = str_replace(['[', '"', ']'], '', $subsite->PageTypeBlacklist); $blacklist = Convert::json2array($subsite->PageTypeBlacklist) ?: [];
$blacklist = str_replace(['\\\\'], '\\', $blacklist);
$blacklisted = explode(',', $blacklist);
if (in_array(get_class($this->owner), $blacklisted)) { if (in_array(get_class($this->owner), $blacklist)) {
return false; return false;
} }
} }

View File

@ -185,7 +185,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2'); $s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
$page = singleton(SiteTree::class); $page = singleton(SiteTree::class);
$s1->PageTypeBlacklist = implode(',', [TestClassA::class, ErrorPage::class]); $s1->PageTypeBlacklist = json_encode([TestClassA::class, ErrorPage::class]);
$s1->write(); $s1->write();
Subsite::changeSubsite($s1); Subsite::changeSubsite($s1);
@ -257,7 +257,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
$s1 = $this->objFromFixture(Subsite::class, 'domaintest1'); $s1 = $this->objFromFixture(Subsite::class, 'domaintest1');
$s2 = $this->objFromFixture(Subsite::class, 'domaintest2'); $s2 = $this->objFromFixture(Subsite::class, 'domaintest2');
$s1->PageTypeBlacklist = implode(',', [TestClassA::class, ErrorPage::class]); $s1->PageTypeBlacklist = json_encode([TestClassA::class, ErrorPage::class]);
$s1->write(); $s1->write();
Subsite::changeSubsite($s1); Subsite::changeSubsite($s1);