From d0149f899596103fefeb7d442d779c64c107ec7c Mon Sep 17 00:00:00 2001 From: Andreas Piening Date: Mon, 9 Apr 2018 11:20:34 +1200 Subject: [PATCH 1/2] FIX: add missing canView check in json --- src/DataFormatter/JSONDataFormatter.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/DataFormatter/JSONDataFormatter.php b/src/DataFormatter/JSONDataFormatter.php index cac7bda..b780874 100644 --- a/src/DataFormatter/JSONDataFormatter.php +++ b/src/DataFormatter/JSONDataFormatter.php @@ -106,6 +106,9 @@ class JSONDataFormatter extends DataFormatter if ($this->customRelations && !in_array($relName, $this->customRelations)) { continue; } + if ($obj->$relName() && (!$obj->$relName()->exists() || !$obj->$relName()->canView())) { + continue; + } $fieldName = $relName . 'ID'; $rel = $this->config()->api_base; @@ -140,6 +143,7 @@ class JSONDataFormatter extends DataFormatter $innerParts = array(); $items = $obj->$relName(); foreach ($items as $item) { + if (!$item->canView()) continue; $rel = $this->config()->api_base . $this->sanitiseClassName($relClass) . "/$item->ID"; $href = Director::absoluteURL($rel); $innerParts[] = ArrayData::array_to_object(array( From cbca821c9b8975270c2828c5b1068b00c9fc9605 Mon Sep 17 00:00:00 2001 From: Andreas Piening Date: Mon, 9 Apr 2018 11:27:20 +1200 Subject: [PATCH 2/2] FIX: comply with psr-2 --- src/DataFormatter/JSONDataFormatter.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/DataFormatter/JSONDataFormatter.php b/src/DataFormatter/JSONDataFormatter.php index b780874..cd4840c 100644 --- a/src/DataFormatter/JSONDataFormatter.php +++ b/src/DataFormatter/JSONDataFormatter.php @@ -143,7 +143,9 @@ class JSONDataFormatter extends DataFormatter $innerParts = array(); $items = $obj->$relName(); foreach ($items as $item) { - if (!$item->canView()) continue; + if (!$item->canView()) { + continue; + } $rel = $this->config()->api_base . $this->sanitiseClassName($relClass) . "/$item->ID"; $href = Director::absoluteURL($rel); $innerParts[] = ArrayData::array_to_object(array(