Merge pull request #21215 from owncloud/files_external-db-set-mountpoint

fix setting mountpoint and auth backend of external storages
This commit is contained in:
Thomas Müller 2016-01-08 13:36:30 +01:00
commit 427dbdabba
7 changed files with 112 additions and 2 deletions

View File

@ -212,6 +212,34 @@ class DBConfigService {
$query->execute();
}
/**
* @param int $mountId
* @param string $newMountPoint
*/
public function setMountPoint($mountId, $newMountPoint) {
$builder = $this->connection->getQueryBuilder();
$query = $builder->update('external_mounts')
->set('mount_point', $builder->createNamedParameter($newMountPoint))
->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, \PDO::PARAM_INT)));
$query->execute();
}
/**
* @param int $mountId
* @param string $newAuthBackend
*/
public function setAuthBackend($mountId, $newAuthBackend) {
$builder = $this->connection->getQueryBuilder();
$query = $builder->update('external_mounts')
->set('auth_backend', $builder->createNamedParameter($newAuthBackend))
->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, \PDO::PARAM_INT)));
$query->execute();
}
/**
* @param int $mountId
* @param string $key

View File

@ -392,6 +392,14 @@ abstract class StoragesService {
$this->dbConfig->setOption($id, $key, $value);
}
if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) {
$this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint());
}
if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) {
$this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier());
}
$this->triggerChangeHooks($oldStorage, $updatedStorage);
return $this->getStorage($id);

View File

@ -104,11 +104,24 @@ class UserStoragesService extends StoragesService {
* @return StorageConfig storage config, with added id
*/
public function addStorage(StorageConfig $newStorage) {
$newStorage->setApplicableUsers([$this->getUser()->getUID()]);
$config = parent::addStorage($newStorage);
$this->dbConfig->addApplicable($config->getId(), DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID());
return $config;
}
/**
* 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);
}
/**
* Get the visibility type for this controller, used in validation
*

View File

@ -230,4 +230,32 @@ class DBConfigServiceTest extends TestCase {
$this->assertEquals($id1, $mounts[0]['mount_id']);
$this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_GLOBAL, 'value' => null, 'mount_id' => $id1]], $mounts[0]['applicable']);
}
public function testSetMountPoint() {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->setMountPoint($id1, '/asd');
$mount = $this->dbConfig->getMountById($id1);
$this->assertEquals('/asd', $mount['mount_point']);
// remains unchanged
$mount = $this->dbConfig->getMountById($id2);
$this->assertEquals('/foo', $mount['mount_point']);
}
public function testSetAuthBackend() {
$id1 = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$id2 = $this->addMount('/foo', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
$this->dbConfig->setAuthBackend($id1, 'none');
$mount = $this->dbConfig->getMountById($id1);
$this->assertEquals('none', $mount['auth_backend']);
// remains unchanged
$mount = $this->dbConfig->getMountById($id2);
$this->assertEquals('bar', $mount['auth_backend']);
}
}

View File

@ -465,4 +465,33 @@ abstract class StoragesServiceTest extends \Test\TestCase {
$params[Filesystem::signal_param_users]
);
}
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'));
}
}

View File

@ -349,4 +349,8 @@ class UserGlobalStoragesServiceTest extends GlobalStoragesServiceTest {
$this->assertTrue(true);
}
public function testUpdateStorageMountPoint() {
// we don't test this here
$this->assertTrue(true);
}
}

View File

@ -122,8 +122,8 @@ class UserStoragesServiceTest extends StoragesServiceTest {
$newStorage = $this->service->updateStorage($newStorage);
$this->assertEquals('anotherPassword', $newStorage->getBackendOptions()['password']);
$this->assertEquals([$this->userId], $newStorage->getApplicableUsers());
// these attributes are unused for user storages
$this->assertEmpty($newStorage->getApplicableUsers());
$this->assertEmpty($newStorage->getApplicableGroups());
$this->assertEquals(0, $newStorage->getStatus());