‪TYPO3CMS  9.5
FolderMountsRestriction.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
24 
30 {
34  private ‪$backendUser;
35 
40 
42  {
43  $this->backendUser = ‪$backendUser;
44  $this->‪populateRestrictions();
45  }
46 
47  private function ‪populateRestrictions(): void
48  {
49  if ($this->backendUser->isAdmin()) {
50  return;
51  }
52  foreach ($this->‪getFolderMounts() as $folder) {
53  $this->‪add(new ‪FolderRestriction($folder, true));
54  }
55  }
56 
64  public function ‪buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder): CompositeExpression
65  {
66  if (!$this->backendUser->isAdmin() && empty($this->‪getFolderMounts())) {
67  // If the user isn't an admin but has no mounted folders, add an expression leading to an empty result
68  return $expressionBuilder->andX('1=0');
69  }
70  $constraints = [];
71  foreach ($this->restrictions as $restriction) {
72  $constraints[] = $restriction->buildExpression($queriedTables, $expressionBuilder);
73  }
74  return $expressionBuilder->orX(...$constraints);
75  }
76 
80  private function ‪getFolderMounts(): array
81  {
82  if ($this->folderMounts !== null) {
84  }
85  $this->folderMounts = [];
86  $fileMounts = $this->backendUser->getFileMountRecords();
87  foreach ($fileMounts as $fileMount) {
88  $this->folderMounts[] = ‪ResourceFactory::getInstance()->‪getFolderObjectFromCombinedIdentifier($fileMount['base'] . ':' . $fileMount['path']);
89  }
90 
92  }
93 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:33
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\$folderMounts
‪Folder[] null $folderMounts
Definition: FolderMountsRestriction.php:37
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\populateRestrictions
‪populateRestrictions()
Definition: FolderMountsRestriction.php:45
‪TYPO3\CMS\Core\Resource\ResourceFactory\getFolderObjectFromCombinedIdentifier
‪Folder getFolderObjectFromCombinedIdentifier($identifier)
Definition: ResourceFactory.php:539
‪TYPO3\CMS\Core\Resource\ResourceFactory\getInstance
‪static ResourceFactory getInstance()
Definition: ResourceFactory.php:39
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\add
‪QueryRestrictionContainerInterface add(QueryRestrictionInterface $restriction)
Definition: AbstractRestrictionContainer.php:81
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\getFolderMounts
‪Folder[] getFolderMounts()
Definition: FolderMountsRestriction.php:78
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:23
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\andX
‪CompositeExpression andX(... $expressions)
Definition: ExpressionBuilder.php:68
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:34
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:33
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\orX
‪CompositeExpression orX(... $expressions)
Definition: ExpressionBuilder.php:80
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions
Definition: ConsistencyRestriction.php:3
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: FolderMountsRestriction.php:62
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer
Definition: AbstractRestrictionContainer.php:26
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction
Definition: FolderMountsRestriction.php:30
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderRestriction
Definition: FolderRestriction.php:28
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\$backendUser
‪BackendUserAuthentication $backendUser
Definition: FolderMountsRestriction.php:33
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\__construct
‪__construct(BackendUserAuthentication $backendUser)
Definition: FolderMountsRestriction.php:39