summaryrefslogtreecommitdiffstats
path: root/apps/files_external/service
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@owncloud.com>2015-09-23 15:35:17 +0100
committerRobin McCorkell <rmccorkell@owncloud.com>2015-09-23 16:00:11 +0100
commit24043333008b12dfbe7374cb318d9041717b87e0 (patch)
tree415d4ddb64db6da0971d6059769a0ef0e63a815f /apps/files_external/service
parent6f5f1c4f142e5e2417b188b55d2f9fadf03749b3 (diff)
downloadnextcloud-server-24043333008b12dfbe7374cb318d9041717b87e0.tar.gz
nextcloud-server-24043333008b12dfbe7374cb318d9041717b87e0.zip
Perform visibility checks on storages
StoragesService::getStorages() will check the visibility of the backend and auth mechanism for the storage, and if either are not visible to the user (aka disabled by admin) then the storage will be filtered out. The original method StoragesService::getAllStorages() still exists in case such storages need to be detected, but its use is discouraged.
Diffstat (limited to 'apps/files_external/service')
-rw-r--r--apps/files_external/service/globalstoragesservice.php9
-rw-r--r--apps/files_external/service/storagesservice.php45
-rw-r--r--apps/files_external/service/userglobalstoragesservice.php2
-rw-r--r--apps/files_external/service/userstoragesservice.php9
4 files changed, 63 insertions, 2 deletions
diff --git a/apps/files_external/service/globalstoragesservice.php b/apps/files_external/service/globalstoragesservice.php
index 0e2d3f2b9c1..49ffea43d1b 100644
--- a/apps/files_external/service/globalstoragesservice.php
+++ b/apps/files_external/service/globalstoragesservice.php
@@ -210,4 +210,13 @@ class GlobalStoragesService extends StoragesService {
);
}
}
+
+ /**
+ * Get the visibility type for this controller, used in validation
+ *
+ * @return string BackendService::VISIBILITY_* constants
+ */
+ public function getVisibilityType() {
+ return BackendService::VISIBILITY_ADMIN;
+ }
}
diff --git a/apps/files_external/service/storagesservice.php b/apps/files_external/service/storagesservice.php
index 703f277d84e..83a82de0bed 100644
--- a/apps/files_external/service/storagesservice.php
+++ b/apps/files_external/service/storagesservice.php
@@ -29,6 +29,8 @@ use \OC\Files\Filesystem;
use \OCA\Files_external\Lib\StorageConfig;
use \OCA\Files_external\NotFoundException;
use \OCA\Files_External\Service\BackendService;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
/**
* Service class to manage external storages
@@ -331,7 +333,7 @@ abstract class StoragesService {
}
/**
- * Gets all storages
+ * Gets all storages, valid or not
*
* @return array array of storage configs
*/
@@ -340,6 +342,47 @@ abstract class StoragesService {
}
/**
+ * Gets all valid storages
+ *
+ * @return array
+ */
+ public function getStorages() {
+ return array_filter($this->getAllStorages(), [$this, 'validateStorage']);
+ }
+
+ /**
+ * Validate storage
+ * FIXME: De-duplicate with StoragesController::validate()
+ *
+ * @param StorageConfig $storage
+ * @return bool
+ */
+ protected function validateStorage(StorageConfig $storage) {
+ /** @var Backend */
+ $backend = $storage->getBackend();
+ /** @var AuthMechanism */
+ $authMechanism = $storage->getAuthMechanism();
+
+ if (!$backend->isVisibleFor($this->getVisibilityType())) {
+ // not permitted to use backend
+ return false;
+ }
+ if (!$authMechanism->isVisibleFor($this->getVisibilityType())) {
+ // not permitted to use auth mechanism
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Get the visibility type for this controller, used in validation
+ *
+ * @return string BackendService::VISIBILITY_* constants
+ */
+ abstract public function getVisibilityType();
+
+ /**
* Add new storage to the configuration
*
* @param array $newStorage storage attributes
diff --git a/apps/files_external/service/userglobalstoragesservice.php b/apps/files_external/service/userglobalstoragesservice.php
index b60473f131e..7c60bc6d497 100644
--- a/apps/files_external/service/userglobalstoragesservice.php
+++ b/apps/files_external/service/userglobalstoragesservice.php
@@ -117,7 +117,7 @@ class UserGlobalStoragesService extends GlobalStoragesService {
* @return StorageConfig[]
*/
public function getUniqueStorages() {
- $storages = $this->getAllStorages();
+ $storages = $this->getStorages();
$storagesByMountpoint = [];
foreach ($storages as $storage) {
diff --git a/apps/files_external/service/userstoragesservice.php b/apps/files_external/service/userstoragesservice.php
index c69b8d4f51e..6e3c327c09c 100644
--- a/apps/files_external/service/userstoragesservice.php
+++ b/apps/files_external/service/userstoragesservice.php
@@ -171,4 +171,13 @@ class UserStoragesService extends StoragesService {
$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
}
}
+
+ /**
+ * Get the visibility type for this controller, used in validation
+ *
+ * @return string BackendService::VISIBILITY_* constants
+ */
+ public function getVisibilityType() {
+ return BackendService::VISIBILITY_PERSONAL;
+ }
}