Browse Source

Merge pull request #26319 from nextcloud/files_external_app.php

Move files_external to IBootstrap and remove some deprecated stuff in the process
Morris Jobke 2 years ago
parent
commit
4c93249514

+ 0 - 51
apps/files_external/appinfo/app.php

@@ -1,51 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Jan-Christoph Borchardt <hey@jancborchardt.net>
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Robin McCorkell <robin@mccorkell.me.uk>
- * @author szaimen <szaimen@e.mail.de>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-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();
-
-$appContainer = \OCA\Files_External\MountConfig::$app->getContainer();
-
-\OCA\Files\App::getNavigationManager()->add(function () {
-	$l = \OC::$server->getL10N('files_external');
-	return [
-		'id' => 'extstoragemounts',
-		'appname' => 'files_external',
-		'script' => 'list.php',
-		'order' => 30,
-		'name' => $l->t('External storage'),
-	];
-});
-
-$mountProvider = $appContainer->query(ConfigAdapter::class);
-\OC::$server->getMountProviderCollection()->registerProvider($mountProvider);

+ 29 - 30
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',
+		],
+	],
+];

+ 37 - 36
apps/files_external/lib/AppInfo/Application.php

@@ -29,8 +29,10 @@
  */
 namespace OCA\Files_External\AppInfo;
 
+use OCA\Files_External\Config\ConfigAdapter;
 use OCA\Files_External\Config\UserPlaceholderHandler;
-use OCA\Files_External\Service\DBConfigService;
+use OCA\Files_External\Listener\GroupDeletedListener;
+use OCA\Files_External\Listener\UserDeletedListener;
 use OCA\Files_External\Lib\Auth\AmazonS3\AccessKey;
 use OCA\Files_External\Lib\Auth\Builtin;
 use OCA\Files_External\Lib\Auth\NullMechanism;
@@ -62,14 +64,19 @@ use OCA\Files_External\Lib\Config\IAuthMechanismProvider;
 use OCA\Files_External\Lib\Config\IBackendProvider;
 use OCA\Files_External\Service\BackendService;
 use OCP\AppFramework\App;
-use OCP\IGroup;
-use OCP\IUser;
-use Symfony\Component\EventDispatcher\GenericEvent;
+use OCP\AppFramework\Bootstrap\IBootContext;
+use OCP\AppFramework\Bootstrap\IBootstrap;
+use OCP\AppFramework\Bootstrap\IRegistrationContext;
+use OCP\Files\Config\IMountProviderCollection;
+use OCP\Group\Events\GroupDeletedEvent;
+use OCP\User\Events\UserDeletedEvent;
+
+require_once __DIR__ . '/../../3rdparty/autoload.php';
 
 /**
  * @package OCA\Files_External\AppInfo
  */
-class Application extends App implements IBackendProvider, IAuthMechanismProvider {
+class Application extends App implements IBackendProvider, IAuthMechanismProvider, IBootstrap {
 
 	/**
 	 * Application constructor.
@@ -78,15 +85,33 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide
 	 */
 	public function __construct(array $urlParams = []) {
 		parent::__construct('files_external', $urlParams);
+	}
 
-		$container = $this->getContainer();
+	public function register(IRegistrationContext $context): void {
+		$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class);
+		$context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class);
+	}
 
