Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apps/files_sharing/tests/CapabilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
use OCP\IConfig;
use OCP\IDateTimeZone;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
Expand Down Expand Up @@ -86,7 +85,6 @@ private function getResults(array $map) {
$this->createMock(IHasher::class),
$this->createMock(IMountManager::class),
$this->createMock(IGroupManager::class),
$this->createMock(IL10N::class),
$this->createMock(IFactory::class),
$this->createMock(IProviderFactory::class),
$this->createMock(IUserManager::class),
Expand Down
32 changes: 5 additions & 27 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@
use OC\Session\CryptoWrapper;
use OC\SetupCheck\SetupCheckManager;
use OC\Share20\ProviderFactory;
use OC\Share20\ShareDisableChecker;
use OC\Share20\ShareHelper;
use OC\SpeechToText\SpeechToTextManager;
use OC\SystemTag\ManagerFactory as SystemTagManagerFactory;
Expand Down Expand Up @@ -261,6 +260,7 @@
use OCP\Security\RateLimiting\ILimiter;
use OCP\Security\VerificationToken\IVerificationToken;
use OCP\SetupCheck\ISetupCheckManager;
use OCP\Share\IProviderFactory;
use OCP\Share\IShareHelper;
use OCP\SpeechToText\ISpeechToTextManager;
use OCP\SystemTag\ISystemTagManager;
Expand Down Expand Up @@ -1247,36 +1247,14 @@ public function __construct($webRoot, \OC\Config $config) {
/** @deprecated 19.0.0 */
$this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);

$this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
$this->registerService(IProviderFactory::class, function (ContainerInterface $c) {
$config = $c->get(\OCP\IConfig::class);
$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
/** @var \OCP\Share\IProviderFactory $factory */
$factory = new $factoryClass($this);

$manager = new \OC\Share20\Manager(
$c->get(LoggerInterface::class),
$c->get(\OCP\IConfig::class),
$c->get(ISecureRandom::class),
$c->get(IHasher::class),
$c->get(IMountManager::class),
$c->get(IGroupManager::class),
$c->getL10N('lib'),
$c->get(IFactory::class),
$factory,
$c->get(IUserManager::class),
$c->get(IRootFolder::class),
$c->get(IMailer::class),
$c->get(IURLGenerator::class),
$c->get('ThemingDefaults'),
$c->get(IEventDispatcher::class),
$c->get(IUserSession::class),
$c->get(KnownUserService::class),
$c->get(ShareDisableChecker::class),
$c->get(IDateTimeZone::class),
);

return $manager;
return new $factoryClass($this);
});

$this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class);
/** @deprecated 19.0.0 */
$this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);

