From 0fe01de26cbf8c5078f2986fc8f0bfb254128890 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Mon, 26 Jan 2026 17:12:02 +0100 Subject: [PATCH 1/2] feat(OCP): Expose setup manager to OCP It's used by a lot of apps so expose just the two methods that are most of the time used, to prevent the apps to relly on private APIs. Signed-off-by: Carl Schwan --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/private/Files/SetupManager.php | 18 +++++------ lib/private/Server.php | 1 + lib/public/Files/ISetupManager.php | 33 +++++++++++++++++++++ 5 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 lib/public/Files/ISetupManager.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 247a140223db6..9ecd43e8c70fd 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -477,6 +477,7 @@ 'OCP\\Files\\IMimeTypeDetector' => $baseDir . '/lib/public/Files/IMimeTypeDetector.php', 'OCP\\Files\\IMimeTypeLoader' => $baseDir . '/lib/public/Files/IMimeTypeLoader.php', 'OCP\\Files\\IRootFolder' => $baseDir . '/lib/public/Files/IRootFolder.php', + 'OCP\\Files\\ISetupManager' => $baseDir . '/lib/public/Files/ISetupManager.php', 'OCP\\Files\\InvalidCharacterInPathException' => $baseDir . '/lib/public/Files/InvalidCharacterInPathException.php', 'OCP\\Files\\InvalidContentException' => $baseDir . '/lib/public/Files/InvalidContentException.php', 'OCP\\Files\\InvalidDirectoryException' => $baseDir . '/lib/public/Files/InvalidDirectoryException.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 9f3d6c2c3dd06..ca4e1fa53de1e 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -518,6 +518,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\Files\\IMimeTypeDetector' => __DIR__ . '/../../..' . '/lib/public/Files/IMimeTypeDetector.php', 'OCP\\Files\\IMimeTypeLoader' => __DIR__ . '/../../..' . '/lib/public/Files/IMimeTypeLoader.php', 'OCP\\Files\\IRootFolder' => __DIR__ . '/../../..' . '/lib/public/Files/IRootFolder.php', + 'OCP\\Files\\ISetupManager' => __DIR__ . '/../../..' . '/lib/public/Files/ISetupManager.php', 'OCP\\Files\\InvalidCharacterInPathException' => __DIR__ . '/../../..' . '/lib/public/Files/InvalidCharacterInPathException.php', 'OCP\\Files\\InvalidContentException' => __DIR__ . '/../../..' . '/lib/public/Files/InvalidContentException.php', 'OCP\\Files\\InvalidDirectoryException' => __DIR__ . '/../../..' . '/lib/public/Files/InvalidDirectoryException.php', diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php index 393a6a7de0fc6..a39a1d11b1bb2 100644 --- a/lib/private/Files/SetupManager.php +++ b/lib/private/Files/SetupManager.php @@ -1,11 +1,12 @@ setupBuiltinWrappersDone) { return; } @@ -256,9 +257,7 @@ private function updateNonAuthoritativeProviders(IUser $user): void { $updatingProviders = false; } - /** - * Setup the full filesystem for the specified user - */ + #[Override] public function setupForUser(IUser $user): void { if ($this->isSetupComplete($user)) { return; @@ -711,7 +710,8 @@ public function setupForProvider(string $path, array $providers): void { $this->eventLogger->end('fs:setup:user:providers'); } - public function tearDown() { + #[Override] + public function tearDown(): void { $this->setupUsers = []; $this->setupUsersComplete = []; $this->setupUserMountProviders = []; diff --git a/lib/private/Server.php b/lib/private/Server.php index 04db3eea842f5..a14ff622647ab 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -287,6 +287,7 @@ public function __construct($webRoot, \OC\Config $config) { $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); $this->registerAlias(\OCP\ContextChat\IContentManager::class, \OC\ContextChat\ContentManager::class); + $this->registerAlias(\OCP\Files\ISetupManager::class, \OC\Files\SetupManager::class); $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class); $this->registerAlias(ITemplateManager::class, TemplateManager::class); diff --git a/lib/public/Files/ISetupManager.php b/lib/public/Files/ISetupManager.php new file mode 100644 index 0000000000000..6567fea30cbc1 --- /dev/null +++ b/lib/public/Files/ISetupManager.php @@ -0,0 +1,33 @@ + Date: Mon, 26 Jan 2026 22:09:40 +0100 Subject: [PATCH 2/2] refactor(setup-manager): Use ISetupManager instead of SetupManager Keep using the OC API in the mount manager and OC_Utils, but the rest is now using the public API. Signed-off-by: Carl Schwan --- .../lib/Command/CleanOrphanedKeys.php | 4 +-- .../lib/Command/DropLegacyFileKey.php | 4 +-- .../lib/Command/FixEncryptedVersion.php | 4 +-- .../encryption/lib/Command/FixKeyLocation.php | 4 +-- .../lib/Command/ScanLegacyFormat.php | 4 +-- apps/encryption/lib/Crypto/EncryptAll.php | 4 +-- .../lib/Listeners/UserEventsListener.php | 8 ++---- .../tests/Command/FixEncryptedVersionTest.php | 4 +-- .../tests/Crypto/EncryptAllTest.php | 6 ++--- .../Listeners/UserEventsListenersTest.php | 15 +++-------- .../lib/OCM/CloudFederationProviderFiles.php | 4 +-- .../lib/BackgroundJob/SanitizeFilenames.php | 5 ++-- apps/files_sharing/lib/External/Manager.php | 4 +-- .../lib/ShareTargetValidator.php | 4 +-- apps/files_sharing/tests/CacheTest.php | 14 +++++------ .../tests/External/ManagerTest.php | 6 ++--- .../lib/BackgroundJob/ExpireTrash.php | 4 +-- .../tests/BackgroundJob/ExpireTrashTest.php | 6 ++--- core/Command/Background/JobWorker.php | 4 +-- core/Command/User/Info.php | 6 ++--- core/Service/CronService.php | 4 +-- .../Encryption/EncryptionEventListener.php | 23 ++++++++++------- lib/private/Files/SetupManager.php | 10 +++----- lib/public/Files/ISetupManager.php | 25 +++++++++++++++++-- 24 files changed, 93 insertions(+), 83 deletions(-) diff --git a/apps/encryption/lib/Command/CleanOrphanedKeys.php b/apps/encryption/lib/Command/CleanOrphanedKeys.php index 74196c202429d..64910b5be1377 100644 --- a/apps/encryption/lib/Command/CleanOrphanedKeys.php +++ b/apps/encryption/lib/Command/CleanOrphanedKeys.php @@ -9,11 +9,11 @@ namespace OCA\Encryption\Command; use OC\Encryption\Util; -use OC\Files\SetupManager; use OCA\Encryption\Crypto\Encryption; use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\ISetupManager; use OCP\Files\NotFoundException; use OCP\IConfig; use OCP\IUser; @@ -34,7 +34,7 @@ public function __construct( protected QuestionHelper $questionHelper, private IUserManager $userManager, private Util $encryptionUtil, - private SetupManager $setupManager, + private ISetupManager $setupManager, private IRootFolder $rootFolder, private LoggerInterface $logger, ) { diff --git a/apps/encryption/lib/Command/DropLegacyFileKey.php b/apps/encryption/lib/Command/DropLegacyFileKey.php index 96f9485100a11..704ab52b6c157 100644 --- a/apps/encryption/lib/Command/DropLegacyFileKey.php +++ b/apps/encryption/lib/Command/DropLegacyFileKey.php @@ -11,10 +11,10 @@ use OC\Encryption\Exceptions\DecryptionFailedException; use OC\Files\FileInfo; -use OC\Files\SetupManager; use OC\Files\View; use OCA\Encryption\KeyManager; use OCP\Encryption\Exceptions\GenericEncryptionException; +use OCP\Files\ISetupManager; use OCP\IUser; use OCP\IUserManager; use Symfony\Component\Console\Command\Command; @@ -27,7 +27,7 @@ class DropLegacyFileKey extends Command { public function __construct( private readonly IUserManager $userManager, private readonly KeyManager $keyManager, - private readonly SetupManager $setupManager, + private readonly ISetupManager $setupManager, ) { parent::__construct(); diff --git a/apps/encryption/lib/Command/FixEncryptedVersion.php b/apps/encryption/lib/Command/FixEncryptedVersion.php index fd5f670a9c281..f33311028c0c2 100644 --- a/apps/encryption/lib/Command/FixEncryptedVersion.php +++ b/apps/encryption/lib/Command/FixEncryptedVersion.php @@ -8,12 +8,12 @@ namespace OCA\Encryption\Command; -use OC\Files\SetupManager; use OC\Files\Storage\Wrapper\Encryption; use OC\Files\View; use OC\ServerNotAvailableException; use OCA\Encryption\Util; use OCP\Encryption\Exceptions\InvalidHeaderException; +use OCP\Files\ISetupManager; use OCP\HintException; use OCP\IConfig; use OCP\IUser; @@ -34,7 +34,7 @@ public function __construct( private readonly IUserManager $userManager, private readonly Util $util, private readonly View $view, - private readonly SetupManager $setupManager, + private readonly ISetupManager $setupManager, ) { parent::__construct(); } diff --git a/apps/encryption/lib/Command/FixKeyLocation.php b/apps/encryption/lib/Command/FixKeyLocation.php index 1ad48f5b5e87c..805d7f4e0b85f 100644 --- a/apps/encryption/lib/Command/FixKeyLocation.php +++ b/apps/encryption/lib/Command/FixKeyLocation.php @@ -10,7 +10,6 @@ use OC\Encryption\Manager; use OC\Encryption\Util; -use OC\Files\SetupManager; use OC\Files\Storage\Wrapper\Encryption; use OC\Files\View; use OCP\Encryption\IManager; @@ -19,6 +18,7 @@ use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\ISetupManager; use OCP\Files\Node; use OCP\IUser; use OCP\IUserManager; @@ -38,7 +38,7 @@ public function __construct( private readonly IUserMountCache $userMountCache, private readonly Util $encryptionUtil, private readonly IRootFolder $rootFolder, - private readonly SetupManager $setupManager, + private readonly ISetupManager $setupManager, IManager $encryptionManager, ) { $this->keyRootDirectory = rtrim($this->encryptionUtil->getKeyStorageRoot(), '/'); diff --git a/apps/encryption/lib/Command/ScanLegacyFormat.php b/apps/encryption/lib/Command/ScanLegacyFormat.php index 56601354d0a95..0a1946ecc8925 100644 --- a/apps/encryption/lib/Command/ScanLegacyFormat.php +++ b/apps/encryption/lib/Command/ScanLegacyFormat.php @@ -8,9 +8,9 @@ */ namespace OCA\Encryption\Command; -use OC\Files\SetupManager; use OC\Files\View; use OCA\Encryption\Util; +use OCP\Files\ISetupManager; use OCP\IConfig; use OCP\IUser; use OCP\IUserManager; @@ -27,7 +27,7 @@ public function __construct( protected readonly IConfig $config, protected readonly QuestionHelper $questionHelper, private readonly IUserManager $userManager, - private readonly SetupManager $setupManager, + private readonly ISetupManager $setupManager, ) { parent::__construct(); diff --git a/apps/encryption/lib/Crypto/EncryptAll.php b/apps/encryption/lib/Crypto/EncryptAll.php index 5600526eac09c..e44c7fd8b5627 100644 --- a/apps/encryption/lib/Crypto/EncryptAll.php +++ b/apps/encryption/lib/Crypto/EncryptAll.php @@ -11,12 +11,12 @@ namespace OCA\Encryption\Crypto; use OC\Encryption\Exceptions\DecryptionFailedException; -use OC\Files\SetupManager; use OC\Files\View; use OCA\Encryption\KeyManager; use OCA\Encryption\Users\Setup; use OCA\Encryption\Util; use OCP\Files\FileInfo; +use OCP\Files\ISetupManager; use OCP\IConfig; use OCP\IL10N; use OCP\IUser; @@ -53,7 +53,7 @@ public function __construct( protected readonly QuestionHelper $questionHelper, protected readonly ISecureRandom $secureRandom, protected readonly LoggerInterface $logger, - protected readonly SetupManager $setupManager, + protected readonly ISetupManager $setupManager, ) { } diff --git a/apps/encryption/lib/Listeners/UserEventsListener.php b/apps/encryption/lib/Listeners/UserEventsListener.php index 16879fe648bfc..76fe31e63b6b7 100644 --- a/apps/encryption/lib/Listeners/UserEventsListener.php +++ b/apps/encryption/lib/Listeners/UserEventsListener.php @@ -10,7 +10,6 @@ use OC\Core\Events\BeforePasswordResetEvent; use OC\Core\Events\PasswordResetEvent; -use OC\Files\SetupManager; use OCA\Encryption\KeyManager; use OCA\Encryption\Services\PassphraseService; use OCA\Encryption\Session; @@ -18,9 +17,8 @@ use OCA\Encryption\Util; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +use OCP\Files\ISetupManager; use OCP\IUser; -use OCP\IUserManager; -use OCP\IUserSession; use OCP\Lockdown\ILockdownManager; use OCP\User\Events\BeforePasswordUpdatedEvent; use OCP\User\Events\PasswordUpdatedEvent; @@ -40,9 +38,7 @@ public function __construct( private Setup $userSetup, private Session $session, private KeyManager $keyManager, - private IUserManager $userManager, - private IUserSession $userSession, - private SetupManager $setupManager, + private ISetupManager $setupManager, private PassphraseService $passphraseService, private ILockdownManager $lockdownManager, ) { diff --git a/apps/encryption/tests/Command/FixEncryptedVersionTest.php b/apps/encryption/tests/Command/FixEncryptedVersionTest.php index d2d9feed6ffca..8a37aae28067e 100644 --- a/apps/encryption/tests/Command/FixEncryptedVersionTest.php +++ b/apps/encryption/tests/Command/FixEncryptedVersionTest.php @@ -10,11 +10,11 @@ namespace OCA\Encryption\Tests\Command; -use OC\Files\SetupManager; use OC\Files\View; use OCA\Encryption\Command\FixEncryptedVersion; use OCA\Encryption\Util; use OCP\Encryption\IManager; +use OCP\Files\ISetupManager; use OCP\IAppConfig; use OCP\IConfig; use OCP\ITempManager; @@ -69,7 +69,7 @@ public function setUp(): void { Server::get(IUserManager::class), $this->util, new View('/'), - Server::get(SetupManager::class), + Server::get(ISetupManager::class), ); $this->commandTester = new CommandTester($this->fixEncryptedVersion); diff --git a/apps/encryption/tests/Crypto/EncryptAllTest.php b/apps/encryption/tests/Crypto/EncryptAllTest.php index 3e324f7cb7643..d3dcffae67753 100644 --- a/apps/encryption/tests/Crypto/EncryptAllTest.php +++ b/apps/encryption/tests/Crypto/EncryptAllTest.php @@ -9,13 +9,13 @@ */ namespace OCA\Encryption\Tests\Crypto; -use OC\Files\SetupManager; use OC\Files\View; use OCA\Encryption\Crypto\EncryptAll; use OCA\Encryption\KeyManager; use OCA\Encryption\Users\Setup; use OCA\Encryption\Util; use OCP\Files\FileInfo; +use OCP\Files\ISetupManager; use OCP\IConfig; use OCP\IL10N; use OCP\IUser; @@ -50,7 +50,7 @@ class EncryptAllTest extends TestCase { protected UserInterface&MockObject $userInterface; protected ISecureRandom&MockObject $secureRandom; protected LoggerInterface&MockObject $logger; - protected SetupManager&MockObject $setupManager; + protected ISetupManager&MockObject $setupManager; protected IUser&MockObject $user1; protected IUser&MockObject $user2; @@ -84,7 +84,7 @@ protected function setUp(): void { $this->userInterface = $this->getMockBuilder(UserInterface::class) ->disableOriginalConstructor()->getMock(); $this->logger = $this->createMock(LoggerInterface::class); - $this->setupManager = $this->createMock(SetupManager::class); + $this->setupManager = $this->createMock(ISetupManager::class); /** * We need format method to return a string diff --git a/apps/encryption/tests/Listeners/UserEventsListenersTest.php b/apps/encryption/tests/Listeners/UserEventsListenersTest.php index 83a57af184aa5..08a7f40035b6f 100644 --- a/apps/encryption/tests/Listeners/UserEventsListenersTest.php +++ b/apps/encryption/tests/Listeners/UserEventsListenersTest.php @@ -10,16 +10,14 @@ use OC\Core\Events\BeforePasswordResetEvent; use OC\Core\Events\PasswordResetEvent; -use OC\Files\SetupManager; use OCA\Encryption\KeyManager; use OCA\Encryption\Listeners\UserEventsListener; use OCA\Encryption\Services\PassphraseService; use OCA\Encryption\Session; use OCA\Encryption\Users\Setup; use OCA\Encryption\Util; +use OCP\Files\ISetupManager; use OCP\IUser; -use OCP\IUserManager; -use OCP\IUserSession; use OCP\Lockdown\ILockdownManager; use OCP\User\Events\BeforePasswordUpdatedEvent; use OCP\User\Events\PasswordUpdatedEvent; @@ -32,14 +30,11 @@ #[\PHPUnit\Framework\Attributes\Group(name: 'DB')] class UserEventsListenersTest extends TestCase { - protected Util&MockObject $util; protected Setup&MockObject $userSetup; protected Session&MockObject $session; protected KeyManager&MockObject $keyManager; - protected IUserManager&MockObject $userManager; - protected IUserSession&MockObject $userSession; - protected SetupManager&MockObject $setupManager; + protected ISetupManager&MockObject $setupManager; protected ILockdownManager&MockObject $lockdownManager; protected PassphraseService&MockObject $passphraseService; @@ -52,9 +47,7 @@ public function setUp(): void { $this->userSetup = $this->createMock(Setup::class); $this->session = $this->createMock(Session::class); $this->keyManager = $this->createMock(KeyManager::class); - $this->userManager = $this->createMock(IUserManager::class); - $this->userSession = $this->createMock(IUserSession::class); - $this->setupManager = $this->createMock(SetupManager::class); + $this->setupManager = $this->createMock(ISetupManager::class); $this->lockdownManager = $this->createMock(ILockdownManager::class); $this->passphraseService = $this->createMock(PassphraseService::class); @@ -63,8 +56,6 @@ public function setUp(): void { $this->userSetup, $this->session, $this->keyManager, - $this->userManager, - $this->userSession, $this->setupManager, $this->passphraseService, $this->lockdownManager, diff --git a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php index 30da7befa8fc5..a5ae8c87abd25 100644 --- a/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php +++ b/apps/federatedfilesharing/lib/OCM/CloudFederationProviderFiles.php @@ -8,7 +8,6 @@ use OC\AppFramework\Http; use OC\Files\Filesystem; -use OC\Files\SetupManager; use OCA\FederatedFileSharing\AddressHandler; use OCA\FederatedFileSharing\FederatedShareProvider; use OCA\Federation\TrustedServers; @@ -31,6 +30,7 @@ use OCP\Federation\ICloudIdManager; use OCP\Federation\ISignedCloudFederationProvider; use OCP\Files\IFilenameValidator; +use OCP\Files\ISetupManager; use OCP\Files\NotFoundException; use OCP\HintException; use OCP\IConfig; @@ -68,7 +68,7 @@ public function __construct( private readonly LoggerInterface $logger, private readonly IFilenameValidator $filenameValidator, private readonly IProviderFactory $shareProviderFactory, - private readonly SetupManager $setupManager, + private readonly ISetupManager $setupManager, private readonly ExternalShareMapper $externalShareMapper, ) { } diff --git a/apps/files/lib/BackgroundJob/SanitizeFilenames.php b/apps/files/lib/BackgroundJob/SanitizeFilenames.php index 855fa4b2d0495..429fe0ab5097f 100644 --- a/apps/files/lib/BackgroundJob/SanitizeFilenames.php +++ b/apps/files/lib/BackgroundJob/SanitizeFilenames.php @@ -8,7 +8,6 @@ */ namespace OCA\Files\BackgroundJob; -use OC\Files\SetupManager; use OCA\Files\AppInfo\Application; use OCA\Files\Service\SettingsService; use OCP\AppFramework\Services\IAppConfig; @@ -16,10 +15,10 @@ use OCP\BackgroundJob\IJobList; use OCP\BackgroundJob\QueuedJob; use OCP\Config\IUserConfig; -use OCP\Files\File; use OCP\Files\Folder; use OCP\Files\IFilenameValidator; use OCP\Files\IRootFolder; +use OCP\Files\ISetupManager; use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\IUser; @@ -43,7 +42,7 @@ public function __construct( private IAppConfig $appConfig, private IUserConfig $userConfig, private IRootFolder $rootFolder, - private SetupManager $setupManager, + private ISetupManager $setupManager, private IFilenameValidator $filenameValidator, private LoggerInterface $logger, ) { diff --git a/apps/files_sharing/lib/External/Manager.php b/apps/files_sharing/lib/External/Manager.php index 1196f7c362912..44bf97512ef98 100644 --- a/apps/files_sharing/lib/External/Manager.php +++ b/apps/files_sharing/lib/External/Manager.php @@ -9,7 +9,6 @@ namespace OCA\Files_Sharing\External; use OC\Files\Filesystem; -use OC\Files\SetupManager; use OC\User\NoUserException; use OCA\FederatedFileSharing\Events\FederatedShareAddedEvent; use OCA\Files_Sharing\Helper; @@ -21,6 +20,7 @@ use OCP\Files\Events\InvalidateMountCacheEvent; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\ISetupManager; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; use OCP\Files\Storage\IStorageFactory; @@ -53,7 +53,7 @@ public function __construct( private IEventDispatcher $eventDispatcher, private LoggerInterface $logger, private IRootFolder $rootFolder, - private SetupManager $setupManager, + private ISetupManager $setupManager, private ICertificateManager $certificateManager, private ExternalShareMapper $externalShareMapper, ) { diff --git a/apps/files_sharing/lib/ShareTargetValidator.php b/apps/files_sharing/lib/ShareTargetValidator.php index f063f77f96dce..b47dde1138112 100644 --- a/apps/files_sharing/lib/ShareTargetValidator.php +++ b/apps/files_sharing/lib/ShareTargetValidator.php @@ -9,11 +9,11 @@ namespace OCA\Files_Sharing; use OC\Files\Filesystem; -use OC\Files\SetupManager; use OC\Files\View; use OCP\Cache\CappedMemoryCache; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Config\ICachedMountInfo; +use OCP\Files\ISetupManager; use OCP\Files\Mount\IMountManager; use OCP\Files\Mount\IMountPoint; use OCP\IUser; @@ -30,7 +30,7 @@ class ShareTargetValidator { public function __construct( private readonly IManager $shareManager, private readonly IEventDispatcher $eventDispatcher, - private readonly SetupManager $setupManager, + private readonly ISetupManager $setupManager, private readonly IMountManager $mountManager, ) { $this->folderExistsCache = new CappedMemoryCache(); diff --git a/apps/files_sharing/tests/CacheTest.php b/apps/files_sharing/tests/CacheTest.php index 0f0f5b21ddbad..777f3b1d0c65a 100644 --- a/apps/files_sharing/tests/CacheTest.php +++ b/apps/files_sharing/tests/CacheTest.php @@ -9,7 +9,6 @@ use OC\Files\Cache\Cache; use OC\Files\Filesystem; -use OC\Files\SetupManager; use OC\Files\Storage\Storage; use OC\Files\Storage\Temporary; use OC\Files\Storage\Wrapper\Jail; @@ -18,6 +17,7 @@ use OCP\Constants; use OCP\Files\Cache\IWatcher; use OCP\Files\IRootFolder; +use OCP\Files\ISetupManager; use OCP\Files\Node; use OCP\IUserManager; use OCP\Server; @@ -412,7 +412,7 @@ public function testGetPathByIdDirectShare(): void { $share = $this->shareManager->createShare($share); $share->setStatus(IShare::STATUS_ACCEPTED); $this->shareManager->updateShare($share); - Server::get(SetupManager::class)->tearDown(); + Server::get(ISetupManager::class)->tearDown(); self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertTrue(Filesystem::file_exists('/test.txt')); @@ -443,7 +443,7 @@ public function testGetPathByIdShareSubFolder(): void { $share = $this->shareManager->createShare($share); $share->setStatus(IShare::STATUS_ACCEPTED); $this->shareManager->updateShare($share); - Server::get(SetupManager::class)->tearDown(); + Server::get(ISetupManager::class)->tearDown(); self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertTrue(Filesystem::file_exists('/foo')); @@ -471,7 +471,7 @@ public function testNumericStorageId(): void { $share = $this->shareManager->createShare($share); $share->setStatus(IShare::STATUS_ACCEPTED); $this->shareManager->updateShare($share); - Server::get(SetupManager::class)->tearDown(); + Server::get(ISetupManager::class)->tearDown(); [$sourceStorage] = Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo'); @@ -508,7 +508,7 @@ public function testShareJailedStorage(): void { $share = $this->shareManager->createShare($share); $share->setStatus(IShare::STATUS_ACCEPTED); $this->shareManager->updateShare($share); - Server::get(SetupManager::class)->tearDown(); + Server::get(ISetupManager::class)->tearDown(); self::loginHelper(self::TEST_FILES_SHARING_API_USER2); $this->assertEquals('foo', Filesystem::file_get_contents('/sub/foo.txt')); @@ -547,7 +547,7 @@ public function testSearchShareJailedStorage(): void { $share = $this->shareManager->createShare($share); $share->setStatus(IShare::STATUS_ACCEPTED); $this->shareManager->updateShare($share); - Server::get(SetupManager::class)->tearDown(); + Server::get(ISetupManager::class)->tearDown(); self::loginHelper(self::TEST_FILES_SHARING_API_USER2); @@ -582,7 +582,7 @@ public function testWatcherRootChange(): void { $share = $this->shareManager->createShare($share); $share->setStatus(IShare::STATUS_ACCEPTED); $this->shareManager->updateShare($share); - Server::get(SetupManager::class)->tearDown(); + Server::get(ISetupManager::class)->tearDown(); self::loginHelper(self::TEST_FILES_SHARING_API_USER2); diff --git a/apps/files_sharing/tests/External/ManagerTest.php b/apps/files_sharing/tests/External/ManagerTest.php index e9e89de25fe81..67e3884907c8b 100644 --- a/apps/files_sharing/tests/External/ManagerTest.php +++ b/apps/files_sharing/tests/External/ManagerTest.php @@ -9,7 +9,6 @@ use OC\Federation\CloudIdManager; use OC\Files\Mount\MountPoint; -use OC\Files\SetupManager; use OC\Files\SetupManagerFactory; use OC\Files\Storage\StorageFactory; use OC\Files\Storage\Temporary; @@ -24,6 +23,7 @@ use OCP\Federation\ICloudFederationProviderManager; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\ISetupManager; use OCP\Files\NotFoundException; use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; @@ -68,7 +68,7 @@ class ManagerTest extends TestCase { protected ICloudFederationFactory&MockObject $cloudFederationFactory; protected IGroupManager&MockObject $groupManager; protected IUserManager&MockObject $userManager; - protected SetupManager&MockObject $setupManager; + protected ISetupManager&MockObject $setupManager; protected ICertificateManager&MockObject $certificateManager; private ExternalShareMapper $externalShareMapper; @@ -84,7 +84,7 @@ protected function setUp(): void { $this->groupManager = $this->createMock(IGroupManager::class); $this->userManager = $this->createMock(IUserManager::class); $this->eventDispatcher = $this->createMock(IEventDispatcher::class); - $this->setupManager = $this->createMock(SetupManager::class); + $this->setupManager = $this->createMock(ISetupManager::class); $this->rootFolder = $this->createMock(IRootFolder::class); $this->rootFolder->method('getUserFolder') ->willReturnCallback(function (string $userId): Folder { diff --git a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php index 3c558208792a3..4d890f977b95e 100644 --- a/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php +++ b/apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php @@ -7,13 +7,13 @@ */ namespace OCA\Files_Trashbin\BackgroundJob; -use OC\Files\SetupManager; use OC\Files\View; use OCA\Files_Trashbin\AppInfo\Application; use OCA\Files_Trashbin\Expiration; use OCA\Files_Trashbin\Trashbin; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\TimedJob; +use OCP\Files\ISetupManager; use OCP\IAppConfig; use OCP\IUser; use OCP\IUserManager; @@ -32,7 +32,7 @@ public function __construct( private IUserManager $userManager, private Expiration $expiration, private LoggerInterface $logger, - private SetupManager $setupManager, + private ISetupManager $setupManager, private ILockingProvider $lockingProvider, ITimeFactory $time, ) { diff --git a/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php b/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php index f43ce79259e6a..ec5e716289576 100644 --- a/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php +++ b/apps/files_trashbin/tests/BackgroundJob/ExpireTrashTest.php @@ -9,12 +9,12 @@ namespace OCA\Files_Trashbin\Tests\BackgroundJob; -use OC\Files\SetupManager; use OCA\Files_Trashbin\AppInfo\Application; use OCA\Files_Trashbin\BackgroundJob\ExpireTrash; use OCA\Files_Trashbin\Expiration; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; +use OCP\Files\ISetupManager; use OCP\IAppConfig; use OCP\IUserManager; use OCP\Lock\ILockingProvider; @@ -29,7 +29,7 @@ class ExpireTrashTest extends TestCase { private IJobList&MockObject $jobList; private LoggerInterface&MockObject $logger; private ITimeFactory&MockObject $time; - private SetupManager&MockObject $setupManager; + private ISetupManager&MockObject $setupManager; private ILockingProvider&MockObject $lockingProvider; protected function setUp(): void { @@ -40,7 +40,7 @@ protected function setUp(): void { $this->expiration = $this->createMock(Expiration::class); $this->jobList = $this->createMock(IJobList::class); $this->logger = $this->createMock(LoggerInterface::class); - $this->setupManager = $this->createMock(SetupManager::class); + $this->setupManager = $this->createMock(ISetupManager::class); $this->lockingProvider = $this->createMock(ILockingProvider::class); $this->time = $this->createMock(ITimeFactory::class); diff --git a/core/Command/Background/JobWorker.php b/core/Command/Background/JobWorker.php index 723b7d32db22e..4ce7fba1517ed 100644 --- a/core/Command/Background/JobWorker.php +++ b/core/Command/Background/JobWorker.php @@ -9,8 +9,8 @@ namespace OC\Core\Command\Background; use OC\Core\Command\InterruptedException; -use OC\Files\SetupManager; use OCP\BackgroundJob\IJobList; +use OCP\Files\ISetupManager; use OCP\ITempManager; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Input\InputArgument; @@ -24,7 +24,7 @@ public function __construct( protected IJobList $jobList, protected LoggerInterface $logger, private ITempManager $tempManager, - private SetupManager $setupManager, + private ISetupManager $setupManager, ) { parent::__construct($jobList, $logger); } diff --git a/core/Command/User/Info.php b/core/Command/User/Info.php index f8339f96056fc..4be0caefae355 100644 --- a/core/Command/User/Info.php +++ b/core/Command/User/Info.php @@ -7,7 +7,7 @@ namespace OC\Core\Command\User; use OC\Core\Command\Base; -use OC\Files\SetupManager; +use OCP\Files\ISetupManager; use OCP\Files\NotFoundException; use OCP\IGroupManager; use OCP\IUser; @@ -22,12 +22,12 @@ class Info extends Base { public function __construct( protected IUserManager $userManager, protected IGroupManager $groupManager, - protected SetupManager $setupManager, + protected ISetupManager $setupManager, ) { parent::__construct(); } - protected function configure() { + protected function configure(): void { $this ->setName('user:info') ->setDescription('show user info') diff --git a/core/Service/CronService.php b/core/Service/CronService.php index d5b4034a3387c..18039926b1075 100644 --- a/core/Service/CronService.php +++ b/core/Service/CronService.php @@ -13,13 +13,13 @@ use OC; use OC\Authentication\LoginCredentials\Store; -use OC\Files\SetupManager; use OC\Security\CSRF\TokenStorage\SessionStorage; use OC\Session\CryptoWrapper; use OC\Session\Memory; use OC\User\Session; use OCP\App\IAppManager; use OCP\BackgroundJob\IJobList; +use OCP\Files\ISetupManager; use OCP\IAppConfig; use OCP\IConfig; use OCP\ILogger; @@ -44,7 +44,7 @@ public function __construct( private readonly ITempManager $tempManager, private readonly IAppConfig $appConfig, private readonly IJobList $jobList, - private readonly SetupManager $setupManager, + private readonly ISetupManager $setupManager, private readonly bool $isCLI, ) { } diff --git a/lib/private/Encryption/EncryptionEventListener.php b/lib/private/Encryption/EncryptionEventListener.php index 4560c4796df81..ddd0eaa475ce0 100644 --- a/lib/private/Encryption/EncryptionEventListener.php +++ b/lib/private/Encryption/EncryptionEventListener.php @@ -9,18 +9,22 @@ namespace OC\Encryption; -use OC\Files\SetupManager; use OC\Files\View; use OCA\Files_Trashbin\Events\NodeRestoredEvent; use OCP\Encryption\IFile; +use OCP\Encryption\IManager as IEncryptionManager; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventListener; use OCP\Files\Events\Node\NodeRenamedEvent; +use OCP\Files\ISetupManager; use OCP\Files\NotFoundException; +use OCP\IConfig; +use OCP\IGroupManager; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; +use OCP\Server; use OCP\Share\Events\ShareCreatedEvent; use OCP\Share\Events\ShareDeletedEvent; use Psr\Log\LoggerInterface; @@ -31,7 +35,7 @@ class EncryptionEventListener implements IEventListener { public function __construct( private IUserSession $userSession, - private SetupManager $setupManager, + private ISetupManager $setupManager, private Manager $encryptionManager, private IUserManager $userManager, ) { @@ -55,10 +59,10 @@ public function handle(Event $event): void { } elseif ($event instanceof ShareDeletedEvent) { try { // In case the unsharing happens in a background job, we don't have - // a session and we load instead the user from the UserManager + // a session, and we load instead the user from the UserManager $owner = $this->userManager->get($event->getShare()->getShareOwner()); $this->getUpdate($owner)->postUnshared($event->getShare()->getNode()); - } catch (NotFoundException $e) { + } catch (NotFoundException) { /* The node was deleted already, nothing to update */ } } elseif ($event instanceof NodeRestoredEvent) { @@ -81,11 +85,12 @@ private function getUpdate(?IUser $owner = null): Update { new Util( new View(), $this->userManager, - \OC::$server->getGroupManager(), - \OC::$server->getConfig()), - \OC::$server->getEncryptionManager(), - \OC::$server->get(IFile::class), - \OC::$server->get(LoggerInterface::class), + Server::get(IGroupManager::class), + Server::get(IConfig::class) + ), + Server::get(IEncryptionManager::class), + Server::get(IFile::class), + Server::get(LoggerInterface::class), ); } diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php index a39a1d11b1bb2..4850dd55faa45 100644 --- a/lib/private/Files/SetupManager.php +++ b/lib/private/Files/SetupManager.php @@ -1,12 +1,12 @@ getUID(), $this->setupUsers, true); } + #[Override] public function isSetupComplete(IUser $user): bool { return in_array($user->getUID(), $this->setupUsersComplete, true); } @@ -451,10 +452,7 @@ private function getUserForPath(string $path) { return $this->userManager->get($userId); } - /** - * Set up the filesystem for the specified path, optionally including all - * children mounts. - */ + #[Override] public function setupForPath(string $path, bool $includeChildren = false): void { $user = $this->getUserForPath($path); if (!$user) { diff --git a/lib/public/Files/ISetupManager.php b/lib/public/Files/ISetupManager.php index 6567fea30cbc1..b1b14ccf8cf29 100644 --- a/lib/public/Files/ISetupManager.php +++ b/lib/public/Files/ISetupManager.php @@ -1,12 +1,12 @@