summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan-Christoph Borchardt <hey@jancborchardt.net>2014-03-05 14:41:36 +0100
committerJan-Christoph Borchardt <hey@jancborchardt.net>2014-03-05 14:41:36 +0100
commitbd866427471ec178602959afdce8851979501c45 (patch)
treed1d059b9ce00ca7b9b3409bf253cb4ebc29c4f62
parent36d7c0b6a7ed79ec1c578476a797648715b3b000 (diff)
parent932c4ee927f278f4ef5275a9582bca8822310738 (diff)
downloadnextcloud-server-bd866427471ec178602959afdce8851979501c45.tar.gz
nextcloud-server-bd866427471ec178602959afdce8851979501c45.zip
Merge pull request #7261 from owncloud/issue/6793
Allow admins to disable certain external storages for users
-rw-r--r--apps/files_external/js/settings.js10
-rwxr-xr-xapps/files_external/lib/config.php36
-rwxr-xr-xapps/files_external/personal.php5
-rw-r--r--apps/files_external/settings.php18
-rw-r--r--apps/files_external/templates/settings.php18
5 files changed, 74 insertions, 13 deletions
diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js
index 895f97bd2c3..dbc9f548292 100644
--- a/apps/files_external/js/settings.js
+++ b/apps/files_external/js/settings.js
@@ -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')}});
+ });
});
})();
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index 8456b81d255..1069e2b42eb 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -156,6 +156,35 @@ class OC_Mount_Config {
}
/**
+ * 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()
* @return array
@@ -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, '/');
diff --git a/apps/files_external/personal.php b/apps/files_external/personal.php
index 90f5e159535..90d7afed28b 100755
--- a/apps/files_external/personal.php
+++ b/apps/files_external/personal.php
@@ -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());
diff --git a/apps/files_external/settings.php b/apps/files_external/settings.php
index 31183409e39..5b62b542200 100644
--- a/apps/files_external/settings.php
+++ b/apps/files_external/settings.php
@@ -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());
diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php
index 3ca16c3c7a8..de44d3c8644 100644
--- a/apps/files_external/templates/settings.php
+++ b/apps/files_external/templates/settings.php
@@ -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>