Merge pull request #15338 from owncloud/encryption-mount-option
Add mount point to disable the encryption wrapper
This commit is contained in:
commit
4996706078
|
@ -15,6 +15,10 @@ var MOUNT_OPTIONS_DROPDOWN_TEMPLATE =
|
||||||
'<div class="drop dropdown mountOptionsDropdown">' +
|
'<div class="drop dropdown mountOptionsDropdown">' +
|
||||||
// FIXME: options are hard-coded for now
|
// FIXME: options are hard-coded for now
|
||||||
' <div class="optionRow">' +
|
' <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>' +
|
' <label for="mountOptionsPreviews">{{t "files_external" "Enable previews"}}</label>' +
|
||||||
' <input id="mountOptionsPreviews" name="previews" type="checkbox" value="true" checked="checked"/>' +
|
' <input id="mountOptionsPreviews" name="previews" type="checkbox" value="true" checked="checked"/>' +
|
||||||
' </div>' +
|
' </div>' +
|
||||||
|
@ -422,8 +426,9 @@ MountOptionsDropdown.prototype = {
|
||||||
*
|
*
|
||||||
* @param {Object} $container container
|
* @param {Object} $container container
|
||||||
* @param {Object} mountOptions mount options
|
* @param {Object} mountOptions mount options
|
||||||
|
* @param {Array} enabledOptions enabled mount options
|
||||||
*/
|
*/
|
||||||
show: function($container, mountOptions) {
|
show: function($container, mountOptions, enabledOptions) {
|
||||||
if (MountOptionsDropdown._last) {
|
if (MountOptionsDropdown._last) {
|
||||||
MountOptionsDropdown._last.hide();
|
MountOptionsDropdown._last.hide();
|
||||||
}
|
}
|
||||||
|
@ -438,7 +443,7 @@ MountOptionsDropdown.prototype = {
|
||||||
this.$el = $el;
|
this.$el = $el;
|
||||||
$el.addClass('hidden');
|
$el.addClass('hidden');
|
||||||
|
|
||||||
this.setOptions(mountOptions);
|
this.setOptions(mountOptions, enabledOptions);
|
||||||
|
|
||||||
this.$el.appendTo($container);
|
this.$el.appendTo($container);
|
||||||
MountOptionsDropdown._last = this;
|
MountOptionsDropdown._last = this;
|
||||||
|
@ -484,8 +489,9 @@ MountOptionsDropdown.prototype = {
|
||||||
* Sets the mount options to the dropdown controls
|
* Sets the mount options to the dropdown controls
|
||||||
*
|
*
|
||||||
* @param {Object} options mount options
|
* @param {Object} options mount options
|
||||||
|
* @param {Array} enabledOptions enabled mount options
|
||||||
*/
|
*/
|
||||||
setOptions: function(options) {
|
setOptions: function(options, enabledOptions) {
|
||||||
var $el = this.$el;
|
var $el = this.$el;
|
||||||
_.each(options, function(value, key) {
|
_.each(options, function(value, key) {
|
||||||
var $optionEl = $el.find('input, select').filterAttr('name', key);
|
var $optionEl = $el.find('input, select').filterAttr('name', key);
|
||||||
|
@ -498,6 +504,15 @@ MountOptionsDropdown.prototype = {
|
||||||
$optionEl.val(value);
|
$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,
|
_allBackends: null,
|
||||||
|
|
||||||
|
_encryptionEnabled: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Object} $el DOM object containing the list
|
* @param {Object} $el DOM object containing the list
|
||||||
* @param {Object} [options]
|
* @param {Object} [options]
|
||||||
|
@ -573,6 +590,8 @@ MountConfigListView.prototype = {
|
||||||
this._userListLimit = options.userListLimit;
|
this._userListLimit = options.userListLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._encryptionEnabled = options.encryptionEnabled;
|
||||||
|
|
||||||
// read the backend config that was carefully crammed
|
// read the backend config that was carefully crammed
|
||||||
// into the data-configurations attribute of the select
|
// into the data-configurations attribute of the select
|
||||||
this._allBackends = this.$el.find('.selectBackend').data('configurations');
|
this._allBackends = this.$el.find('.selectBackend').data('configurations');
|
||||||
|
@ -935,8 +954,11 @@ MountConfigListView.prototype = {
|
||||||
var storage = this.getStorageConfig($tr);
|
var storage = this.getStorageConfig($tr);
|
||||||
var $toggle = $tr.find('.mountOptionsToggle');
|
var $toggle = $tr.find('.mountOptionsToggle');
|
||||||
var dropDown = new MountOptionsDropdown();
|
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) {
|
$('body').on('mouseup.mountOptionsDropdown', function(event) {
|
||||||
var $target = $(event.target);
|
var $target = $(event.target);
|
||||||
if ($toggle.has($target).length) {
|
if ($toggle.has($target).length) {
|
||||||
|
@ -963,7 +985,11 @@ MountConfigListView.prototype = {
|
||||||
};
|
};
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(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() {
|
$('#sslCertificate').on('click', 'td.remove>img', function() {
|
||||||
var $tr = $(this).closest('tr');
|
var $tr = $(this).closest('tr');
|
||||||
|
|
|
@ -48,6 +48,7 @@ if (!$hasId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmpl = new OCP\Template('files_external', 'settings');
|
$tmpl = new OCP\Template('files_external', 'settings');
|
||||||
|
$tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
|
||||||
$tmpl->assign('isAdminPage', false);
|
$tmpl->assign('isAdminPage', false);
|
||||||
$tmpl->assign('mounts', $mounts);
|
$tmpl->assign('mounts', $mounts);
|
||||||
$tmpl->assign('dependencies', OC_Mount_Config::checkDependencies());
|
$tmpl->assign('dependencies', OC_Mount_Config::checkDependencies());
|
||||||
|
|
|
@ -68,6 +68,7 @@ if (!$hasId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmpl = new OCP\Template('files_external', 'settings');
|
$tmpl = new OCP\Template('files_external', 'settings');
|
||||||
|
$tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
|
||||||
$tmpl->assign('isAdminPage', true);
|
$tmpl->assign('isAdminPage', true);
|
||||||
$tmpl->assign('mounts', $mounts);
|
$tmpl->assign('mounts', $mounts);
|
||||||
$tmpl->assign('backends', $backends);
|
$tmpl->assign('backends', $backends);
|
||||||
|
|
|
@ -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>
|
<h2><?php p($l->t('External Storage')); ?></h2>
|
||||||
<?php if (isset($_['dependencies']) and ($_['dependencies']<>'')) print_unescaped(''.$_['dependencies'].''); ?>
|
<?php if (isset($_['dependencies']) and ($_['dependencies']<>'')) print_unescaped(''.$_['dependencies'].''); ?>
|
||||||
<table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['isAdminPage'])); ?>'>
|
<table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['isAdminPage'])); ?>'>
|
||||||
|
|
|
@ -85,7 +85,7 @@ describe('OCA.External.Settings tests', function() {
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
var $el = $('#externalStorage');
|
var $el = $('#externalStorage');
|
||||||
view = new OCA.External.Settings.MountConfigListView($el);
|
view = new OCA.External.Settings.MountConfigListView($el, {encryptionEnabled: false});
|
||||||
});
|
});
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
view = null;
|
view = null;
|
||||||
|
@ -205,6 +205,17 @@ describe('OCA.External.Settings tests', function() {
|
||||||
expect($td.find('.dropdown').length).toEqual(0);
|
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() {
|
it('reads config from mountOptions field', function() {
|
||||||
$tr.find('input.mountOptions').val(JSON.stringify({previews:false}));
|
$tr.find('input.mountOptions').val(JSON.stringify({previews:false}));
|
||||||
|
|
||||||
|
@ -226,6 +237,7 @@ describe('OCA.External.Settings tests', function() {
|
||||||
$('body').mouseup();
|
$('body').mouseup();
|
||||||
|
|
||||||
expect(JSON.parse($tr.find('input.mountOptions').val())).toEqual({
|
expect(JSON.parse($tr.find('input.mountOptions').val())).toEqual({
|
||||||
|
encrypt: true,
|
||||||
previews: true,
|
previews: true,
|
||||||
filesystem_check_changes: 2
|
filesystem_check_changes: 2
|
||||||
});
|
});
|
||||||
|
|
20
lib/base.php
20
lib/base.php
|
@ -703,14 +703,18 @@ class OC {
|
||||||
private static function registerEncryptionWrapper() {
|
private static function registerEncryptionWrapper() {
|
||||||
$enabled = self::$server->getEncryptionManager()->isEnabled();
|
$enabled = self::$server->getEncryptionManager()->isEnabled();
|
||||||
if ($enabled) {
|
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) {
|
||||||
$parameters = array('storage' => $storage, 'mountPoint' => $mountPoint);
|
if($mount->getOption('encrypt', true)) {
|
||||||
$manager = \OC::$server->getEncryptionManager();
|
$parameters = array('storage' => $storage, 'mountPoint' => $mountPoint);
|
||||||
$util = new \OC\Encryption\Util(new \OC\Files\View(), \OC::$server->getUserManager());
|
$manager = \OC::$server->getEncryptionManager();
|
||||||
$user = \OC::$server->getUserSession()->getUser();
|
$util = new \OC\Encryption\Util(new \OC\Files\View(), \OC::$server->getUserManager());
|
||||||
$logger = \OC::$server->getLogger();
|
$user = \OC::$server->getUserSession()->getUser();
|
||||||
$uid = $user ? $user->getUID() : null;
|
$logger = \OC::$server->getLogger();
|
||||||
return new \OC\Files\Storage\Wrapper\Encryption($parameters, $manager,$util, $logger, $uid);
|
$uid = $user ? $user->getUID() : null;
|
||||||
|
return new \OC\Files\Storage\Wrapper\Encryption($parameters, $manager, $util, $logger, $uid);
|
||||||
|
} else {
|
||||||
|
return $storage;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue