TYPO3  7.6
StoragePermissionsAspect.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Resource\Security;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 use TYPO3\CMS\Core\Resource\Exception\FolderDoesNotExistException;
21 
33 {
38 
42  protected $defaultStorageZeroPermissions = array(
43  'readFolder' => true,
44  'readFile' => true
45  );
46 
47 
51  public function __construct($backendUserAuthentication = null)
52  {
53  $this->backendUserAuthentication = $backendUserAuthentication ?: $GLOBALS['BE_USER'];
54  }
55 
63  public function addUserPermissionsToStorage(ResourceFactory $resourceFactory, ResourceStorage $storage)
64  {
65  if (!$this->backendUserAuthentication->isAdmin()) {
66  $storage->setEvaluatePermissions(true);
67  if ($storage->getUid() > 0) {
68  $storage->setUserPermissions($this->backendUserAuthentication->getFilePermissionsForStorage($storage));
69  } else {
70  $storage->setEvaluatePermissions(false);
71  }
72  $this->addFileMountsToStorage($storage);
73  }
74  }
75 
82  protected function addFileMountsToStorage(ResourceStorage $storage)
83  {
84  foreach ($this->backendUserAuthentication->getFileMountRecords() as $fileMountRow) {
85  if ((int)$fileMountRow['base'] === (int)$storage->getUid()) {
86  try {
87  $storage->addFileMount($fileMountRow['path'], $fileMountRow);
88  } catch (FolderDoesNotExistException $e) {
89  // That file mount does not seem to be valid, fail silently
90  }
91  }
92  }
93  }
94 }