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 | |
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')
-rw-r--r-- | apps/files_external/appinfo/app.php | 6 | ||||
-rw-r--r-- | apps/files_external/appinfo/routes.php | 59 | ||||
-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 | ||||
-rw-r--r-- | apps/files_external/tests/Service/StoragesServiceTest.php | 7 |
6 files changed, 91 insertions, 159 deletions
diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php index 432a2af502d..92236f2de32 100644 --- a/apps/files_external/appinfo/app.php +++ b/apps/files_external/appinfo/app.php @@ -31,10 +31,10 @@ use OCA\Files_External\Config\ConfigAdapter; require_once __DIR__ . '/../3rdparty/autoload.php'; // register Application object singleton -\OCA\Files_External\MountConfig::$app = \OC::$server->query(\OCA\Files_External\AppInfo\Application::class); -\OCA\Files_External\MountConfig::$app->registerListeners(); +$app = \OC::$server->query(\OCA\Files_External\AppInfo\Application::class); +$app->registerListeners(); -$appContainer = \OCA\Files_External\MountConfig::$app->getContainer(); +$appContainer = $app->getContainer(); \OCA\Files\App::getNavigationManager()->add(function () { $l = \OC::$server->getL10N('files_external'); diff --git a/apps/files_external/appinfo/routes.php b/apps/files_external/appinfo/routes.php index bce4b0acdfb..df0a9922dd7 100644 --- a/apps/files_external/appinfo/routes.php +++ b/apps/files_external/appinfo/routes.php @@ -26,36 +26,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ -\OCA\Files_External\MountConfig::$app->registerRoutes( - $this, - [ - 'resources' => [ - 'global_storages' => ['url' => '/globalstorages'], - 'user_storages' => ['url' => '/userstorages'], - 'user_global_storages' => ['url' => '/userglobalstorages'], - ], - 'routes' => [ - [ - 'name' => 'Ajax#getSshKeys', - 'url' => '/ajax/public_key.php', - 'verb' => 'POST', - 'requirements' => [], - ], - [ - 'name' => 'Ajax#saveGlobalCredentials', - 'url' => '/globalcredentials', - 'verb' => 'POST', - ], - ], - 'ocs' => [ - [ - 'name' => 'Api#getUserMounts', - 'url' => '/api/v1/mounts', - 'verb' => 'GET', - ], - ], - ] -); + $this->create('files_external_oauth1', 'apps/files_external/ajax/oauth1.php') ->actionInclude('files_external/ajax/oauth1.php'); @@ -65,3 +36,31 @@ $this->create('files_external_oauth2', 'apps/files_external/ajax/oauth2.php') $this->create('files_external_list_applicable', '/apps/files_external/applicable') ->actionInclude('files_external/ajax/applicable.php'); + +return [ + 'resources' => [ + 'global_storages' => ['url' => '/globalstorages'], + 'user_storages' => ['url' => '/userstorages'], + 'user_global_storages' => ['url' => '/userglobalstorages'], + ], + 'routes' => [ + [ + 'name' => 'Ajax#getSshKeys', + 'url' => '/ajax/public_key.php', + 'verb' => 'POST', + 'requirements' => [], + ], + [ + 'name' => 'Ajax#saveGlobalCredentials', + 'url' => '/globalcredentials', + 'verb' => 'POST', + ], + ], + 'ocs' => [ + [ + 'name' => 'Api#getUserMounts', + 'url' => '/api/v1/mounts', + 'verb' => 'GET', + ], + ], +]; 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) { diff --git a/apps/files_external/tests/Service/StoragesServiceTest.php b/apps/files_external/tests/Service/StoragesServiceTest.php index 78510c3e383..3829a9ea0ce 100644 --- a/apps/files_external/tests/Service/StoragesServiceTest.php +++ b/apps/files_external/tests/Service/StoragesServiceTest.php @@ -154,6 +154,7 @@ abstract class StoragesServiceTest extends \Test\TestCase { }); $this->backendService->method('getBackends') ->willReturn($backends); + $this->overwriteService(BackendService::class, $this->backendService); \OCP\Util::connectHook( Filesystem::CLASSNAME, @@ -171,12 +172,6 @@ abstract class StoragesServiceTest extends \Test\TestCase { return $this->backendService; } }); - - \OCA\Files_External\MountConfig::$app = $this->getMockBuilder('\OCA\Files_External\Appinfo\Application') - ->disableOriginalConstructor() - ->getMock(); - \OCA\Files_External\MountConfig::$app->method('getContainer') - ->willReturn($containerMock); } protected function tearDown(): void { |