diff options
Diffstat (limited to 'apps/files_external/lib/Service/UserGlobalStoragesService.php')
-rw-r--r-- | apps/files_external/lib/Service/UserGlobalStoragesService.php | 59 |
1 files changed, 23 insertions, 36 deletions
diff --git a/apps/files_external/lib/Service/UserGlobalStoragesService.php b/apps/files_external/lib/Service/UserGlobalStoragesService.php index 355401bb84f..aaa59c85d62 100644 --- a/apps/files_external/lib/Service/UserGlobalStoragesService.php +++ b/apps/files_external/lib/Service/UserGlobalStoragesService.php @@ -1,61 +1,44 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * - * @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/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ - namespace OCA\Files_External\Service; +use OCA\Files_External\Lib\StorageConfig; +use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\IUserMountCache; -use \OCP\IUserSession; -use \OCP\IGroupManager; -use \OCA\Files_External\Lib\StorageConfig; +use OCP\IGroupManager; +use OCP\IUser; +use OCP\IUserSession; /** * Service class to read global storages applicable to the user * Read-only access available, attempting to write will throw DomainException */ class UserGlobalStoragesService extends GlobalStoragesService { - use UserTrait; - /** @var IGroupManager */ - protected $groupManager; - /** * @param BackendService $backendService * @param DBConfigService $dbConfig * @param IUserSession $userSession * @param IGroupManager $groupManager * @param IUserMountCache $userMountCache + * @param IEventDispatcher $eventDispatcher */ public function __construct( BackendService $backendService, DBConfigService $dbConfig, IUserSession $userSession, - IGroupManager $groupManager, - IUserMountCache $userMountCache + protected IGroupManager $groupManager, + IUserMountCache $userMountCache, + IEventDispatcher $eventDispatcher, ) { - parent::__construct($backendService, $dbConfig, $userMountCache); + parent::__construct($backendService, $dbConfig, $userMountCache, $eventDispatcher); $this->userSession = $userSession; - $this->groupManager = $groupManager; } /** @@ -75,7 +58,7 @@ class UserGlobalStoragesService extends GlobalStoragesService { $userMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); $globalMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null); $groups = $this->groupManager->getUserGroupIds($this->getUser()); - if (is_array($groups) && count($groups) !== 0) { + if (count($groups) !== 0) { $groupMounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, $groups); } else { $groupMounts = []; @@ -177,14 +160,18 @@ class UserGlobalStoragesService extends GlobalStoragesService { /** * Gets all storages for the user, admin, personal, global, etc * + * @param IUser|null $user user to get the storages for, if not set the currently logged in user will be used * @return StorageConfig[] array of storage configs */ - public function getAllStoragesForUser() { - if (is_null($this->getUser())) { + public function getAllStoragesForUser(?IUser $user = null) { + if (is_null($user)) { + $user = $this->getUser(); + } + if (is_null($user)) { return []; } - $groupIds = $this->groupManager->getUserGroupIds($this->getUser()); - $mounts = $this->dbConfig->getMountsForUser($this->getUser()->getUID(), $groupIds); + $groupIds = $this->groupManager->getUserGroupIds($user); + $mounts = $this->dbConfig->getMountsForUser($user->getUID(), $groupIds); $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); $configs = array_filter($configs, function ($config) { return $config instanceof StorageConfig; |