From 932c4ee927f278f4ef5275a9582bca8822310738 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 18 Feb 2014 16:36:02 +0100 Subject: Allow admins to disable certain external storages for users Fix issue #6793 --- apps/files_external/lib/config.php | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'apps/files_external/lib/config.php') diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index 43275d36c06..778f9620d53 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -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, '/'); -- cgit v1.2.3