コード例 #1
0
ファイル: configadapter.php プロジェクト: GrumpyCrouton/core
 /**
  * Get all mountpoints applicable for the user
  *
  * @param \OCP\IUser $user
  * @param \OCP\Files\Storage\IStorageFactory $loader
  * @return \OCP\Files\Mount\IMountPoint[]
  */
 public function getMountsForUser(IUser $user, IStorageFactory $loader)
 {
     $mounts = [];
     $this->userStoragesService->setUser($user);
     $this->userGlobalStoragesService->setUser($user);
     foreach ($this->userGlobalStoragesService->getAllStorages() as $storage) {
         try {
             $this->prepareStorageConfig($storage, $user);
             $impl = $this->constructStorage($storage);
         } catch (\Exception $e) {
             // propagate exception into filesystem
             $impl = new FailedStorage(['exception' => $e]);
         }
         $mount = new MountPoint($impl, '/' . $user->getUID() . '/files' . $storage->getMountPoint(), null, $loader, $storage->getMountOptions());
         $mounts[$storage->getMountPoint()] = $mount;
     }
     foreach ($this->userStoragesService->getAllStorages() as $storage) {
         try {
             $this->prepareStorageConfig($storage, $user);
             $impl = $this->constructStorage($storage);
         } catch (\Exception $e) {
             // propagate exception into filesystem
             $impl = new FailedStorage(['exception' => $e]);
         }
         $mount = new PersonalMount($this->userStoragesService, $storage->getId(), $impl, '/' . $user->getUID() . '/files' . $storage->getMountPoint(), null, $loader, $storage->getMountOptions());
         $mounts[$storage->getMountPoint()] = $mount;
     }
     $this->userStoragesService->resetUser();
     $this->userGlobalStoragesService->resetUser();
     return $mounts;
 }
コード例 #2
0
 /**
  * @dataProvider applicableStorageProvider
  */
 public function testGetStorageWithApplicable($applicableUsers, $applicableGroups, $isVisible)
 {
     $backend = $this->backendService->getBackend('identifier:\\OCA\\Files_External\\Lib\\Backend\\SMB');
     $authMechanism = $this->backendService->getAuthMechanism('identifier:\\Auth\\Mechanism');
     $storage = new StorageConfig();
     $storage->setMountPoint('mountpoint');
     $storage->setBackend($backend);
     $storage->setAuthMechanism($authMechanism);
     $storage->setBackendOptions(['password' => 'testPassword']);
     $storage->setApplicableUsers($applicableUsers);
     $storage->setApplicableGroups($applicableGroups);
     $newStorage = $this->globalStoragesService->addStorage($storage);
     $storages = $this->service->getAllStorages();
     if ($isVisible) {
         $this->assertEquals(1, count($storages));
         $retrievedStorage = $this->service->getStorage($newStorage->getId());
         $this->assertEquals('/mountpoint', $retrievedStorage->getMountPoint());
     } else {
         $this->assertEquals(0, count($storages));
         try {
             $this->service->getStorage($newStorage->getId());
             $this->fail('Failed asserting that storage can\'t be accessed by id');
         } catch (NotFoundException $e) {
         }
     }
 }