Expand Down
3 changes: 1 addition & 2 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public function __construct(
IHasher $hasher,
IMountManager $mountManager,
IGroupManager $groupManager,
IL10N $l,
IFactory $l10nFactory,
IProviderFactory $factory,
IUserManager $userManager,
Expand All @@ -150,7 +149,7 @@ public function __construct(
$this->hasher = $hasher;
$this->mountManager = $mountManager;
$this->groupManager = $groupManager;
$this->l = $l;
$this->l = $l10nFactory->get('lib');
$this->l10nFactory = $l10nFactory;
$this->factory = $factory;
$this->userManager = $userManager;
Expand Down
195 changes: 19 additions & 176 deletions tests/lib/Share20/ManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,27 @@ protected function setUp(): void {
->willReturnCallback(function ($singular, $plural, $count, $parameters = []) {
return vsprintf(str_replace('%n', $count, ($count === 1) ? $singular : $plural), $parameters);
});
$this->l10nFactory->method('get')->willReturn($this->l);

$this->factory = new DummyFactory(\OC::$server);

$this->manager = new Manager(
$this->manager = $this->createManager($this->factory);

$this->defaultProvider = $this->createMock(DefaultShareProvider::class);
$this->defaultProvider->method('identifier')->willReturn('default');
$this->factory->setProvider($this->defaultProvider);
}

private function createManager(IProviderFactory $factory): Manager {
return new Manager(
$this->logger,
$this->config,
$this->secureRandom,
$this->hasher,
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$this->factory,
$factory,
$this->userManager,
$this->rootFolder,
$this->mailer,
Expand All @@ -175,10 +183,6 @@ protected function setUp(): void {
$this->shareDisabledChecker,
$this->dateTimeZone,
);

$this->defaultProvider = $this->createMock(DefaultShareProvider::class);
$this->defaultProvider->method('identifier')->willReturn('default');
$this->factory->setProvider($this->defaultProvider);
}

/**
Expand All @@ -193,7 +197,6 @@ private function createManagerMock() {
$this->hasher,
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$this->factory,
$this->userManager,
Expand Down Expand Up @@ -2796,27 +2799,7 @@ public function testGetShareByToken() {

$factory = $this->createMock(IProviderFactory::class);

$manager = new Manager(
$this->logger,
$this->config,
$this->secureRandom,
$this->hasher,
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
$this->mailer,
$this->urlGenerator,
$this->defaults,
$this->dispatcher,
$this->userSession,
$this->knownUserService,
$this->shareDisabledChecker,
$this->dateTimeZone,
);
$manager = $this->createManager($factory);

$share = $this->createMock(IShare::class);

Expand Down Expand Up @@ -2845,27 +2828,7 @@ public function testGetShareByTokenRoom() {

$factory = $this->createMock(IProviderFactory::class);

$manager = new Manager(
$this->logger,
$this->config,
$this->secureRandom,
$this->hasher,
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
$this->mailer,
$this->urlGenerator,
$this->defaults,
$this->dispatcher,
$this->userSession,
$this->knownUserService,
$this->shareDisabledChecker,
$this->dateTimeZone,
);
$manager = $this->createManager($factory);

$share = $this->createMock(IShare::class);

Expand Down Expand Up @@ -2901,27 +2864,7 @@ public function testGetShareByTokenWithException() {

$factory = $this->createMock(IProviderFactory::class);

$manager = new Manager(
$this->logger,
$this->config,
$this->secureRandom,
$this->hasher,
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
$this->mailer,
$this->urlGenerator,
$this->defaults,
$this->dispatcher,
$this->userSession,
$this->knownUserService,
$this->shareDisabledChecker,
$this->dateTimeZone,
);
$manager = $this->createManager($factory);

$share = $this->createMock(IShare::class);

Expand Down Expand Up @@ -4302,27 +4245,7 @@ public function testShareProviderExists($shareType, $expected) {
throw new Exception\ProviderException();
});

$manager = new Manager(
$this->logger,
$this->config,
$this->secureRandom,
$this->hasher,
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
$this->mailer,
$this->urlGenerator,
$this->defaults,
$this->dispatcher,
$this->userSession,
$this->knownUserService,
$this->shareDisabledChecker,
$this->dateTimeZone,
);
$manager = $this->createManager($factory);
$this->assertSame($expected,
$manager->shareProviderExists($shareType)
);
Expand All @@ -4338,27 +4261,7 @@ public function dataTestShareProviderExists() {
public function testGetSharesInFolder() {
$factory = new DummyFactory2($this->createMock(IServerContainer::class));

$manager = new Manager(
$this->logger,
$this->config,
$this->secureRandom,
$this->hasher,
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
$this->mailer,
$this->urlGenerator,
$this->defaults,
$this->dispatcher,
$this->userSession,
$this->knownUserService,
$this->shareDisabledChecker,
$this->dateTimeZone,
);
$manager = $this->createManager($factory);

$factory->setProvider($this->defaultProvider);
$extraProvider = $this->createMock(IShareProvider::class);
Expand Down Expand Up @@ -4405,27 +4308,7 @@ public function testGetSharesInFolder() {
public function testGetAccessList() {
$factory = new DummyFactory2($this->createMock(IServerContainer::class));

$manager = new Manager(
$this->logger,
$this->config,
$this->secureRandom,
$this->hasher,
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
$this->mailer,
$this->urlGenerator,
$this->defaults,
$this->dispatcher,
$this->userSession,
$this->knownUserService,
$this->shareDisabledChecker,
$this->dateTimeZone,
);
$manager = $this->createManager($factory);

$factory->setProvider($this->defaultProvider);
$extraProvider = $this->createMock(IShareProvider::class);
Expand Down Expand Up @@ -4524,27 +4407,7 @@ public function testGetAccessList() {
public function testGetAccessListWithCurrentAccess() {
$factory = new DummyFactory2($this->createMock(IServerContainer::class));

$manager = new Manager(
$this->logger,
$this->config,
$this->secureRandom,
$this->hasher,
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
$this->mailer,
$this->urlGenerator,
$this->defaults,
$this->dispatcher,
$this->userSession,
$this->knownUserService,
$this->shareDisabledChecker,
$this->dateTimeZone,
);
$manager = $this->createManager($factory);

$factory->setProvider($this->defaultProvider);
$extraProvider = $this->createMock(IShareProvider::class);
Expand Down Expand Up @@ -4652,27 +4515,7 @@ public function testGetAccessListWithCurrentAccess() {
public function testGetAllShares() {
$factory = new DummyFactory2($this->createMock(IServerContainer::class));

$manager = new Manager(
$this->logger,
$this->config,
$this->secureRandom,
$this->hasher,
$this->mountManager,
$this->groupManager,
$this->l,
$this->l10nFactory,
$factory,
$this->userManager,
$this->rootFolder,
$this->mailer,
$this->urlGenerator,
$this->defaults,
$this->dispatcher,
$this->userSession,
$this->knownUserService,
$this->shareDisabledChecker,
$this->dateTimeZone,
);
$manager = $this->createManager($factory);

$factory->setProvider($this->defaultProvider);
$extraProvider = $this->createMock(IShareProvider::class);
Expand Down