Merge pull request #15338 from owncloud/encryption-mount-option

Add mount point to disable the encryption wrapper
This commit is contained in:
Thomas Müller 2015-04-04 12:51:41 +02:00
commit 4996706078
6 changed files with 60 additions and 16 deletions

View File

@ -15,6 +15,10 @@ var MOUNT_OPTIONS_DROPDOWN_TEMPLATE =
'<div class="drop dropdown mountOptionsDropdown">' +
// FIXME: options are hard-coded for now
' <div class="optionRow">' +
' <label for="mountOptionsEncrypt">{{t "files_external" "Enable encryption"}}</label>' +
' <input id="mountOptionsEncrypt" name="encrypt" type="checkbox" value="true" checked="checked"/>' +
' </div>' +
' <div class="optionRow">' +
' <label for="mountOptionsPreviews">{{t "files_external" "Enable previews"}}</label>' +
' <input id="mountOptionsPreviews" name="previews" type="checkbox" value="true" checked="checked"/>' +
' </div>' +
@ -422,8 +426,9 @@ MountOptionsDropdown.prototype = {
*
* @param {Object} $container container
* @param {Object} mountOptions mount options
* @param {Array} enabledOptions enabled mount options
*/
show: function($container, mountOptions) {
show: function($container, mountOptions, enabledOptions) {
if (MountOptionsDropdown._last) {
MountOptionsDropdown._last.hide();
}
@ -438,7 +443,7 @@ MountOptionsDropdown.prototype = {
this.$el = $el;
$el.addClass('hidden');
this.setOptions(mountOptions);
this.setOptions(mountOptions, enabledOptions);
this.$el.appendTo($container);
MountOptionsDropdown._last = this;
@ -484,8 +489,9 @@ MountOptionsDropdown.prototype = {
* Sets the mount options to the dropdown controls
*
* @param {Object} options mount options
* @param {Array} enabledOptions enabled mount options
*/
setOptions: function(options) {
setOptions: function(options, enabledOptions) {
var $el = this.$el;
_.each(options, function(value, key) {
var $optionEl = $el.find('input, select').filterAttr('name', key);
@ -498,6 +504,15 @@ MountOptionsDropdown.prototype = {
$optionEl.val(value);
}
});
$el.find('.optionRow').each(function(i, row){
var $row = $(row);
var optionId = $row.find('input, select').attr('name');
if (enabledOptions.indexOf(optionId) === -1) {
$row.hide();
} else {
$row.show();
}
});
}
};
@ -554,6 +569,8 @@ MountConfigListView.prototype = {
*/
_allBackends: null,
_encryptionEnabled: false,
/**
* @param {Object} $el DOM object containing the list
* @param {Object} [options]
@ -573,6 +590,8 @@ MountConfigListView.prototype = {
this._userListLimit = options.userListLimit;
}
this._encryptionEnabled = options.encryptionEnabled;
// read the backend config that was carefully crammed
// into the data-configurations attribute of the select
this._allBackends = this.$el.find('.selectBackend').data('configurations');
@ -935,8 +954,11 @@ MountConfigListView.prototype = {
var storage = this.getStorageConfig($tr);
var $toggle = $tr.find('.mountOptionsToggle');
var dropDown = new MountOptionsDropdown();
dropDown.show($toggle, storage.mountOptions || []);
var enabledOptions = ['previews', 'filesystem_check_changes'];
if (this._encryptionEnabled) {
enabledOptions.push('encrypt');
}
dropDown.show($toggle, storage.mountOptions || [], enabledOptions);
$('body').on('mouseup.mountOptionsDropdown', function(event) {
var $target = $(event.target);
if ($toggle.has($target).length) {
@ -963,7 +985,11 @@ MountConfigListView.prototype = {
};
$(document).ready(function() {
var mountConfigListView = new MountConfigListView($('#externalStorage'));
var enabled = $('#files_external').attr('data-encryption-enabled');
var encryptionEnabled = (enabled ==='true')? true: false;
var mountConfigListView = new MountConfigListView($('#externalStorage'), {
encryptionEnabled: encryptionEnabled
});
$('#sslCertificate').on('click', 'td.remove>img', function() {
var $tr = $(this).closest('tr');

View File

@ -48,6 +48,7 @@ if (!$hasId) {
}
$tmpl = new OCP\Template('files_external', 'settings');
$tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
$tmpl->assign('isAdminPage', false);
$tmpl->assign('mounts', $mounts);
$tmpl->assign('dependencies', OC_Mount_Config::checkDependencies());

View File

@ -68,6 +68,7 @@ if (!$hasId) {
}
$tmpl = new OCP\Template('files_external', 'settings');
$tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
$tmpl->assign('isAdminPage', true);
$tmpl->assign('mounts', $mounts);
$tmpl->assign('backends', $backends);

View File

@ -1,4 +1,4 @@
<form id="files_external" class="section">
<form id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>">
<h2><?php p($l->t('External Storage')); ?></h2>
<?php if (isset($_['dependencies']) and ($_['dependencies']<>'')) print_unescaped(''.$_['dependencies'].''); ?>
<table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['isAdminPage'])); ?>'>

View File

@ -85,7 +85,7 @@ describe('OCA.External.Settings tests', function() {
beforeEach(function() {
var $el = $('#externalStorage');
view = new OCA.External.Settings.MountConfigListView($el);
view = new OCA.External.Settings.MountConfigListView($el, {encryptionEnabled: false});
});
afterEach(function() {
view = null;
@ -205,6 +205,17 @@ describe('OCA.External.Settings tests', function() {
expect($td.find('.dropdown').length).toEqual(0);
});
it('doesnt show the encryption option when encryption is disabled', function () {
view._encryptionEnabled = false;
$td.find('img').click();
expect($td.find('.dropdown [name=encrypt]:visible').length).toEqual(0);
$('body').mouseup();
expect($td.find('.dropdown').length).toEqual(0);
});
it('reads config from mountOptions field', function() {
$tr.find('input.mountOptions').val(JSON.stringify({previews:false}));
@ -226,6 +237,7 @@ describe('OCA.External.Settings tests', function() {
$('body').mouseup();
expect(JSON.parse($tr.find('input.mountOptions').val())).toEqual({
encrypt: true,
previews: true,
filesystem_check_changes: 2
});

View File

@ -703,7 +703,8 @@ class OC {
private static function registerEncryptionWrapper() {
$enabled = self::$server->getEncryptionManager()->isEnabled();
if ($enabled) {
\OC\Files\Filesystem::addStorageWrapper('oc_encryption', function ($mountPoint, $storage) {
\OC\Files\Filesystem::addStorageWrapper('oc_encryption', function ($mountPoint, $storage, \OCP\Files\Mount\IMountPoint $mount) {
if($mount->getOption('encrypt', true)) {
$parameters = array('storage' => $storage, 'mountPoint' => $mountPoint);
$manager = \OC::$server->getEncryptionManager();
$util = new \OC\Encryption\Util(new \OC\Files\View(), \OC::$server->getUserManager());
@ -711,6 +712,9 @@ class OC {
$logger = \OC::$server->getLogger();
$uid = $user ? $user->getUID() : null;
return new \OC\Files\Storage\Wrapper\Encryption($parameters, $manager, $util, $logger, $uid);
} else {
return $storage;
}
});
}