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.
remotes/origin/etag-endpoint
Vincent Petry 11 years ago
parent 680ec056dc
commit 34c8b1ac77
  1. 6
      apps/files_external/controller/globalstoragescontroller.php
  2. 10
      apps/files_external/controller/userstoragescontroller.php
  3. 15
      apps/files_external/js/settings.js
  4. 12
      apps/files_external/lib/config.php
  5. 29
      apps/files_external/lib/storageconfig.php
  6. 7
      apps/files_external/service/storagesservice.php
  7. 11
      apps/files_external/templates/settings.php
  8. 8
      apps/files_external/tests/controller/storagescontrollertest.php
  9. 2
      apps/files_external/tests/controller/userstoragescontrollertest.php
  10. 6
      apps/files_external/tests/service/globalstoragesservicetest.php
  11. 3
      apps/files_external/tests/service/storagesservicetest.php
  12. 4
      apps/files_external/tests/service/userstoragesservicetest.php
  13. 2
      apps/files_external/tests/storageconfigtest.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);

@ -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)) {

@ -194,6 +194,13 @@ StorageConfig.prototype = {
*/
backendOptions: null,
/**
* Mount-specific options
*
* @type Object.<string,object>
*/
mountOptions: null,
/**
* Creates or saves the storage.
*
@ -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;
},

@ -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;

@ -53,6 +53,11 @@ class StorageConfig implements \JsonSerializable {
*/
private $applicableGroups = [];
/**
* @var array
*/
private $mountOptions = [];
/**
* @param int|null $id config id or null for a new config
*/
@ -195,6 +200,27 @@ class StorageConfig implements \JsonSerializable {
$this->applicableGroups = $applicableGroups;
}
/**
* 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
*
@ -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;
}

@ -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;
}

@ -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;"

@ -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')

@ -91,6 +91,7 @@ class UserStoragesControllerTest extends StoragesControllerTest {
array(),
[],
[],
[],
null
);
@ -103,6 +104,7 @@ class UserStoragesControllerTest extends StoragesControllerTest {
array(),
[],
[],
[],
null
);

@ -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']);

@ -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;
}

@ -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']);

@ -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']);
}
}

Loading…
Cancel
Save