Allow admins to disable certain external storages for users

Fix issue #6793
This commit is contained in:
Joas Schilling 2014-02-18 16:36:02 +01:00
parent 2f0db9af07
commit 932c4ee927
5 changed files with 74 additions and 13 deletions

View File

@ -302,13 +302,23 @@ $(document).ready(function() {
});
$('#allowUserMounting').bind('change', function() {
OC.msg.startSaving('#userMountingMsg');
if (this.checked) {
OC.AppConfig.setValue('files_external', 'allow_user_mounting', 'yes');
$('#userMountingBackups').removeClass('hidden');
} else {
OC.AppConfig.setValue('files_external', 'allow_user_mounting', 'no');
$('#userMountingBackups').addClass('hidden');
}
OC.msg.finishedSaving('#userMountingMsg', {status: 'success', data: {message: t('settings', 'Saved')}});
});
$('input[name="allowUserMountingBackends\\[\\]"]').bind('change', function() {
OC.msg.startSaving('#userMountingMsg');
var user_mounting_backends = $('input[name="allowUserMountingBackends\\[\\]"]:checked').map(function(){return $(this).val();}).get();
OC.AppConfig.setValue('files_external', 'user_mounting_backends', user_mounting_backends.join());
OC.msg.finishedSaving('#userMountingMsg', {status: 'success', data: {message: t('settings', 'Saved')}});
});
});
})();

View File

@ -155,6 +155,35 @@ class OC_Mount_Config {
return($backends);
}
/**
* Get details on each of the external storage backends, used for the mount config UI
* Some backends are not available as a personal backend, f.e. Local and such that have
* been disabled by the admin.
*
* If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded
* If the configuration parameter should be secret, add a '*' to the beginning of the value
* If the configuration parameter is a boolean, add a '!' to the beginning of the value
* If the configuration parameter is optional, add a '&' to the beginning of the value
* If the configuration parameter is hidden, add a '#' to the beginning of the value
* @return array
*/
public static function getPersonalBackends() {
$backends = self::getBackends();
// Remove local storage and other disabled storages
unset($backends['\OC\Files\Storage\Local']);
$allowed_backends = explode(',', OCP\Config::getAppValue('files_external', 'user_mounting_backends', ''));
foreach ($backends as $backend => $null) {
if (!in_array($backend, $allowed_backends)) {
unset($backends[$backend]);
}
}
return $backends;
}
/**
* Get the system mount points
* The returned array is not in the same format as getUserMountPoints()
@ -287,11 +316,12 @@ class OC_Mount_Config {
if (!isset($backends[$class])) {
// invalid backend
return false;
}
}
if ($isPersonal) {
// Verify that the mount point applies for the current user
// Prevent non-admin users from mounting local storage
if ($applicable !== OCP\User::getUser() || strtolower($class) === '\oc\files\storage\local') {
// Prevent non-admin users from mounting local storage and other disabled backends
$allowed_backends = self::getPersonalBackends();
if ($applicable != OCP\User::getUser() || !in_array($class, $allowed_backends)) {
return false;
}
$mountPoint = '/'.$applicable.'/files/'.ltrim($mountPoint, '/');

View File

@ -22,9 +22,8 @@
OCP\Util::addScript('files_external', 'settings');
OCP\Util::addStyle('files_external', 'settings');
$backends = OC_Mount_Config::getBackends();
// Remove local storage
unset($backends['\OC\Files\Storage\Local']);
$backends = OC_Mount_Config::getPersonalBackends();
$tmpl = new OCP\Template('files_external', 'settings');
$tmpl->assign('isAdminPage', false);
$tmpl->assign('mounts', OC_Mount_Config::getPersonalMountPoints());

View File

@ -26,10 +26,26 @@ OCP\Util::addScript('files_external', 'settings');
OCP\Util::addscript('3rdparty', 'chosen/chosen.jquery.min');
OCP\Util::addStyle('files_external', 'settings');
OCP\Util::addStyle('3rdparty', 'chosen/chosen');
$backends = OC_Mount_Config::getBackends();
$personal_backends = array();
$enabled_backends = explode(',', OCP\Config::getAppValue('files_external', 'user_mounting_backends', ''));
foreach ($backends as $class => $backend)
{
if ($class != '\OC\Files\Storage\Local')
{
$personal_backends[$class] = array(
'backend' => $backend['backend'],
'enabled' => in_array($class, $enabled_backends),
);
}
}
$tmpl = new OCP\Template('files_external', 'settings');
$tmpl->assign('isAdminPage', true);
$tmpl->assign('mounts', OC_Mount_Config::getSystemMountPoints());
$tmpl->assign('backends', OC_Mount_Config::getBackends());
$tmpl->assign('backends', $backends);
$tmpl->assign('personal_backends', $personal_backends);
$tmpl->assign('groups', OC_Group::getGroups());
$tmpl->assign('users', OCP\User::getUsers());
$tmpl->assign('userDisplayNames', OC_User::getDisplayNames());

View File

@ -122,12 +122,18 @@
<?php if ($_['isAdminPage']): ?>
<br />
<input type="checkbox"
name="allowUserMounting"
id="allowUserMounting"
value="1" <?php if ($_['allowUserMounting'] == 'yes') print_unescaped(' checked="checked"'); ?> />
<label for="allowUserMounting"><?php p($l->t('Enable User External Storage')); ?></label><br/>
<em><?php p($l->t('Allow users to mount their own external storage')); ?></em>
<input type="checkbox" name="allowUserMounting" id="allowUserMounting"
value="1" <?php if ($_['allowUserMounting'] == 'yes') print_unescaped(' checked="checked"'); ?> />
<label for="allowUserMounting"><?php p($l->t('Enable User External Storage')); ?></label> <span id="userMountingMsg" class="msg"></span>
<p id="userMountingBackups"<?php if ($_['allowUserMounting'] != 'yes'): ?> class="hidden"<?php endif; ?>>
<?php p($l->t('Allow users to mount the following external storage')); ?><br />
<?php $i = 0; foreach ($_['personal_backends'] as $class => $backend): ?>
<input type="checkbox" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($class); ?>" <?php if ($backend['enabled']) print_unescaped(' checked="checked"'); ?> />
<label for="allowUserMountingBackends<?php p($i); ?>"><?php p($backend['backend']); ?></label> <br />
<?php $i++; ?>
<?php endforeach; ?>
</p>
<?php endif; ?>
</fieldset>
</form>