Skip to content

Commit

Permalink
Refactor permission handling in asset folder content preview.
Browse files Browse the repository at this point in the history
  • Loading branch information
cuca24 committed Dec 26, 2024
1 parent 01789a3 commit 4dd1e92
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
19 changes: 7 additions & 12 deletions src/Controller/Admin/Asset/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,10 @@ public function imageEditorSaveAction(Request $request): JsonResponse
/**
* @Route("/get-folder-content-preview", name="pimcore_admin_asset_getfoldercontentpreview", methods={"GET"})
*/
public function getFolderContentPreviewAction(Request $request, EventDispatcherInterface $eventDispatcher): JsonResponse
/**
* @Route("/get-folder-content-preview", name="pimcore_admin_asset_getfoldercontentpreview", methods={"GET"})
*/
public function getFolderContentPreviewAction(Request $request, EventDispatcherInterface $eventDispatcher, GridHelperService $gridHelperService): JsonResponse
{
$allParams = array_merge($request->request->all(), $request->query->all());

Expand All @@ -1685,18 +1688,10 @@ public function getFolderContentPreviewAction(Request $request, EventDispatcherI
$list = new Asset\Listing();
$conditionFilters[] = '`path` LIKE ' . ($folder->getRealFullPath() == '/' ? "'/%'" : $list->quote(Helper::escapeLike($folder->getRealFullPath()) . '/%')) . " AND `type` != 'folder'";

if (!$this->getAdminUser()->isAdmin()) {
$userIds = $this->getAdminUser()->getRoles();
$currentUserId = $this->getAdminUser()->getId();
$userIds[] = $currentUserId;

$inheritedPermission = $folder->getDao()->isInheritingPermission('list', $userIds);

$anyAllowedRowOrChildren = 'EXISTS(SELECT list FROM users_workspaces_asset uwa WHERE userId IN (' . implode(',', $userIds) . ') AND list=1 AND LOCATE(CONCAT(`path`,filename),cpath)=1 AND
NOT EXISTS(SELECT list FROM users_workspaces_asset WHERE userId =' . $currentUserId . ' AND list=0 AND cpath = uwa.cpath))';
$isDisallowedCurrentRow = 'EXISTS(SELECT list FROM users_workspaces_asset WHERE userId IN (' . implode(',', $userIds) . ') AND cid = id AND list=0)';
$adminUser = $this->getAdminUser();

$conditionFilters[] = 'IF(' . $anyAllowedRowOrChildren . ',1,IF(' . $inheritedPermission . ', ' . $isDisallowedCurrentRow . ' = 0, 0)) = 1';
if (!$adminUser->isAdmin()) {
$conditionFilters[] = $gridHelperService->getPermittedPathsByUser('asset', $adminUser);
}

$condition = implode(' AND ', $conditionFilters);
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/GridHelperService.php
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ private function optimizedConcatNotLike(
*
* @internal
*/
protected function getPermittedPathsByUser(string $type, User $user): string
public function getPermittedPathsByUser(string $type, User $user): string
{
$allowedTypes = [];

Expand Down

0 comments on commit 4dd1e92

Please sign in to comment.