‪TYPO3CMS  10.4
FolderMountsRestriction.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
27 
33 {
37  private ‪$backendUser;
38 
43 
45  {
46  $this->backendUser = ‪$backendUser;
47  $this->‪populateRestrictions();
48  }
49 
50  private function ‪populateRestrictions(): void
51  {
52  if ($this->backendUser->isAdmin()) {
53  return;
54  }
55  foreach ($this->‪getFolderMounts() as $folder) {
56  $this->‪add(new ‪FolderRestriction($folder, true));
57  }
58  }
59 
67  public function ‪buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder): CompositeExpression
68  {
69  if (!$this->backendUser->isAdmin() && empty($this->‪getFolderMounts())) {
70  // If the user isn't an admin but has no mounted folders, add an expression leading to an empty result
71  return $expressionBuilder->andX('1=0');
72  }
73  $constraints = [];
74  foreach ($this->restrictions as $restriction) {
75  $constraints[] = $restriction->buildExpression($queriedTables, $expressionBuilder);
76  }
77  return $expressionBuilder->orX(...$constraints);
78  }
79 
83  private function ‪getFolderMounts(): array
84  {
85  if ($this->folderMounts !== null) {
87  }
88  $this->folderMounts = [];
89  $fileMounts = $this->backendUser->getFileMountRecords();
90  foreach ($fileMounts as $fileMount) {
91  $this->folderMounts[] = GeneralUtility::makeInstance(ResourceFactory::class)->getFolderObjectFromCombinedIdentifier($fileMount['base'] . ':' . $fileMount['path']);
92  }
93 
95  }
96 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:35
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\$folderMounts
‪Folder[] null $folderMounts
Definition: FolderMountsRestriction.php:40
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\populateRestrictions
‪populateRestrictions()
Definition: FolderMountsRestriction.php:48
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\add
‪QueryRestrictionContainerInterface add(QueryRestrictionInterface $restriction)
Definition: AbstractRestrictionContainer.php:83
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\getFolderMounts
‪Folder[] getFolderMounts()
Definition: FolderMountsRestriction.php:81
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:25
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\andX
‪CompositeExpression andX(... $expressions)
Definition: ExpressionBuilder.php:70
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\orX
‪CompositeExpression orX(... $expressions)
Definition: ExpressionBuilder.php:82
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions
Definition: ConsistencyRestriction.php:18
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: FolderMountsRestriction.php:65
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer
Definition: AbstractRestrictionContainer.php:28
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction
Definition: FolderMountsRestriction.php:33
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderRestriction
Definition: FolderRestriction.php:30
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\$backendUser
‪BackendUserAuthentication $backendUser
Definition: FolderMountsRestriction.php:36
‪TYPO3\CMS\Core\Resource\Search\QueryRestrictions\FolderMountsRestriction\__construct
‪__construct(BackendUserAuthentication $backendUser)
Definition: FolderMountsRestriction.php:42