/** * Check if a file has the permission to be copied on a File/Folder/Storage, * if not throw an exception * * @param FolderInterface $folderToMove * @param FolderInterface $targetParentFolder * * @throws \InvalidArgumentException * @throws Exception\InsufficientFolderWritePermissionsException * @throws Exception\IllegalFileExtensionException * @throws Exception\InsufficientFileReadPermissionsException * @throws Exception\InsufficientUserPermissionsException * @throws \RuntimeException * @return void */ protected function assureFolderMovePermissions(FolderInterface $folderToMove, FolderInterface $targetParentFolder) { // Check if targetFolder is within this storage, this should never happen if ($this->getUid() !== $targetParentFolder->getStorage()->getUid()) { throw new \InvalidArgumentException('Cannot move a folder into a folder that does not belong to this storage.', 1325777289); } if (!$folderToMove instanceof Folder) { throw new \RuntimeException('The folder "' . $folderToMove->getIdentifier() . '" to move is not of type Folder.', 1384209022); } // Check if user is allowed to move and the folder is writable // In fact we would need to check if the parent folder of the folder to move is writable also // But as of now we cannot extract the parent folder from this folder if (!$folderToMove->getStorage()->checkFolderActionPermission('move', $folderToMove)) { throw new Exception\InsufficientFileReadPermissionsException('You are not allowed to copy the folder "' . $folderToMove->getIdentifier() . '"', 1377778045); } if (!$targetParentFolder instanceof Folder) { throw new \RuntimeException('The target folder "' . $targetParentFolder->getIdentifier() . '" is not of type Folder.', 1384209023); } // Check if targetFolder is writable if (!$this->checkFolderActionPermission('write', $targetParentFolder)) { throw new Exception\InsufficientFolderWritePermissionsException('You are not allowed to write to the target folder "' . $targetParentFolder->getIdentifier() . '"', 1377778049); } }