diff options
author | Vincent Petry <pvince81@owncloud.com> | 2015-03-13 12:49:11 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2015-03-13 12:49:11 +0100 |
commit | 34c8b1ac7732b4502beebea0dfeeaa8bac225550 (patch) | |
tree | 6fbcb5c17781157bf14afe141b9738814db393c5 | |
parent | 680ec056dc8c4fb84b8300967bcc12db2a57f225 (diff) | |
download | nextcloud-server-34c8b1ac7732b4502beebea0dfeeaa8bac225550.tar.gz nextcloud-server-34c8b1ac7732b4502beebea0dfeeaa8bac225550.zip |
Mount options for ext storage are now passed around
The mount options are now passed to the UI and stored in a hidden field.
The ext storage controllers and services also know how to load/save them
from the legacy config.
13 files changed, 109 insertions, 6 deletions
diff --git a/apps/files_external/controller/globalstoragescontroller.php b/apps/files_external/controller/globalstoragescontroller.php index 3aa64f0d85d..e5aff4f95a2 100644 --- a/apps/files_external/controller/globalstoragescontroller.php +++ b/apps/files_external/controller/globalstoragescontroller.php @@ -49,6 +49,7 @@ class GlobalStoragesController extends StoragesController { * @param string $mountPoint storage mount point * @param string $backendClass backend class name * @param array $backendOptions backend-specific options + * @param array $mountOptions mount-specific options * @param array $applicableUsers users for which to mount the storage * @param array $applicableGroups groups for which to mount the storage * @param int $priority priority @@ -59,6 +60,7 @@ class GlobalStoragesController extends StoragesController { $mountPoint, $backendClass, $backendOptions, + $mountOptions, $applicableUsers, $applicableGroups, $priority @@ -67,6 +69,7 @@ class GlobalStoragesController extends StoragesController { $newStorage->setMountPoint($mountPoint); $newStorage->setBackendClass($backendClass); $newStorage->setBackendOptions($backendOptions); + $newStorage->setMountOptions($mountOptions); $newStorage->setApplicableUsers($applicableUsers); $newStorage->setApplicableGroups($applicableGroups); $newStorage->setPriority($priority); @@ -93,6 +96,7 @@ class GlobalStoragesController extends StoragesController { * @param string $mountPoint storage mount point * @param string $backendClass backend class name * @param array $backendOptions backend-specific options + * @param array $mountOptions mount-specific options * @param array $applicableUsers users for which to mount the storage * @param array $applicableGroups groups for which to mount the storage * @param int $priority priority @@ -104,6 +108,7 @@ class GlobalStoragesController extends StoragesController { $mountPoint, $backendClass, $backendOptions, + $mountOptions, $applicableUsers, $applicableGroups, $priority @@ -112,6 +117,7 @@ class GlobalStoragesController extends StoragesController { $storage->setMountPoint($mountPoint); $storage->setBackendClass($backendClass); $storage->setBackendOptions($backendOptions); + $storage->setMountOptions($mountOptions); $storage->setApplicableUsers($applicableUsers); $storage->setApplicableGroups($applicableGroups); $storage->setPriority($priority); diff --git a/apps/files_external/controller/userstoragescontroller.php b/apps/files_external/controller/userstoragescontroller.php index b77cbca59fd..64202b5e542 100644 --- a/apps/files_external/controller/userstoragescontroller.php +++ b/apps/files_external/controller/userstoragescontroller.php @@ -86,6 +86,7 @@ class UserStoragesController extends StoragesController { * @param string $mountPoint storage mount point * @param string $backendClass backend class name * @param array $backendOptions backend-specific options + * @param array $mountOptions backend-specific mount options * * @return DataResponse * @@ -94,12 +95,14 @@ class UserStoragesController extends StoragesController { public function create( $mountPoint, $backendClass, - $backendOptions + $backendOptions, + $mountOptions ) { $newStorage = new StorageConfig(); $newStorage->setMountPoint($mountPoint); $newStorage->setBackendClass($backendClass); $newStorage->setBackendOptions($backendOptions); + $newStorage->setMountOptions($mountOptions); $response = $this->validate($newStorage); if (!empty($response)) { @@ -122,6 +125,7 @@ class UserStoragesController extends StoragesController { * @param string $mountPoint storage mount point * @param string $backendClass backend class name * @param array $backendOptions backend-specific options + * @param array $mountOptions backend-specific mount options * * @return DataResponse */ @@ -129,12 +133,14 @@ class UserStoragesController extends StoragesController { $id, $mountPoint, $backendClass, - $backendOptions + $backendOptions, + $mountOptions ) { $storage = new StorageConfig($id); $storage->setMountPoint($mountPoint); $storage->setBackendClass($backendClass); $storage->setBackendOptions($backendOptions); + $storage->setMountOptions($mountOptions); $response = $this->validate($storage); if (!empty($response)) { diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index 44488db4bc3..ef64d087884 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -195,6 +195,13 @@ StorageConfig.prototype = { backendOptions: null, /** + * Mount-specific options + * + * @type Object.<string,object> + */ + mountOptions: null, + + /** * Creates or saves the storage. * * @param {Function} [options.success] success callback, receives result as argument @@ -237,6 +244,9 @@ StorageConfig.prototype = { if (this.id) { data.id = this.id; } + if (this.mountOptions) { + data.mountOptions = this.mountOptions; + } return data; }, @@ -641,6 +651,11 @@ MountConfigListView.prototype = { storage.priority = $tr.find('input.priority').val(); } + var mountOptions = $tr.find('input.mountOptions').val(); + if (mountOptions) { + storage.mountOptions = JSON.parse(mountOptions); + } + return storage; }, diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index deeedb98551..378bedfa8de 100644 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -357,6 +357,9 @@ class OC_Mount_Config { 'applicable' => array('groups' => array($group), 'users' => array()), 'status' => self::getBackendStatus($mount['class'], $mount['options'], false) ); + if (isset($mount['mountOptions'])) { + $config['mountOptions'] = $mount['mountOptions']; + } $hash = self::makeConfigHash($config); // If an existing config exists (with same class, mountpoint and options) if (isset($system[$hash])) { @@ -393,6 +396,9 @@ class OC_Mount_Config { 'applicable' => array('groups' => array(), 'users' => array($user)), 'status' => self::getBackendStatus($mount['class'], $mount['options'], false) ); + if (isset($mount['mountOptions'])) { + $config['mountOptions'] = $mount['mountOptions']; + } $hash = self::makeConfigHash($config); // If an existing config exists (with same class, mountpoint and options) if (isset($system[$hash])) { @@ -426,7 +432,7 @@ class OC_Mount_Config { $mount['class'] = '\OC\Files\Storage\\' . substr($mount['class'], 15); } $mount['options'] = self::decryptPasswords($mount['options']); - $personal[] = array( + $config = array( 'id' => (int) $mount['id'], 'storage_id' => (int) $mount['storage_id'], 'class' => $mount['class'], @@ -436,6 +442,10 @@ class OC_Mount_Config { 'options' => $mount['options'], 'status' => self::getBackendStatus($mount['class'], $mount['options'], true) ); + if (isset($mount['mountOptions'])) { + $config['mountOptions'] = $mount['mountOptions']; + } + $personal[] = $config; } } return $personal; diff --git a/apps/files_external/lib/storageconfig.php b/apps/files_external/lib/storageconfig.php index f23b5cd86a9..a45321516d4 100644 --- a/apps/files_external/lib/storageconfig.php +++ b/apps/files_external/lib/storageconfig.php @@ -54,6 +54,11 @@ class StorageConfig implements \JsonSerializable { private $applicableGroups = []; /** + * @var array + */ + private $mountOptions = []; + + /** * @param int|null $id config id or null for a new config */ public function __construct($id = null) { @@ -196,6 +201,27 @@ class StorageConfig implements \JsonSerializable { } /** + * Returns the mount-specific options + * + * @return array mount specific options + */ + public function getMountOptions() { + return $this->mountOptions; + } + + /** + * Sets the mount-specific options + * + * @param array applicable groups + */ + public function setMountOptions($mountOptions) { + if (is_null($mountOptions)) { + $mountOptions = []; + } + $this->mountOptions = $mountOptions; + } + + /** * Sets the storage status, whether the config worked last time * * @return int $status status @@ -235,6 +261,9 @@ class StorageConfig implements \JsonSerializable { if (!empty($this->applicableGroups)) { $result['applicableGroups'] = $this->applicableGroups; } + if (!empty($this->mountOptions)) { + $result['mountOptions'] = $this->mountOptions; + } if (!is_null($this->status)) { $result['status'] = $this->status; } diff --git a/apps/files_external/service/storagesservice.php b/apps/files_external/service/storagesservice.php index 52188b23a39..46a485a169c 100644 --- a/apps/files_external/service/storagesservice.php +++ b/apps/files_external/service/storagesservice.php @@ -50,6 +50,7 @@ abstract class StoragesService { * - "priority": storage priority * - "backend": backend class name * - "options": backend-specific options + * - "mountOptions": mount-specific options (ex: disable previews, scanner, etc) */ // group by storage id @@ -82,6 +83,9 @@ abstract class StoragesService { $currentStorage->setBackendClass($storageOptions['class']); $currentStorage->setBackendOptions($storageOptions['options']); + if (isset($storageOptions['mountOptions'])) { + $currentStorage->setMountOptions($storageOptions['mountOptions']); + } if (isset($storageOptions['priority'])) { $currentStorage->setPriority($storageOptions['priority']); } @@ -141,6 +145,9 @@ abstract class StoragesService { if (!is_null($storageConfig->getPriority())) { $options['priority'] = $storageConfig->getPriority(); } + if (!empty($storageConfig->getMountOptions())) { + $options['mountOptions'] = $storageConfig->getMountOptions(); + } $mountPoints[$mountType][$applicable][$rootMountPoint] = $options; } diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index 4c54d4069b2..3368b96a122 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -80,6 +80,14 @@ <?php OCP\Util::addScript('files_external', $_['backends'][$mount['class']]['custom']); ?> <?php endif; ?> <?php endif; ?> + <?php if (isset($mount['mountOptions'])): ?> + <input type="hidden" class="mountOptions" value="<?php p(json_encode($mount['mountOptions'])) ?>" /> + <?php endif; ?> + <?php if ($_['isAdminPage']): ?> + <?php if (isset($mount['priority'])): ?> + <input type="hidden" class="priority" value="<?php p($mount['priority']) ?>" /> + <?php endif; ?> + <?php endif; ?> </td> <?php if ($_['isAdminPage']): ?> <td class="applicable" @@ -90,9 +98,6 @@ print_unescaped(json_encode($mount['applicable']['users'])); ?>'> <input type="hidden" class="applicableUsers" style="width:20em;" value=""/> </td> - <?php if (isset($mount['priority'])): ?> - <input type="hidden" class="priority" value="<?php p($mount['priority']) ?>" /> - <?php endif; ?> <?php endif; ?> <td <?php if (isset($mount['mountpoint'])): ?>class="remove" <?php else: ?>style="visibility:hidden;" diff --git a/apps/files_external/tests/controller/storagescontrollertest.php b/apps/files_external/tests/controller/storagescontrollertest.php index fefe2928d76..853b4a86f03 100644 --- a/apps/files_external/tests/controller/storagescontrollertest.php +++ b/apps/files_external/tests/controller/storagescontrollertest.php @@ -62,6 +62,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { array(), [], [], + [], null ); @@ -85,6 +86,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { array(), [], [], + [], null ); @@ -116,6 +118,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { array(), [], [], + [], null ); @@ -128,6 +131,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { array(), [], [], + [], null ); @@ -146,6 +150,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { array(), [], [], + [], null ); @@ -158,6 +163,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { array(), [], [], + [], null ); @@ -176,6 +182,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { array(), [], [], + [], null ); @@ -204,6 +211,7 @@ abstract class StoragesControllerTest extends \Test\TestCase { $storageConfig->setMountPoint('test'); $storageConfig->setBackendClass('\OC\Files\Storage\SMB'); $storageConfig->setBackendOptions(['user' => 'test', 'password', 'password123']); + $storageConfig->setMountOptions(['priority' => false]); $this->service->expects($this->once()) ->method('getStorage') diff --git a/apps/files_external/tests/controller/userstoragescontrollertest.php b/apps/files_external/tests/controller/userstoragescontrollertest.php index 9d6fbb15e23..0ba413f6959 100644 --- a/apps/files_external/tests/controller/userstoragescontrollertest.php +++ b/apps/files_external/tests/controller/userstoragescontrollertest.php @@ -91,6 +91,7 @@ class UserStoragesControllerTest extends StoragesControllerTest { array(), [], [], + [], null ); @@ -103,6 +104,7 @@ class UserStoragesControllerTest extends StoragesControllerTest { array(), [], [], + [], null ); diff --git a/apps/files_external/tests/service/globalstoragesservicetest.php b/apps/files_external/tests/service/globalstoragesservicetest.php index 6286865bf43..f5cdcfa3907 100644 --- a/apps/files_external/tests/service/globalstoragesservicetest.php +++ b/apps/files_external/tests/service/globalstoragesservicetest.php @@ -50,6 +50,9 @@ class GlobalStoragesServiceTest extends StoragesServiceTest { 'applicableUsers' => [], 'applicableGroups' => [], 'priority' => 15, + 'mountOptions' => [ + 'preview' => false, + ] ]); } @@ -638,6 +641,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest { $this->assertEquals(1, $mountPointOptions['id']); $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']); $this->assertEquals(15, $mountPointOptions['priority']); + $this->assertEquals(false, $mountPointOptions['mountOptions']['preview']); $backendOptions = $mountPointOptions['options']; $this->assertEquals('value1', $backendOptions['option1']); @@ -677,6 +681,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest { $this->assertEquals(1, $mountPointOptions['id']); $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']); $this->assertEquals(15, $mountPointOptions['priority']); + $this->assertEquals(false, $mountPointOptions['mountOptions']['preview']); $backendOptions = $mountPointOptions['options']; $this->assertEquals('value1', $backendOptions['option1']); @@ -693,6 +698,7 @@ class GlobalStoragesServiceTest extends StoragesServiceTest { $this->assertEquals(1, $mountPointOptions['id']); $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']); $this->assertEquals(15, $mountPointOptions['priority']); + $this->assertEquals(false, $mountPointOptions['mountOptions']['preview']); $backendOptions = $mountPointOptions['options']; $this->assertEquals('value1', $backendOptions['option1']); diff --git a/apps/files_external/tests/service/storagesservicetest.php b/apps/files_external/tests/service/storagesservicetest.php index 1e338b3948d..445e86d4117 100644 --- a/apps/files_external/tests/service/storagesservicetest.php +++ b/apps/files_external/tests/service/storagesservicetest.php @@ -96,6 +96,9 @@ abstract class StoragesServiceTest extends \Test\TestCase { if (isset($data['priority'])) { $storage->setPriority($data['priority']); } + if (isset($data['mountOptions'])) { + $storage->setMountOptions($data['mountOptions']); + } return $storage; } diff --git a/apps/files_external/tests/service/userstoragesservicetest.php b/apps/files_external/tests/service/userstoragesservicetest.php index 64d59dc7d03..77b3842b318 100644 --- a/apps/files_external/tests/service/userstoragesservicetest.php +++ b/apps/files_external/tests/service/userstoragesservicetest.php @@ -61,6 +61,9 @@ class UserStoragesServiceTest extends StoragesServiceTest { 'option2' => 'value2', 'password' => 'testPassword', ], + 'mountOptions' => [ + 'preview' => false, + ] ]); } @@ -190,6 +193,7 @@ class UserStoragesServiceTest extends StoragesServiceTest { $mountPointOptions = current($mountPointData); $this->assertEquals(1, $mountPointOptions['id']); $this->assertEquals('\OC\Files\Storage\SMB', $mountPointOptions['class']); + $this->assertEquals(false, $mountPointOptions['mountOptions']['preview']); $backendOptions = $mountPointOptions['options']; $this->assertEquals('value1', $backendOptions['option1']); diff --git a/apps/files_external/tests/storageconfigtest.php b/apps/files_external/tests/storageconfigtest.php index 473dc20b387..ec79b1bf306 100644 --- a/apps/files_external/tests/storageconfigtest.php +++ b/apps/files_external/tests/storageconfigtest.php @@ -34,6 +34,7 @@ class StorageConfigTest extends \Test\TestCase { $storageConfig->setPriority(128); $storageConfig->setApplicableUsers(['user1', 'user2']); $storageConfig->setApplicableGroups(['group1', 'group2']); + $storageConfig->setMountOptions(['preview' => false]); $json = $storageConfig->jsonSerialize(); @@ -45,6 +46,7 @@ class StorageConfigTest extends \Test\TestCase { $this->assertEquals(128, $json['priority']); $this->assertEquals(['user1', 'user2'], $json['applicableUsers']); $this->assertEquals(['group1', 'group2'], $json['applicableGroups']); + $this->assertEquals(['preview' => false], $json['mountOptions']); } } |