Compare commits

...

5 Commits

Author SHA1 Message Date
Robin Appelman c0436c367b
fix some types
Signed-off-by: Robin Appelman <robin@icewind.nl>
2021-03-26 16:06:46 +01:00
Robin Appelman 622ba4f0c8
move logic from contstructor to boot method
Signed-off-by: Robin Appelman <robin@icewind.nl>
2021-03-26 15:49:49 +01:00
Robin Appelman 369e9f50f3
move user/group deleted listeners to new event listener service
Signed-off-by: Robin Appelman <robin@icewind.nl>
2021-03-26 15:24:51 +01:00
Robin Appelman 347c29d758
move files_external to IBootstrap
Signed-off-by: Robin Appelman <robin@icewind.nl>
2021-03-26 15:20:13 +01:00
Robin Appelman eb511101fe
remove depricated methods from MountConfig
Signed-off-by: Robin Appelman <robin@icewind.nl>
2021-03-26 15:07:39 +01:00
13 changed files with 237 additions and 262 deletions

View File

@ -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 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 storages'),
];
});
$mountProvider = $appContainer->query(ConfigAdapter::class);
\OC::$server->getMountProviderCollection()->registerProvider($mountProvider);

View File

@ -30,36 +30,6 @@
/**
* @var $this \OCP\Route\IRouter
**/
\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');
@ -69,3 +39,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',
],
],
];

View File

@ -30,8 +30,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;
@ -63,14 +65,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.
@ -79,15 +86,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 storages'),
];
});
$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
@ -95,30 +120,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}
*/

View File

@ -120,7 +120,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');

View File

@ -108,7 +108,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');

View File

@ -30,6 +30,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;
@ -39,35 +42,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
@ -79,11 +88,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;
}
@ -97,10 +106,18 @@ class ApiController extends OCSController {
*/
public function getUserMounts(): DataResponse {
$entries = [];
$user = $this->userSession->getUser()->getUID();
$mountPoints = [];
$mounts = \OCA\Files_External\MountConfig::getAbsoluteMountPoints($user);
foreach ($mounts as $mountPoint => $mount) {
foreach ($this->userGlobalStoragesService->getStorages() as $storage) {
$mountPoint = $storage->getMountPoint();
$mountPoints[$mountPoint] = $storage;
}
foreach ($this->userStoragesService->getStorages() as $storage) {
$mountPoint = $storage->getMountPoint();
$mountPoints[$mountPoint] = $storage;
}
foreach ($mountPoints as $mountPoint => $mount) {
$entries[] = $this->formatMount($mountPoint, $mount);
}

View File

@ -99,14 +99,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 = [];
@ -273,7 +273,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;
@ -282,7 +282,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)) {
@ -294,7 +294,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;
@ -303,7 +303,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)) {

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -40,17 +40,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;
/**
@ -67,102 +64,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;
/** @var UserGlobalStoragesService */
private $userGlobalStorageService;
/** @var UserStoragesService */
private $userStorageService;
/** @var GlobalStoragesService */
private $globalStorageService;
/**
* 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;
public function __construct(
UserGlobalStoragesService $userGlobalStorageService,
UserStoragesService $userStorageService,
GlobalStoragesService $globalStorageService
) {
$this->userGlobalStorageService = $userGlobalStorageService;
$this->userStorageService = $userStorageService;
$this->globalStorageService = $globalStorageService;
}
/**
@ -174,7 +90,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) {

View File

@ -151,6 +151,7 @@ abstract class StoragesServiceTest extends \Test\TestCase {
});
$this->backendService->method('getBackends')
->willReturn($backends);
$this->overwriteService(BackendService::class, $this->backendService);
\OCP\Util::connectHook(
Filesystem::CLASSNAME,
@ -168,12 +169,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 {

View File

@ -29,6 +29,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;
@ -111,10 +112,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);
}
}

View File

@ -33,6 +33,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;
@ -266,7 +268,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();
@ -299,10 +301,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;
}
}
@ -314,19 +318,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;
}