-		/** @var BackendService $backendService */
-		$backendService = $container->query(BackendService::class);
-		$backendService->registerBackendProvider($this);
-		$backendService->registerAuthMechanismProvider($this);
-		$backendService->registerConfigHandler('user', function () use ($container) {
-			return $container->query(UserPlaceholderHandler::class);
+	public function boot(IBootContext $context): void {
+		$context->injectFn(function (IMountProviderCollection $mountProviderCollection, ConfigAdapter $configAdapter) {
+			$mountProviderCollection->registerProvider($configAdapter);
+		});
+		\OCA\Files\App::getNavigationManager()->add(function () {
+			$l = \OC::$server->getL10N('files_external');
+			return [
+				'id' => 'extstoragemounts',
+				'appname' => 'files_external',
+				'script' => 'list.php',
+				'order' => 30,
+				'name' => $l->t('External storage'),
+			];
+		});
+		$context->injectFn(function (BackendService $backendService, UserPlaceholderHandler $userConfigHandler) {
+			$backendService->registerBackendProvider($this);
+			$backendService->registerAuthMechanismProvider($this);
+			$backendService->registerConfigHandler('user', function () use ($userConfigHandler) {
+				return $userConfigHandler;
+			});
 		});
 
 		// force-load auth mechanisms since some will register hooks
@@ -94,30 +119,6 @@ class Application extends App implements IBackendProvider, IAuthMechanismProvide
 		$this->getAuthMechanisms();
 	}
 
-	public function registerListeners() {
-		$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
-		$dispatcher->addListener(
-			IUser::class . '::postDelete',
-			function (GenericEvent $event) {
-				/** @var IUser $user */
-				$user = $event->getSubject();
-				/** @var DBConfigService $config */
-				$config = $this->getContainer()->query(DBConfigService::class);
-				$config->modifyMountsOnUserDelete($user->getUID());
-			}
-		);
-		$dispatcher->addListener(
-			IGroup::class . '::postDelete',
-			function (GenericEvent $event) {
-				/** @var IGroup $group */
-				$group = $event->getSubject();
-				/** @var DBConfigService $config */
-				$config = $this->getContainer()->query(DBConfigService::class);
-				$config->modifyMountsOnGroupDelete($group->getGID());
-			}
-		);
-	}
-
 	/**
 	 * @{inheritdoc}
 	 */

+ 1 - 1
apps/files_external/lib/Command/Create.php

@@ -119,7 +119,7 @@ class Create extends Base {
 	}
 
 	protected function execute(InputInterface $input, OutputInterface $output): int {
-		$user = $input->getOption('user');
+		$user = (string) $input->getOption('user');
 		$mountPoint = $input->getArgument('mount_point');
 		$storageIdentifier = $input->getArgument('storage_backend');
 		$authIdentifier = $input->getArgument('authentication_backend');

+ 1 - 1
apps/files_external/lib/Command/Import.php

@@ -107,7 +107,7 @@ class Import extends Base {
 	}
 
 	protected function execute(InputInterface $input, OutputInterface $output): int {
-		$user = $input->getOption('user');
+		$user = (string) $input->getOption('user');
 		$path = $input->getArgument('path');
 		if ($path === '-') {
 			$json = file_get_contents('php://stdin');

+ 34 - 17
apps/files_external/lib/Controller/ApiController.php

@@ -29,6 +29,9 @@ declare(strict_types=1);
  */
 namespace OCA\Files_External\Controller;
 
+use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\Service\UserGlobalStoragesService;
+use OCA\Files_External\Service\UserStoragesService;
 use OCP\AppFramework\Http\DataResponse;
 use OCP\AppFramework\OCSController;
 use OCP\IRequest;
@@ -38,35 +41,41 @@ 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 +87,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 +105,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);
 		}
 

+ 6 - 6
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)) {

+ 45 - 0
apps/files_external/lib/Listener/GroupDeletedListener.php

@@ -0,0 +1,45 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_External\Listener;
+
+use OCA\Files_External\Service\DBConfigService;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\Group\Events\GroupDeletedEvent;
+
+class GroupDeletedListener implements IEventListener {
+	/** @var DBConfigService */
+	private $config;
+
+	public function __construct(DBConfigService $config) {
+		$this->config = $config;
+	}
+
+	public function handle(Event $event): void {
+		if (!$event instanceof GroupDeletedEvent) {
+			return;
+		}
+		$this->config->modifyMountsOnGroupDelete($event->getGroup()->getGID());
+	}
+}

+ 45 - 0
apps/files_external/lib/Listener/UserDeletedListener.php

@@ -0,0 +1,45 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2021 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\Files_External\Listener;
+
+use OCA\Files_External\Service\DBConfigService;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\User\Events\UserDeletedEvent;
+
+class UserDeletedListener implements IEventListener {
+	/** @var DBConfigService */
+	private $config;
+
+	public function __construct(DBConfigService $config) {
+		$this->config = $config;
+	}
+
+	public function handle(Event $event): void {
+		if (!$event instanceof UserDeletedEvent) {
+			return;
+		}
+		$this->config->modifyMountsOnUserDelete($event->getUser()->getUID());
+	}
+}

+ 16 - 100
apps/files_external/lib/MountConfig.php

@@ -39,17 +39,14 @@
  */
 namespace OCA\Files_External;
 
-use OCA\Files_External\AppInfo\Application;
 use OCA\Files_External\Config\IConfigHandler;
 use OCA\Files_External\Config\UserContext;
 use OCA\Files_External\Lib\Backend\Backend;
-use OCA\Files_External\Lib\StorageConfig;
 use OCA\Files_External\Service\BackendService;
 use OCA\Files_External\Service\GlobalStoragesService;
 use OCA\Files_External\Service\UserGlobalStoragesService;
 use OCA\Files_External\Service\UserStoragesService;
 use OCP\Files\StorageNotAvailableException;
-use OCP\IUserManager;
 use phpseclib\Crypt\AES;
 
 /**
@@ -66,102 +63,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 +89,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) {

+ 1 - 6
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 {

+ 7 - 4
lib/private/Encryption/File.php

@@ -28,6 +28,7 @@
 namespace OC\Encryption;
 
 use OC\Cache\CappedMemoryCache;
+use OCA\Files_External\Service\GlobalStoragesService;
 use OCP\Files\IRootFolder;
 use OCP\Files\NotFoundException;
 use OCP\Share\IManager;
@@ -110,10 +111,12 @@ class File implements \OCP\Encryption\IFile {
 
 		// check if it is a group mount
 		if (\OCP\App::isEnabled("files_external")) {
-			$mounts = \OCA\Files_External\MountConfig::getSystemMountPoints();
-			foreach ($mounts as $mount) {
-				if ($mount['mountpoint'] == substr($ownerPath, 1, strlen($mount['mountpoint']))) {
-					$mountedFor = $this->util->getUserWithAccessToMountPoint($mount['applicable']['users'], $mount['applicable']['groups']);
+			/** @var GlobalStoragesService $storageService */
+			$storageService = \OC::$server->get(GlobalStoragesService::class);
+			$storages = $storageService->getAllStorages();
+			foreach ($storages as $storage) {
+				if ($storage->getMountPoint() == substr($ownerPath, 0, strlen($storage->getMountPoint()))) {
+					$mountedFor = $this->util->getUserWithAccessToMountPoint($storage->getApplicableUsers(), $storage->getApplicableGroups());
 					$userIds = array_merge($userIds, $mountedFor);
 				}
 			}

+ 17 - 11
lib/private/Encryption/Util.php

@@ -32,6 +32,8 @@ use OC\Encryption\Exceptions\EncryptionHeaderToLargeException;
 use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
 use OC\Files\Filesystem;
 use OC\Files\View;
+use OCA\Files_External\Lib\StorageConfig;
+use OCA\Files_External\Service\GlobalStoragesService;
 use OCP\Encryption\IEncryptionModule;
 use OCP\IConfig;
 use OCP\IUser;
@@ -265,7 +267,7 @@ class Util {
 
 	public function getUserWithAccessToMountPoint($users, $groups) {
 		$result = [];
-		if (in_array('all', $users)) {
+		if ($users === [] && $groups === []) {
 			$users = $this->userManager->search('', null, null);
 			$result = array_map(function (IUser $user) {
 				return $user->getUID();
@@ -298,10 +300,12 @@ class Util {
 	 */
 	public function isSystemWideMountPoint($path, $uid) {
 		if (\OCP\App::isEnabled("files_external")) {
-			$mounts = \OCA\Files_External\MountConfig::getSystemMountPoints();
-			foreach ($mounts as $mount) {
-				if (strpos($path, '/files/' . $mount['mountpoint']) === 0) {
-					if ($this->isMountPointApplicableToUser($mount, $uid)) {
+			/** @var GlobalStoragesService $storageService */
+			$storageService = \OC::$server->get(GlobalStoragesService::class);
+			$storages = $storageService->getAllStorages();
+			foreach ($storages as $storage) {
+				if (strpos($path, '/files/' . $storage->getMountPoint()) === 0) {
+					if ($this->isMountPointApplicableToUser($storage, $uid)) {
 						return true;
 					}
 				}
@@ -313,19 +317,21 @@ class Util {
 	/**
 	 * check if mount point is applicable to user
 	 *
-	 * @param array $mount contains $mount['applicable']['users'], $mount['applicable']['groups']
+	 * @param StorageConfig $mount
 	 * @param string $uid
 	 * @return boolean
 	 */
-	private function isMountPointApplicableToUser($mount, $uid) {
-		$acceptedUids = ['all', $uid];
+	private function isMountPointApplicableToUser(StorageConfig $mount, string $uid) {
+		if ($mount->getApplicableUsers() === [] && $mount->getApplicableGroups() === []) {
+			// applicable for everyone
+			return true;
+		}
 		// check if mount point is applicable for the user
-		$intersection = array_intersect($acceptedUids, $mount['applicable']['users']);
-		if (!empty($intersection)) {
+		if (array_search($uid, $mount->getApplicableUsers()) !== false) {
 			return true;
 		}
 		// check if mount point is applicable for group where the user is a member
-		foreach ($mount['applicable']['groups'] as $gid) {
+		foreach ($mount->getApplicableGroups() as $gid) {
 			if ($this->groupManager->isInGroup($uid, $gid)) {
 				return true;
 			}