diff options
author | Robin Appelman <robin@icewind.nl> | 2021-03-26 15:07:39 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-06-16 13:55:19 +0200 |
commit | 1052feabede4b9054047f60aaa6fe4e04e89c434 (patch) | |
tree | 7f87fd18601f2f0648f85c5f066dcc0647c05910 /apps/files_external/lib/Controller | |
parent | 7917f4cf763a3f35f81f500b5f5b5135cd136518 (diff) | |
download | nextcloud-server-1052feabede4b9054047f60aaa6fe4e04e89c434.tar.gz nextcloud-server-1052feabede4b9054047f60aaa6fe4e04e89c434.zip |
remove depricated methods from MountConfig
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_external/lib/Controller')
-rw-r--r-- | apps/files_external/lib/Controller/ApiController.php | 53 |
1 files changed, 36 insertions, 17 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); } |