Example #1
0
 private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService)
 {
     $existingStorage = $legacyService->getAllStorages();
     $this->connection->beginTransaction();
     try {
         foreach ($existingStorage as $storage) {
             $storageService->addStorage($storage);
         }
         $this->connection->commit();
     } catch (\Exception $e) {
         $this->logger->logException($e);
         $this->connection->rollBack();
     }
 }
 /**
  * @dataProvider getUniqueStoragesProvider
  */
 public function testGetUniqueStorages($priority1, $applicableUsers1, $applicableGroups1, $priority2, $applicableUsers2, $applicableGroups2, $expectedPrecedence)
 {
     $backend = $this->backendService->getBackend('identifier:\\OCA\\Files_External\\Lib\\Backend\\SMB');
     $backend->method('isVisibleFor')->willReturn(true);
     $authMechanism = $this->backendService->getAuthMechanism('identifier:\\Auth\\Mechanism');
     $authMechanism->method('isVisibleFor')->willReturn(true);
     $storage1 = new StorageConfig();
     $storage1->setMountPoint('mountpoint');
     $storage1->setBackend($backend);
     $storage1->setAuthMechanism($authMechanism);
     $storage1->setBackendOptions(['password' => 'testPassword']);
     $storage1->setPriority($priority1);
     $storage1->setApplicableUsers($applicableUsers1);
     $storage1->setApplicableGroups($applicableGroups1);
     $storage1 = $this->globalStoragesService->addStorage($storage1);
     $storage2 = new StorageConfig();
     $storage2->setMountPoint('mountpoint');
     $storage2->setBackend($backend);
     $storage2->setAuthMechanism($authMechanism);
     $storage2->setBackendOptions(['password' => 'testPassword']);
     $storage2->setPriority($priority2);
     $storage2->setApplicableUsers($applicableUsers2);
     $storage2->setApplicableGroups($applicableGroups2);
     $storage2 = $this->globalStoragesService->addStorage($storage2);
     $storages = $this->service->getUniqueStorages();
     $this->assertCount(1, $storages);
     if ($expectedPrecedence === 1) {
         $this->assertArrayHasKey($storage1->getID(), $storages);
     } elseif ($expectedPrecedence === 2) {
         $this->assertArrayHasKey($storage2->getID(), $storages);
     }
 }
Example #3
0
 /**
  * Deletes the storage with the given id.
  *
  * @param int $id storage id
  *
  * @return DataResponse
  */
 public function destroy($id)
 {
     try {
         $this->service->removeStorage($id);
     } catch (NotFoundException $e) {
         return new DataResponse(['message' => (string) $this->l10n->t('Storage with id "%i" not found', array($id))], Http::STATUS_NOT_FOUND);
     }
     return new DataResponse([], Http::STATUS_NO_CONTENT);
 }
 /**
  * @expectedException \OCA\Files_External\NotFoundException
  */
 public function testGetAdminStorage()
 {
     $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([$this->userId]);
     $newStorage = $this->globalStoragesService->addStorage($storage);
     $this->assertInstanceOf('\\OCA\\Files_External\\Lib\\StorageConfig', $this->globalStoragesService->getStorage($newStorage->getId()));
     $this->service->getStorage($newStorage->getId());
 }
 public function testGetStoragesAuthMechanismNotVisible()
 {
     $backend = $this->backendService->getBackend('identifier:\\OCA\\Files_External\\Lib\\Backend\\SMB');
     $backend->method('isVisibleFor')->with($this->service->getVisibilityType())->willReturn(true);
     $authMechanism = $this->backendService->getAuthMechanism('identifier:\\Auth\\Mechanism');
     $authMechanism->expects($this->once())->method('isVisibleFor')->with($this->service->getVisibilityType())->willReturn(false);
     $storage = new StorageConfig(255);
     $storage->setMountPoint('mountpoint');
     $storage->setBackend($backend);
     $storage->setAuthMechanism($authMechanism);
     $storage->setBackendOptions(['password' => 'testPassword']);
     $newStorage = $this->service->addStorage($storage);
     $this->assertCount(1, $this->service->getAllStorages());
     $this->assertEmpty($this->service->getStorages());
 }
Example #6
0
 /**
  * Read the external storages config
  *
  * @return array map of storage id to storage config
  */
 protected function readConfig()
 {
     $user = $this->getUser()->getUID();
     // TODO: in the future don't rely on the global config reading code
     $storages = parent::readConfig();
     $filteredStorages = [];
     foreach ($storages as $configId => $storage) {
         // filter out all bogus storages that aren't for the current user
         if (!in_array($user, $storage->getApplicableUsers())) {
             continue;
         }
         // clear applicable users, should not be used
         $storage->setApplicableUsers([]);
         // strip out unneeded applicableUser fields
         $filteredStorages[$configId] = $storage;
     }
     return $filteredStorages;
 }
 private function migrate(LegacyStoragesService $legacyService, StoragesService $storageService)
 {
     $existingStorage = $legacyService->getAllStorages();
     $this->connection->beginTransaction();
     try {
         foreach ($existingStorage as $storage) {
             $mountOptions = $storage->getMountOptions();
             if (!empty($mountOptions) && !isset($mountOptions['enable_sharing'])) {
                 // existing mounts must have sharing enabled by default to avoid surprises
                 $mountOptions['enable_sharing'] = true;
                 $storage->setMountOptions($mountOptions);
             }
             $storageService->addStorage($storage);
         }
         $this->connection->commit();
     } catch (\Exception $e) {
         $this->logger->logException($e);
         $this->connection->rollBack();
     }
 }
 public function testUpdateStorageMountPoint()
 {
     $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']);
     $savedStorage = $this->service->addStorage($storage);
     $newAuthMechanism = $this->backendService->getAuthMechanism('identifier:\\Other\\Auth\\Mechanism');
     $updatedStorage = new StorageConfig($savedStorage->getId());
     $updatedStorage->setMountPoint('mountpoint2');
     $updatedStorage->setBackend($backend);
     $updatedStorage->setAuthMechanism($newAuthMechanism);
     $updatedStorage->setBackendOptions(['password' => 'password2']);
     $this->service->updateStorage($updatedStorage);
     $savedStorage = $this->service->getStorage($updatedStorage->getId());
     $this->assertEquals('/mountpoint2', $savedStorage->getMountPoint());
     $this->assertEquals($newAuthMechanism, $savedStorage->getAuthMechanism());
     $this->assertEquals('password2', $savedStorage->getBackendOption('password'));
 }
 /**
  * Add new storage to the configuration
  *
  * @param StorageConfig $newStorage storage attributes
  *
  * @return StorageConfig storage config, with added id
  */
 public function addStorage(StorageConfig $newStorage)
 {
     $config = parent::addStorage($newStorage);
     $this->dbConfig->addApplicable($config->getId(), DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID());
     return $config;
 }
Example #10
0
 /**
  * Update storage to the configuration
  *
  * @param StorageConfig $updatedStorage storage attributes
  *
  * @return StorageConfig storage config
  * @throws NotFoundException if the given storage does not exist in the config
  */
 public function updateStorage(StorageConfig $updatedStorage)
 {
     $updatedStorage->setApplicableUsers([$this->getUser()->getUID()]);
     return parent::updateStorage($updatedStorage);
 }