diff options
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r-- | apps/files_external/lib/Controller/ApiController.php | 53 | ||||
-rw-r--r-- | apps/files_external/lib/Lib/StorageConfig.php | 12 | ||||
-rw-r--r-- | apps/files_external/lib/MountConfig.php | 113 |
3 files changed, 58 insertions, 120 deletions
diff --git a/apps/files_external/lib/Controller/ApiController.php b/apps/files_external/lib/Controller/ApiController.php index d7f24b44cff..906bd7d0f4b 100644 --- a/apps/files_external/lib/Controller/ApiController.php +++ b/apps/files_external/lib/Controller/ApiController.php @@ -29,44 +29,55 @@ declare(strict_types=1); */ namespace OCA\Files_External\Controller; +use OCA\Files_External\Lib\StorageConfig; +use OCA\Files_External\MountConfig; +use OCA\Files_External\Service\UserGlobalStoragesService; +use OCA\Files_External\Service\UserStoragesService; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCSController; use OCP\IRequest; +use OCP\IUserManager; use OCP\IUserSession; class ApiController extends OCSController { /** @var IUserSession */ private $userSession; + /** @var UserGlobalStoragesService */ + private $userGlobalStoragesService; + /** @var UserStoragesService */ + private $userStoragesService; - public function __construct(string $appName, - IRequest $request, - IUserSession $userSession) { + public function __construct( + string $appName, + IRequest $request, + IUserSession $userSession, + UserGlobalStoragesService $userGlobalStorageService, + UserStoragesService $userStorageService + ) { parent::__construct($appName, $request); $this->userSession = $userSession; + $this->userGlobalStoragesService = $userGlobalStorageService; + $this->userStoragesService = $userStorageService; } /** * Formats the given mount config to a mount entry. * * @param string $mountPoint mount point name, relative to the data dir - * @param array $mountConfig mount config to format + * @param StorageConfig $mountConfig mount config to format * * @return array entry */ - private function formatMount(string $mountPoint, array $mountConfig): array { - // strip "/$user/files" from mount point - $mountPoint = explode('/', trim($mountPoint, '/'), 3); - $mountPoint = $mountPoint[2] ?? ''; - + private function formatMount(string $mountPoint, StorageConfig $mountConfig): array { // split path from mount point $path = \dirname($mountPoint); - if ($path === '.') { + if ($path === '.' || $path === '/') { $path = ''; } - $isSystemMount = !$mountConfig['personal']; + $isSystemMount = $mountConfig->getType() === StorageConfig::MOUNT_TYPE_ADMIN; $permissions = \OCP\Constants::PERMISSION_READ; // personal mounts can be deleted @@ -78,11 +89,11 @@ class ApiController extends OCSController { 'name' => basename($mountPoint), 'path' => $path, 'type' => 'dir', - 'backend' => $mountConfig['backend'], + 'backend' => $mountConfig->getBackend()->getText(), 'scope' => $isSystemMount ? 'system' : 'personal', 'permissions' => $permissions, - 'id' => $mountConfig['id'], - 'class' => $mountConfig['class'] + 'id' => $mountConfig->getId(), + 'class' => $mountConfig->getBackend()->getIdentifier(), ]; return $entry; } @@ -96,10 +107,18 @@ class ApiController extends OCSController { */ public function getUserMounts(): DataResponse { $entries = []; - $user = $this->userSession->getUser()->getUID(); + $mountPoints = []; + + foreach ($this->userGlobalStoragesService->getStorages() as $storage) { + $mountPoint = $storage->getMountPoint(); + $mountPoints[$mountPoint] = $storage; + } - $mounts = \OCA\Files_External\MountConfig::getAbsoluteMountPoints($user); - foreach ($mounts as $mountPoint => $mount) { + foreach ($this->userStoragesService->getStorages() as $storage) { + $mountPoint = $storage->getMountPoint(); + $mountPoints[$mountPoint] = $storage; + } + foreach ($mountPoints as $mountPoint => $mount) { $entries[] = $this->formatMount($mountPoint, $mount); } diff --git a/apps/files_external/lib/Lib/StorageConfig.php b/apps/files_external/lib/Lib/StorageConfig.php index ca8622ab32d..97b72005018 100644 --- a/apps/files_external/lib/Lib/StorageConfig.php +++ b/apps/files_external/lib/Lib/StorageConfig.php @@ -98,14 +98,14 @@ class StorageConfig implements \JsonSerializable { /** * List of users who have access to this storage * - * @var array + * @var string[] */ private $applicableUsers = []; /** * List of groups that have access to this storage * - * @var array + * @var string[] */ private $applicableGroups = []; @@ -272,7 +272,7 @@ class StorageConfig implements \JsonSerializable { /** * Returns the users for which to mount this storage * - * @return array applicable users + * @return string[] applicable users */ public function getApplicableUsers() { return $this->applicableUsers; @@ -281,7 +281,7 @@ class StorageConfig implements \JsonSerializable { /** * Sets the users for which to mount this storage * - * @param array|null $applicableUsers applicable users + * @param string[]|null $applicableUsers applicable users */ public function setApplicableUsers($applicableUsers) { if (is_null($applicableUsers)) { @@ -293,7 +293,7 @@ class StorageConfig implements \JsonSerializable { /** * Returns the groups for which to mount this storage * - * @return array applicable groups + * @return string[] applicable groups */ public function getApplicableGroups() { return $this->applicableGroups; @@ -302,7 +302,7 @@ class StorageConfig implements \JsonSerializable { /** * Sets the groups for which to mount this storage * - * @param array|null $applicableGroups applicable groups + * @param string[]|null $applicableGroups applicable groups */ public function setApplicableGroups($applicableGroups) { if (is_null($applicableGroups)) { diff --git a/apps/files_external/lib/MountConfig.php b/apps/files_external/lib/MountConfig.php index 0a9168bbfd7..741368a6996 100644 --- a/apps/files_external/lib/MountConfig.php +++ b/apps/files_external/lib/MountConfig.php @@ -66,102 +66,21 @@ class MountConfig { // whether to skip backend test (for unit tests, as this static class is not mockable) public static $skipTest = false; - /** @var Application */ - public static $app; - - /** - * Returns the mount points for the given user. - * The mount point is relative to the data directory. - * - * @param string $uid user - * @return array of mount point string as key, mountpoint config as value - * - * @deprecated 8.2.0 use UserGlobalStoragesService::getStorages() and UserStoragesService::getStorages() - */ - public static function getAbsoluteMountPoints($uid) { - $mountPoints = []; - - $userGlobalStoragesService = self::$app->getContainer()->query(UserGlobalStoragesService::class); - $userStoragesService = self::$app->getContainer()->query(UserStoragesService::class); - $user = self::$app->getContainer()->query(IUserManager::class)->get($uid); - - $userGlobalStoragesService->setUser($user); - $userStoragesService->setUser($user); - - foreach ($userGlobalStoragesService->getStorages() as $storage) { - /** @var \OCA\Files_External\Lib\StorageConfig $storage */ - $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint(); - $mountEntry = self::prepareMountPointEntry($storage, false); - foreach ($mountEntry['options'] as &$option) { - $option = self::substitutePlaceholdersInConfig($option, $uid); - } - $mountPoints[$mountPoint] = $mountEntry; - } - - foreach ($userStoragesService->getStorages() as $storage) { - $mountPoint = '/'.$uid.'/files'.$storage->getMountPoint(); - $mountEntry = self::prepareMountPointEntry($storage, true); - foreach ($mountEntry['options'] as &$option) { - $option = self::substitutePlaceholdersInConfig($option, $uid); - } - $mountPoints[$mountPoint] = $mountEntry; - } - - $userGlobalStoragesService->resetUser(); - $userStoragesService->resetUser(); - - return $mountPoints; - } - - /** - * Get the system mount points - * - * @return array - * - * @deprecated 8.2.0 use GlobalStoragesService::getStorages() - */ - public static function getSystemMountPoints() { - $mountPoints = []; - $service = self::$app->getContainer()->query(GlobalStoragesService::class); - - foreach ($service->getStorages() as $storage) { - $mountPoints[] = self::prepareMountPointEntry($storage, false); - } - - return $mountPoints; - } - - /** - * Convert a StorageConfig to the legacy mountPoints array format - * There's a lot of extra information in here, to satisfy all of the legacy functions - * - * @param StorageConfig $storage - * @param bool $isPersonal - * @return array - */ - private static function prepareMountPointEntry(StorageConfig $storage, $isPersonal) { - $mountEntry = []; - - $mountEntry['mountpoint'] = substr($storage->getMountPoint(), 1); // remove leading slash - $mountEntry['class'] = $storage->getBackend()->getIdentifier(); - $mountEntry['backend'] = $storage->getBackend()->getText(); - $mountEntry['authMechanism'] = $storage->getAuthMechanism()->getIdentifier(); - $mountEntry['personal'] = $isPersonal; - $mountEntry['options'] = self::decryptPasswords($storage->getBackendOptions()); - $mountEntry['mountOptions'] = $storage->getMountOptions(); - $mountEntry['priority'] = $storage->getPriority(); - $mountEntry['applicable'] = [ - 'groups' => $storage->getApplicableGroups(), - 'users' => $storage->getApplicableUsers(), - ]; - // if mountpoint is applicable to all users the old API expects ['all'] - if (empty($mountEntry['applicable']['groups']) && empty($mountEntry['applicable']['users'])) { - $mountEntry['applicable']['users'] = ['all']; - } - - $mountEntry['id'] = $storage->getId(); - - return $mountEntry; + /** @var UserGlobalStoragesService */ + private $userGlobalStorageService; + /** @var UserStoragesService */ + private $userStorageService; + /** @var GlobalStoragesService */ + private $globalStorageService; + + public function __construct( + UserGlobalStoragesService $userGlobalStorageService, + UserStoragesService $userStorageService, + GlobalStoragesService $globalStorageService + ) { + $this->userGlobalStorageService = $userGlobalStorageService; + $this->userStorageService = $userStorageService; + $this->globalStorageService = $globalStorageService; } /** @@ -173,7 +92,7 @@ class MountConfig { */ public static function substitutePlaceholdersInConfig($input, string $userId = null) { /** @var BackendService $backendService */ - $backendService = self::$app->getContainer()->query(BackendService::class); + $backendService = \OC::$server->get(BackendService::class); /** @var IConfigHandler[] $handlers */ $handlers = $backendService->getConfigHandlers(); foreach ($handlers as $handler) { |