diff --git a/apps/files_sharing/lib/External/Storage.php b/apps/files_sharing/lib/External/Storage.php
index b1c5342a0f3..68c69e9e7c8 100644
--- a/apps/files_sharing/lib/External/Storage.php
+++ b/apps/files_sharing/lib/External/Storage.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);
diff --git a/apps/files_sharing/lib/SharedStorage.php b/apps/files_sharing/lib/SharedStorage.php
index f754512f26b..be8cb48487c 100644
--- a/apps/files_sharing/lib/SharedStorage.php
+++ b/apps/files_sharing/lib/SharedStorage.php
@@ -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);
diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml
index 915b5cff096..2fdb5e044fb 100644
--- a/build/psalm-baseline.xml
+++ b/build/psalm-baseline.xml
@@ -1527,10 +1527,6 @@
-
-
-
-
@@ -1624,7 +1620,6 @@
-
sourceRootInfo]]>
diff --git a/lib/private/Files/SetupManager.php b/lib/private/Files/SetupManager.php
index 79079758599..5cd32fdfe0e 100644
--- a/lib/private/Files/SetupManager.php
+++ b/lib/private/Files/SetupManager.php
@@ -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(
diff --git a/lib/private/Files/SetupManagerFactory.php b/lib/private/Files/SetupManagerFactory.php
index 369e3089017..721281685fc 100644
--- a/lib/private/Files/SetupManagerFactory.php
+++ b/lib/private/Files/SetupManagerFactory.php
@@ -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;
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 5e728d0a8d0..21265b7d048 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -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);
diff --git a/lib/public/Util.php b/lib/public/Util.php
index 70a862880f1..0610460fc22 100644
--- a/lib/public/Util.php
+++ b/lib/public/Util.php
@@ -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
diff --git a/tests/lib/Files/SetupManagerTest.php b/tests/lib/Files/SetupManagerTest.php
index f70358691cd..1e9906e51db 100644
--- a/tests/lib/Files/SetupManagerTest.php
+++ b/tests/lib/Files/SetupManagerTest.php
@@ -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),
);
}