Skip to content

Commit

Permalink
Refactor OC\Server::getShareManager
Browse files Browse the repository at this point in the history
  • Loading branch information
summersab committed Aug 29, 2023
1 parent 613cd16 commit 386ab36
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
6 changes: 4 additions & 2 deletions lib/private/Share20/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
*/
namespace OC\Share20;

use OCP\Share\IManager as IShareManager;

class Hooks {
public static function post_deleteUser($arguments) {
\OC::$server->getShareManager()->userDeleted($arguments['uid']);
\OC::$server->get(IShareManager::class)->userDeleted($arguments['uid']);
}

public static function post_deleteGroup($arguments) {
\OC::$server->getShareManager()->groupDeleted($arguments['gid']);
\OC::$server->get(IShareManager::class)->groupDeleted($arguments['gid']);
}
}
3 changes: 2 additions & 1 deletion lib/private/Template/JSConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use OCP\IURLGenerator;
use OCP\ILogger;
use OCP\IUser;
use OCP\Share\IManager as IShareManager;
use OCP\User\Backend\IPasswordConfirmationBackend;
use OCP\Util;

Expand Down Expand Up @@ -260,7 +261,7 @@ public function getConfig(): string {
'resharingAllowed' => Share::isResharingAllowed(),
'remoteShareAllowed' => $outgoingServer2serverShareEnabled,
'federatedCloudShareDoc' => $this->urlGenerator->linkToDocs('user-sharing-federated'),
'allowGroupSharing' => \OC::$server->getShareManager()->allowGroupSharing(),
'allowGroupSharing' => \OC::$server->get(IShareManager::class)->allowGroupSharing(),
'defaultInternalExpireDateEnabled' => $defaultInternalExpireDateEnabled,
'defaultInternalExpireDate' => $defaultInternalExpireDate,
'defaultInternalExpireDateEnforced' => $defaultInternalExpireDateEnforced,
Expand Down
5 changes: 3 additions & 2 deletions lib/public/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

use OC\AppScriptDependency;
use OC\AppScriptSort;
use OCP\Share\IManager as IShareManager;
use bantu\IniGetWrapper\IniGetWrapper;
use Psr\Container\ContainerExceptionInterface;

Expand Down Expand Up @@ -127,11 +128,11 @@ public static function writeLog($app, $message, $level) {
*
* @return boolean
* @since 7.0.0
* @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser
* @deprecated 9.1.0 Use \OC::$server->get(\OCP\Share\IManager::class)->sharingDisabledForUser
*/
public static function isSharingDisabledForUser() {
if (self::$shareManager === null) {
self::$shareManager = \OC::$server->getShareManager();
self::$shareManager = \OC::$server->get(IShareManager::class);
}

$user = \OC::$server->getUserSession()->getUser();
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use OCP\IDBConnection;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use OCP\Util;
use Test\HookHelper;
Expand Down Expand Up @@ -296,7 +297,7 @@ public function sharingDisabledPermissionProvider() {
*/
public function testRemoveSharePermissionWhenSharingDisabledForUser($excludeGroups, $excludeGroupsList, $expectedShareable) {
// Reset sharing disabled for users cache
self::invokePrivate(\OC::$server->getShareManager(), 'sharingDisabledForUsersCache', [new CappedMemoryCache()]);
self::invokePrivate(\OC::$server->get(IShareManager::class), 'sharingDisabledForUsersCache', [new CappedMemoryCache()]);

$config = \OC::$server->getConfig();
$oldExcludeGroupsFlag = $config->getAppValue('core', 'shareapi_exclude_groups', 'no');
Expand All @@ -321,7 +322,7 @@ public function testRemoveSharePermissionWhenSharingDisabledForUser($excludeGrou
$config->setAppValue('core', 'shareapi_exclude_groups_list', $oldExcludeGroupsList);

// Reset sharing disabled for users cache
self::invokePrivate(\OC::$server->getShareManager(), 'sharingDisabledForUsersCache', [new CappedMemoryCache()]);
self::invokePrivate(\OC::$server->get(IShareManager::class), 'sharingDisabledForUsersCache', [new CappedMemoryCache()]);
}

public function testCacheIncompleteFolder() {
Expand Down Expand Up @@ -1683,7 +1684,7 @@ public function testMoveMountPointIntoSharedFolder() {

$userFolder = \OC::$server->getUserFolder($this->user);
$shareDir = $userFolder->get('shareddir');
$shareManager = \OC::$server->getShareManager();
$shareManager = \OC::$server->get(IShareManager::class);
$share = $shareManager->newShare();
$share->setSharedWith('test2')
->setSharedBy($this->user)
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/Share20/DefaultShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\Mail\IMailer;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;

Expand Down Expand Up @@ -2540,7 +2541,7 @@ public function testGetSharesInFolder() {
$file1 = $folder1->newFile('bar');
$folder2 = $folder1->newFolder('baz');

$shareManager = \OC::$server->getShareManager();
$shareManager = \OC::$server->get(IShareManager::class);
$share1 = $shareManager->newShare();
$share1->setNode($folder1)
->setSharedBy($u1->getUID())
Expand Down Expand Up @@ -2644,7 +2645,7 @@ public function testGetAccessListNoCurrentAccessRequired() {
$this->assertCount(0, $result['users']);
$this->assertFalse($result['public']);

$shareManager = \OC::$server->getShareManager();
$shareManager = \OC::$server->get(IShareManager::class);
$share1 = $shareManager->newShare();
$share1->setNode($folder1)
->setSharedBy($u1->getUID())
Expand Down Expand Up @@ -2740,7 +2741,7 @@ public function testGetAccessListCurrentAccessRequired() {
$this->assertCount(0, $result['users']);
$this->assertFalse($result['public']);

$shareManager = \OC::$server->getShareManager();
$shareManager = \OC::$server->get(IShareManager::class);
$share1 = $shareManager->newShare();
$share1->setNode($folder1)
->setSharedBy($u1->getUID())
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/Share20/LegacyHooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use OCP\Share\Events\ShareCreatedEvent;
use OCP\Share\Events\ShareDeletedEvent;
use OCP\Share\Events\ShareDeletedFromSelfEvent;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;
use Test\TestCase;
Expand All @@ -56,7 +57,7 @@ protected function setUp(): void {
$logger = $this->createMock(LoggerInterface::class);
$this->eventDispatcher = new \OC\EventDispatcher\EventDispatcher($symfonyDispatcher, \OC::$server->get(IServerContainer::class), $logger);
$this->hooks = new LegacyHooks($this->eventDispatcher);
$this->manager = \OC::$server->getShareManager();
$this->manager = \OC::$server->get(IShareManager::class);
}

public function testPreUnshare() {
Expand Down

0 comments on commit 386ab36

Please sign in to comment.