diff --git a/apps/files_external/appinfo/app.php b/apps/files_external/appinfo/app.php deleted file mode 100644 index 432a2af502d0a..0000000000000 --- a/apps/files_external/appinfo/app.php +++ /dev/null @@ -1,51 +0,0 @@ - - * @author Jan-Christoph Borchardt - * @author Jörn Friedrich Dreyer - * @author Morris Jobke - * @author Robin Appelman - * @author Robin McCorkell - * @author szaimen - * @author Vincent Petry - * - * @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 - * - */ -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); diff --git a/apps/files_external/appinfo/routes.php b/apps/files_external/appinfo/routes.php index bce4b0acdfb3e..df0a9922dd7d6 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 * */ -\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_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/AppInfo/Application.php b/apps/files_external/lib/AppInfo/Application.php index 151b14fdfa9d0..7f6d886335064 100644 --- a/apps/files_external/lib/AppInfo/Application.php +++ b/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\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 @@ public function __construct(array $urlParams = []) { $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} */ diff --git a/apps/files_external/lib/Command/Create.php b/apps/files_external/lib/Command/Create.php index 3fe9e71b17a1e..99991b893cdab 100644 --- a/apps/files_external/lib/Command/Create.php +++ b/apps/files_external/lib/Command/Create.php @@ -119,7 +119,7 @@ protected function configure() { } 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'); diff --git a/apps/files_external/lib/Command/Import.php b/apps/files_external/lib/Command/Import.php index 5d9a6893353b7..53ae0d7c5bf88 100644 --- a/apps/files_external/lib/Command/Import.php +++ b/apps/files_external/lib/Command/Import.php @@ -107,7 +107,7 @@ protected function configure() { } 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'); diff --git a/apps/files_external/lib/Controller/ApiController.php b/apps/files_external/lib/Controller/ApiController.php index d7f24b44cffd8..40539d0bbcaec 100644 --- a/apps/files_external/lib/Controller/ApiController.php +++ b/apps/files_external/lib/Controller/ApiController.php @@ -29,6 +29,9 @@ */ 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 @@ private function formatMount(string $mountPoint, array $mountConfig): array { '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 @@ private function formatMount(string $mountPoint, array $mountConfig): array { */ 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 ca8622ab32d46..97b72005018d0 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 @@ public function setPriority($priority) { /** * 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 @@ public function getApplicableUsers() { /** * 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 @@ public function setApplicableUsers($applicableUsers) { /** * 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 @@ public function getApplicableGroups() { /** * 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/Listener/GroupDeletedListener.php b/apps/files_external/lib/Listener/GroupDeletedListener.php new file mode 100644 index 0000000000000..d274f35d9cfaf --- /dev/null +++ b/apps/files_external/lib/Listener/GroupDeletedListener.php @@ -0,0 +1,45 @@ + + * + * @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 . + * + */ + +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()); + } +} diff --git a/apps/files_external/lib/Listener/UserDeletedListener.php b/apps/files_external/lib/Listener/UserDeletedListener.php new file mode 100644 index 0000000000000..1417119b3179a --- /dev/null +++ b/apps/files_external/lib/Listener/UserDeletedListener.php @@ -0,0 +1,45 @@ + + * + * @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 . + * + */ + +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()); + } +} diff --git a/apps/files_external/lib/MountConfig.php b/apps/files_external/lib/MountConfig.php index 0a9168bbfd740..aa3b662e22406 100644 --- a/apps/files_external/lib/MountConfig.php +++ b/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 @@ private static function prepareMountPointEntry(StorageConfig $storage, $isPerson */ 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 78510c3e3832f..3829a9ea0cea8 100644 --- a/apps/files_external/tests/Service/StoragesServiceTest.php +++ b/apps/files_external/tests/Service/StoragesServiceTest.php @@ -154,6 +154,7 @@ protected function setUp(): void { }); $this->backendService->method('getBackends') ->willReturn($backends); + $this->overwriteService(BackendService::class, $this->backendService); \OCP\Util::connectHook( Filesystem::CLASSNAME, @@ -171,12 +172,6 @@ protected function setUp(): void { 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 { diff --git a/lib/private/Encryption/File.php b/lib/private/Encryption/File.php index 76d8900a40eb1..2c486dfade675 100644 --- a/lib/private/Encryption/File.php +++ b/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 @@ public function getAccessList($path) { // 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); } } diff --git a/lib/private/Encryption/Util.php b/lib/private/Encryption/Util.php index e1f03e2fff19d..dc878ba8fc133 100644 --- a/lib/private/Encryption/Util.php +++ b/lib/private/Encryption/Util.php @@ -32,6 +32,8 @@ 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 @@ public function stripPartialFileExtension($path) { 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 @@ public function getUserWithAccessToMountPoint($users, $groups) { */ 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 @@ public function isSystemWideMountPoint($path, $uid) { /** * 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; }