refactor(share): Remove some deprecated method usages

Signed-off-by: Carl Schwan <carlschwan@kde.org>
pull/58593/head
Carl Schwan 3 months ago
parent af94028bdb
commit 7fa44717e0
No known key found for this signature in database
GPG Key ID: 02325448204E452A
  1. 11
      apps/files_sharing/lib/External/Storage.php
  2. 10
      apps/files_sharing/lib/SharedStorage.php
  3. 5
      build/psalm-baseline.xml
  4. 4
      lib/private/Files/SetupManager.php
  5. 3
      lib/private/Files/SetupManagerFactory.php
  6. 11
      lib/private/Files/View.php
  7. 20
      lib/public/Util.php
  8. 2
      tests/lib/Files/SetupManagerTest.php

@ -30,13 +30,15 @@ use OCP\Files\StorageInvalidException;
use OCP\Files\StorageNotAvailableException;
use OCP\Http\Client\IClientService;
use OCP\Http\Client\LocalServerException;
use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IUserSession;
use OCP\OCM\Exceptions\OCMArgumentException;
use OCP\OCM\Exceptions\OCMProviderException;
use OCP\OCM\IOCMDiscoveryService;
use OCP\Server;
use OCP\Util;
use OCP\Share\IManager as IShareManager;
use Psr\Log\LoggerInterface;
class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, IReliableEtagStorage {
@ -48,6 +50,8 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage,
private bool $updateChecked = false;
private ExternalShareManager $manager;
private IConfig $config;
private IAppConfig $appConfig;
private IShareManager $shareManager;
/**
* @param array{HttpClientService: IClientService, manager: ExternalShareManager, cloudId: ICloudId, mountpoint: string, token: string, password: ?string}|array $options
@ -60,6 +64,8 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage,
$this->logger = Server::get(LoggerInterface::class);
$discoveryService = Server::get(IOCMDiscoveryService::class);
$this->config = Server::get(IConfig::class);
$this->appConfig = Server::get(IAppConfig::class);
$this->shareManager = Server::get(IShareManager::class);
// use default path to webdav if not found on discovery
try {
@ -330,7 +336,8 @@ class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage,
}
public function isSharable(string $path): bool {
if (Util::isSharingDisabledForUser() || $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') !== 'yes') {
if ($this->shareManager->sharingDisabledForUser(Server::get(IUserSession::class)->getUser()?->getUID())
|| !$this->appConfig->getValueBool('core', 'shareapi_allow_resharing', true)) {
return false;
}
return (bool)($this->getPermissions($path) & Constants::PERMISSION_SHARE);

@ -37,8 +37,10 @@ use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\ISharedStorage;
use OCP\Files\Storage\IStorage;
use OCP\IAppConfig;
use OCP\IUserSession;
use OCP\Lock\ILockingProvider;
use OCP\Server;
use OCP\Share\IManager as IShareManager;
use OCP\Share\IShare;
use OCP\Util;
use Override;
@ -83,12 +85,16 @@ class SharedStorage extends Jail implements LegacyISharedStorage, ISharedStorage
private $ownerUserFolder = null;
private string $sourcePath = '';
private IAppConfig $appConfig;
private IShareManager $shareManager;
private static int $initDepth = 0;
public function __construct(array $parameters) {
$this->ownerView = $parameters['ownerView'];
$this->logger = Server::get(LoggerInterface::class);
$this->appConfig = Server::get(IAppConfig::class);
$this->shareManager = Server::get(IShareManager::class);
$this->superShare = $parameters['superShare'];
$this->groupedShares = $parameters['groupedShares'];
@ -280,8 +286,8 @@ class SharedStorage extends Jail implements LegacyISharedStorage, ISharedStorage
}
public function isSharable(string $path): bool {
$appConfig = \OCP\Server::get(IAppConfig::class);
if (Util::isSharingDisabledForUser() || !$appConfig->getValueBool('core', 'shareapi_allow_resharing', true)) {
if ($this->shareManager->sharingDisabledForUser(Server::get(IUserSession::class)->getUser()?->getUID())
|| !$this->appConfig->getValueBool('core', 'shareapi_allow_resharing', true)) {
return false;
}
return (bool)($this->getPermissions($path) & Constants::PERMISSION_SHARE);

@ -1527,10 +1527,6 @@
<DeprecatedInterface>
<code><![CDATA[Storage]]></code>
</DeprecatedInterface>
<DeprecatedMethod>
<code><![CDATA[Util::isSharingDisabledForUser()]]></code>
<code><![CDATA[getAppValue]]></code>
</DeprecatedMethod>
</file>
<file src="apps/files_sharing/lib/Helper.php">
<DeprecatedMethod>
@ -1624,7 +1620,6 @@
<code><![CDATA[Util::emitHook('\OC\Files\Storage\Shared', 'file_get_contents', $info)]]></code>
<code><![CDATA[Util::emitHook('\OC\Files\Storage\Shared', 'file_put_contents', $info)]]></code>
<code><![CDATA[Util::emitHook('\OC\Files\Storage\Shared', 'fopen', $info)]]></code>
<code><![CDATA[Util::isSharingDisabledForUser()]]></code>
</DeprecatedMethod>
<FalsableReturnStatement>
<code><![CDATA[$this->sourceRootInfo]]></code>

@ -50,6 +50,7 @@ use OCP\Files\Storage\IStorage;
use OCP\Group\Events\UserAddedEvent;
use OCP\Group\Events\UserRemovedEvent;
use OCP\HintException;
use OCP\IAppConfig;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
@ -109,6 +110,7 @@ class SetupManager implements ISetupManager {
private ShareDisableChecker $shareDisableChecker,
private IAppManager $appManager,
private FileAccess $fileAccess,
private IAppConfig $appConfig,
) {
$this->cache = $cacheFactory->createDistributed('setupmanager::');
$this->listeningForProviders = false;
@ -166,7 +168,7 @@ class SetupManager implements ISetupManager {
return $storage;
});
$reSharingEnabled = $this->config->getAppValue('core', 'shareapi_allow_resharing', 'yes') === 'yes';
$reSharingEnabled = $this->appConfig->getValueBool('core', 'shareapi_allow_resharing', true);
$user = $this->userSession->getUser();
$sharingEnabledForUser = $user ? !$this->shareDisableChecker->sharingDisabledForUser($user->getUID()) : true;
Filesystem::addStorageWrapper(

@ -16,6 +16,7 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Config\IUserMountCache;
use OCP\Files\Mount\IMountManager;
use OCP\IAppConfig;
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IUserManager;
@ -40,6 +41,7 @@ class SetupManagerFactory {
private ShareDisableChecker $shareDisableChecker,
private IAppManager $appManager,
private FileAccess $fileAccess,
private IAppConfig $appConfig,
) {
$this->setupManager = null;
}
@ -61,6 +63,7 @@ class SetupManagerFactory {
$this->shareDisableChecker,
$this->appManager,
$this->fileAccess,
$this->appConfig,
);
}
return $this->setupManager;

@ -44,6 +44,7 @@ use OCP\Files\UnseekableException;
use OCP\ITempManager;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
@ -1508,7 +1509,7 @@ class View {
}
$cache = $storage->getCache($internalPath);
$user = \OC_User::getUser();
$user = Server::get(IUserSession::class)->getUser();
if (!$directoryInfo) {
$data = $this->getCacheEntry($storage, $internalPath, $directory);
@ -1526,7 +1527,8 @@ class View {
$folderId = $data->getId();
$contents = $cache->getFolderContentsById($folderId, $mimeTypeFilter);
$sharingDisabled = Util::isSharingDisabledForUser();
$shareManager = Server::get(IManager::class);
$sharingDisabled = $shareManager->sharingDisabledForUser($user?->getUID());
$permissionsMask = ~Constants::PERMISSION_SHARE;
$files = [];
@ -1642,13 +1644,14 @@ class View {
$rootEntry['permissions'] = $permissions & (Constants::PERMISSION_ALL - (Constants::PERMISSION_UPDATE | Constants::PERMISSION_DELETE));
}
$rootEntry['path'] = substr(Filesystem::normalizePath($path . '/' . $rootEntry['name']), strlen($user) + 2); // full path without /$user/
// if sharing was disabled for the user we remove the share permissions
if ($sharingDisabled) {
$rootEntry['permissions'] = $rootEntry['permissions'] & ~Constants::PERMISSION_SHARE;
}
// FIXME: $user is null in encrypt:all occ command
$rootEntry['path'] = substr(Filesystem::normalizePath($path . '/' . $rootEntry['name']), strlen($user?->getUID() ?? '') + 2); // full path without /$user/
$ownerId = $subStorage->getOwner('');
if ($ownerId !== false) {
$owner = $this->getUserObjectForOwner($ownerId);

@ -16,7 +16,6 @@ use OC\AppScriptSort;
use OC\Security\CSRF\CsrfTokenManager;
use OCP\L10N\IFactory;
use OCP\Mail\IEmailValidator;
use OCP\Share\IManager;
use Psr\Container\ContainerExceptionInterface;
/**
@ -25,8 +24,6 @@ use Psr\Container\ContainerExceptionInterface;
* @since 4.0.0
*/
class Util {
private static ?IManager $shareManager = null;
private static array $scriptsInit = [];
private static array $scripts = [];
private static array $scriptDeps = [];
@ -73,23 +70,6 @@ class Util {
return \OCP\Server::get(ServerVersion::class)->getChannel();
}
/**
* check if sharing is disabled for the current user
*
* @return boolean
* @since 7.0.0
* @deprecated 9.1.0 Use Server::get(\OCP\Share\IManager::class)->sharingDisabledForUser
*/
public static function isSharingDisabledForUser() {
if (self::$shareManager === null) {
self::$shareManager = Server::get(IManager::class);
}
$user = Server::get(\OCP\IUserSession::class)->getUser();
return self::$shareManager->sharingDisabledForUser($user?->getUID());
}
/**
* get l10n object
* @since 6.0.0 - parameter $language was added in 8.0.0

@ -23,6 +23,7 @@ use OCP\Files\Config\MountProviderArgs;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Storage\IStorageFactory;
use OCP\IAppConfig;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\IConfig;
@ -111,6 +112,7 @@ class SetupManagerTest extends TestCase {
$shareDisableChecker,
$appManager,
$this->fileAccess,
$this->createMock(IAppConfig::class),
);
}

Loading…
Cancel
Save