Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Add option to disable sharing in user-mounted external storages #28706

Merged
merged 1 commit into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions apps/files_external/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ MountOptionsDropdown.prototype = {
}

var $el = $(template({
mountOptionsEncodingLabel: t('files_external', 'Compatibility with Mac NFD encoding (slow)')
mountOptionsEncodingLabel: t('files_external', 'Compatibility with Mac NFD encoding (slow)'),
}));
this.$el = $el;

Expand Down Expand Up @@ -654,7 +654,6 @@ MountConfigListView.prototype = _.extend({
* @param {int} [options.userListLimit] page size in applicable users dropdown
*/
initialize: function($el, options) {
var self = this;
this.$el = $el;
this._isPersonal = ($el.data('admin') !== true);
if (this._isPersonal) {
Expand All @@ -668,6 +667,7 @@ MountConfigListView.prototype = _.extend({
}

this._encryptionEnabled = options.encryptionEnabled;
this._allowUserMountSharing = options.allowUserMountSharing;

// read the backend config that was carefully crammed
// into the data-configurations attribute of the select
Expand Down Expand Up @@ -1272,12 +1272,15 @@ MountConfigListView.prototype = _.extend({
var visibleOptions = [
'previews',
'filesystem_check_changes',
'enable_sharing',
'encoding_compatibility'
];
if (this._encryptionEnabled) {
visibleOptions.push('encrypt');
}
if (!this._isPersonal || this._allowUserMountSharing) {
visibleOptions.push('enable_sharing');
}

dropDown.show($toggle, storage.mountOptions || [], visibleOptions);
$('body').on('mouseup.mountOptionsDropdown', function(event) {
var $target = $(event.target);
Expand Down Expand Up @@ -1308,7 +1311,8 @@ $(document).ready(function() {
var enabled = $('#files_external').attr('data-encryption-enabled');
var encryptionEnabled = (enabled ==='true')? true: false;
var mountConfigListView = new MountConfigListView($('#externalStorage'), {
encryptionEnabled: encryptionEnabled
encryptionEnabled: encryptionEnabled,
allowUserMountSharing: (parseInt($('#allowUserMountSharing').val(), 10) === 1)
});
mountConfigListView.loadStorages();

Expand All @@ -1328,6 +1332,13 @@ $(document).ready(function() {
OC.msg.finishedSaving('#userMountingMsg', {status: 'success', data: {message: t('files_external', 'Saved')}});
});

var $allowUserMountSharing = $('#allowUserMountSharing');
$allowUserMountSharing.bind('change', function() {
OC.msg.startSaving('#userMountSharingMsg');
OC.AppConfig.setValue('core', 'allow_user_mount_sharing', this.checked ? 'yes' : 'no');
OC.msg.finishedSaving('#userMountSharingMsg', {status: 'success', data: {message: t('files_external', 'Saved')}});
});

$('input[name="allowUserMountingBackends\\[\\]"]').bind('change', function() {
OC.msg.startSaving('#userMountingMsg');

Expand Down
2 changes: 2 additions & 0 deletions apps/files_external/lib/Panels/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public function getPanel() {
$tmpl->assign('authMechanisms', $this->backendService->getAuthMechanisms());
$tmpl->assign('dependencies', \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()));
$tmpl->assign('allowUserMounting', $this->backendService->isUserMountingAllowed());
$tmpl->assign('allowUserMountSharing', $this->config->getAppValue('core', 'allow_user_mount_sharing', 'yes') === 'yes');

return $tmpl;
}

Expand Down
1 change: 1 addition & 0 deletions apps/files_external/lib/Panels/Personal.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function getPanel() {
$tmpl->assign('backends', $this->backendService->getAvailableBackends());
$tmpl->assign('authMechanisms', $this->backendService->getAuthMechanisms());
$tmpl->assign('allowUserMounting', $enabled);
$tmpl->assign('allowUserMountSharing', $this->config->getAppValue('core', 'allow_user_mount_sharing', 'yes') === 'yes');
return $tmpl;
}

Expand Down
7 changes: 7 additions & 0 deletions apps/files_external/templates/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,14 @@
<?php endif; ?>
<?php $i++; ?>
<?php endforeach; ?>
<br/>
<input type="checkbox" name="allowUserMountSharing" id="allowUserMountSharing" class="checkbox"
value="1" <?php if ($_['allowUserMountSharing'] === 'yes') print_unescaped(' checked="checked"'); ?> />
<label for="allowUserMountSharing"><?php p($l->t('Allow sharing on user-mounted external storages')); ?></label> <span id="userMountSharingMsg" class="msg"></span>
</p>
<?php else: ?>
<input type="hidden" name="allowUserMountSharing" id="allowUserMountSharing"
value="<?php p($_['allowUserMountSharing']) ?>" />
<?php endif; ?>
</div>
</form>
37 changes: 36 additions & 1 deletion apps/files_external/tests/js/settingsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ describe('OCA.External.Settings tests', function() {
expect($td.find('.dropdown').length).toEqual(0);
});

it('doesnt show the encryption option when encryption is disabled', function () {
it('does not show the encryption option when encryption is disabled', function () {
view._encryptionEnabled = false;
$td.find('img').click();

Expand Down Expand Up @@ -375,6 +375,41 @@ describe('OCA.External.Settings tests', function() {
encoding_compatibility: false
});
});

it('does not show the sharing option when sharing is disabled for user shares', function () {
var testCases = [
{
personal: false,
sharingAllowed: false,
expectedVisible: true
},
{
personal: true,
sharingAllowed: false,
expectedVisible: false
},
{
personal: true,
sharingAllowed: true,
expectedVisible: true
},
];

_.each(testCases, function(testCase) {
view._isPersonal = testCase.personal;
view._allowUserMountSharing = testCase.sharingAllowed;

$td.find('img').click();

expect($td.find('.dropdown [name=enable_sharing]:visible').length)
.toEqual(testCase.expectedVisible ? 1 : 0);

$('body').mouseup();

expect($td.find('.dropdown').length).toEqual(0);
});

});
});
});
describe('applicable user list', function() {
Expand Down
14 changes: 13 additions & 1 deletion lib/private/Files/External/ConfigAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@
use OCP\Files\External\IStorageConfig;
use OC\Files\Storage\FailedStorage;
use OCP\Files\StorageNotAvailableException;
use OCP\IConfig;

/**
* Make the old files_external config work with the new public mount config api
*/
class ConfigAdapter implements IMountProvider {

/** @var IConfig */
private $config;

/** @var IUserStoragesService */
private $userStoragesService;

Expand All @@ -52,9 +56,11 @@ class ConfigAdapter implements IMountProvider {
* @param IUserGlobalStoragesService $userGlobalStoragesService
*/
public function __construct(
IConfig $config,
IUserStoragesService $userStoragesService,
IUserGlobalStoragesService $userGlobalStoragesService
) {
$this->config = $config;
$this->userStoragesService = $userStoragesService;
$this->userGlobalStoragesService = $userGlobalStoragesService;
}
Expand Down Expand Up @@ -146,6 +152,7 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
$mounts[$storage->getMountPoint()] = $mount;
}

$allowUserMountSharing = $this->config->getAppValue('core', 'allow_user_mount_sharing', 'yes') === 'yes';
foreach ($this->userStoragesService->getStorages() as $storage) {
try {
$this->prepareStorageConfig($storage, $user);
Expand All @@ -155,14 +162,19 @@ public function getMountsForUser(IUser $user, IStorageFactory $loader) {
$impl = new FailedStorage(['exception' => $e]);
}

$mountOptions = $storage->getMountOptions();
if (!$allowUserMountSharing) {
$mountOptions['enable_sharing'] = false;
}

$mount = new PersonalMount(
$this->userStoragesService,
$storage->getId(),
$impl,
'/' . $user->getUID() . '/files' . $storage->getMountPoint(),
null,
$loader,
$storage->getMountOptions()
$mountOptions
);
$mounts[$storage->getMountPoint()] = $mount;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/private/Files/Storage/Temporary.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ public function __destruct() {
public function getDataDir() {
return $this->datadir;
}

public function getAvailability() {
return ['available' => true, 'last_checked' => 0];
}
}
1 change: 1 addition & 0 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ public function __construct($webRoot, \OC\Config $config) {
// external storage
if ($config->getAppValue('core', 'enable_external_storage', 'no') === 'yes') {
$manager->registerProvider(new \OC\Files\External\ConfigAdapter(
$c->query('AllConfig'),
$c->query('UserStoragesService'),
$c->query('UserGlobalStoragesService')
));
Expand Down
Loading