Skip to content

Commit 3baacdc

Browse files
committed
Included checking permissions like in Advanced Object Search grid.
1 parent bc4438f commit 3baacdc

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

src/ClassificationTreeBundle/Service/ClassificationTreeBuilder.php

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Divante\ClassificationTreeBundle\Service;
99

1010
use AdvancedObjectSearchBundle\Service;
11+
use Pimcore\Bundle\AdminBundle\Security\User\TokenStorageUserResolver;
1112
use Pimcore\Db;
1213
use Pimcore\Logger;
1314
use Pimcore\Model\DataObject\ClassDefinition;
@@ -27,6 +28,9 @@ class ClassificationTreeBuilder
2728
/** @var StoreConfig\Listing $storeConfigListing */
2829
private $storeConfigListing;
2930

31+
/** @var TokenStorageUserResolver */
32+
protected $tokenStorageResolver;
33+
3034
/**
3135
* ClassificationTreeBuilder constructor.
3236
* @param Service $searchService
@@ -274,7 +278,29 @@ public function getProductsFromGroup($nodeName, $classificationName, $limit = 30
274278
return ['results' => [], 'totalCount' => 0];
275279
}
276280

277-
$list->setCondition("o_id IN (" . implode(",", $ids) . ")");
281+
$conditionFilters = [];
282+
if (!$this->getAdminUser()->isAdmin()) {
283+
$userIds = $this->getAdminUser()->getRoles();
284+
$userIds[] = $this->getAdminUser()->getId();
285+
$userIdsAsString = implode(',', $userIds);
286+
$conditionFilters[] =
287+
<<<EOD
288+
(
289+
(
290+
select list from users_workspaces_object where userId in ($userIdsAsString)
291+
AND LOCATE(CONCAT(o_path,o_key),cpath)=1 ORDER BY LENGTH(cpath) DESC LIMIT 1
292+
)=1
293+
OR
294+
(
295+
select list from users_workspaces_object where userId in ($userIdsAsString)
296+
AND LOCATE(cpath,CONCAT(o_path,o_key))=1 ORDER BY LENGTH(cpath) DESC LIMIT 1
297+
)=1
298+
)
299+
EOD;
300+
}
301+
302+
$conditionFilters[] = "o_id IN (" . implode(",", $ids) . ")";
303+
$list->setCondition(implode(" AND ", $conditionFilters));
278304
$list->setOrderKey(" FIELD(o_id, " . implode(",", $ids) . ")", false);
279305
$list->load();
280306
$result = [];
@@ -390,4 +416,21 @@ protected function getPermission(bool $isProduct = false)
390416
"unlock" => false,
391417
];
392418
}
419+
420+
/**
421+
* @return \Pimcore\Model\User|null
422+
*/
423+
protected function getAdminUser()
424+
{
425+
return $this->tokenStorageResolver->getUser();
426+
}
427+
428+
/**
429+
* @required
430+
* @param TokenStorageUserResolver $tokenStorageResolver
431+
*/
432+
public function setTokenStorageResolver(TokenStorageUserResolver $tokenStorageResolver): void
433+
{
434+
$this->tokenStorageResolver = $tokenStorageResolver;
435+
}
393436
}

0 commit comments

Comments
 (0)