diff --git a/core/AppInfo/ConfigLexicon.php b/core/AppInfo/ConfigLexicon.php index 3bc2ebeba1bcf..ba4789fda66c0 100644 --- a/core/AppInfo/ConfigLexicon.php +++ b/core/AppInfo/ConfigLexicon.php @@ -28,6 +28,7 @@ class ConfigLexicon implements ILexicon { public const SHARE_LINK_EXPIRE_DATE_ENFORCED = 'shareapi_enforce_expire_date'; public const USER_LANGUAGE = 'lang'; public const OCM_DISCOVERY_ENABLED = 'ocm_discovery_enabled'; + public const LOOKUP_LOCAL_ACCOUNT_SEARCH = 'lus_local_account_search'; public const USER_LOCALE = 'locale'; public const USER_TIMEZONE = 'timezone'; @@ -93,6 +94,7 @@ public function getAppConfigs(): array { ), new Entry(self::LASTCRON_TIMESTAMP, ValueType::INT, 0, 'timestamp of last cron execution'), new Entry(self::OCM_DISCOVERY_ENABLED, ValueType::BOOL, true, 'enable/disable OCM'), + new Entry(self::LOOKUP_LOCAL_ACCOUNT_SEARCH, ValueType::BOOL, false, 'use lookup result only when searching for local account'), new Entry(self::UNIFIED_SEARCH_MIN_SEARCH_LENGTH, ValueType::INT, 1, 'Minimum search length to trigger the request', rename: 'unified-search.min-search-length'), new Entry(self::UNIFIED_SEARCH_MAX_RESULTS_PER_REQUEST, ValueType::INT, 25, 'Maximum results returned per search request', rename: 'unified-search.max-results-per-request'), new Entry( diff --git a/lib/private/Collaboration/Collaborators/LookupPlugin.php b/lib/private/Collaboration/Collaborators/LookupPlugin.php index 9c48670daaaa4..91853d3e206e5 100644 --- a/lib/private/Collaboration/Collaborators/LookupPlugin.php +++ b/lib/private/Collaboration/Collaborators/LookupPlugin.php @@ -7,12 +7,14 @@ namespace OC\Collaboration\Collaborators; +use OC\Core\AppInfo\ConfigLexicon; use OCA\Federation\TrustedServers; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; use OCP\Collaboration\Collaborators\SearchResultType; use OCP\Federation\ICloudIdManager; use OCP\Http\Client\IClientService; +use OCP\IAppConfig; use OCP\IConfig; use OCP\IUserSession; use OCP\Share\IShare; @@ -24,6 +26,7 @@ class LookupPlugin implements ISearchPlugin { public function __construct( private IConfig $config, + private readonly IAppConfig $appConfig, private IClientService $clientService, IUserSession $userSession, private ICloudIdManager $cloudIdManager, @@ -75,7 +78,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b ]); continue; } - if ($this->currentUserRemote === $remote) { + if ($this->currentUserRemote === $remote && !$this->appConfig->getValueBool('core', ConfigLexicon::LOOKUP_LOCAL_ACCOUNT_SEARCH)) { continue; } $name = $lookup['name']['value'] ?? ''; diff --git a/lib/private/Collaboration/Collaborators/Search.php b/lib/private/Collaboration/Collaborators/Search.php index fefc7722a2f7b..ce735dba5dca2 100644 --- a/lib/private/Collaboration/Collaborators/Search.php +++ b/lib/private/Collaboration/Collaborators/Search.php @@ -7,11 +7,13 @@ namespace OC\Collaboration\Collaborators; +use OC\Core\AppInfo\ConfigLexicon; use OCP\AppFramework\QueryException; use OCP\Collaboration\Collaborators\ISearch; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\ISearchResult; use OCP\Collaboration\Collaborators\SearchResultType; +use OCP\IAppConfig; use OCP\IContainer; use OCP\Share\IShare; @@ -20,6 +22,7 @@ class Search implements ISearch { public function __construct( private IContainer $container, + private readonly IAppConfig $appConfig, ) { } @@ -47,6 +50,9 @@ public function search($search, array $shareTypes, $lookup, $limit, $offset): ar foreach ($this->pluginList[$type] as $plugin) { /** @var ISearchPlugin $searchPlugin */ $searchPlugin = $this->container->resolve($plugin); + if ($searchPlugin instanceof UserPlugin && $lookup && $this->appConfig->getValueBool('core', ConfigLexicon::LOOKUP_LOCAL_ACCOUNT_SEARCH)) { + continue; + } $hasMoreResults = $searchPlugin->search($search, $limit, $offset, $searchResult) || $hasMoreResults; } } diff --git a/lib/private/Server.php b/lib/private/Server.php index a1caf17da3984..28daabe99a56c 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1035,8 +1035,8 @@ public function __construct( $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); - $this->registerService(ISearch::class, function (Server $c): ISearch { - $instance = new Search($c); + $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c): \OCP\Collaboration\Collaborators\ISearch { + $instance = new \OC\Collaboration\Collaborators\Search($c, $c->get(IAppConfig::class)); // register default plugins $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); diff --git a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php index 7f70c3ba3d734..4d49beec9303c 100644 --- a/tests/lib/Collaboration/Collaborators/LookupPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/LookupPluginTest.php @@ -16,6 +16,7 @@ use OCP\Http\Client\IClient; use OCP\Http\Client\IClientService; use OCP\Http\Client\IResponse; +use OCP\IAppConfig; use OCP\IConfig; use OCP\IUser; use OCP\IUserSession; @@ -27,6 +28,8 @@ class LookupPluginTest extends TestCase { /** @var IConfig|MockObject */ protected $config; + /** @var IAppConfig|MockObject */ + protected $appConfig; /** @var IClientService|MockObject */ protected $clientService; /** @var IUserSession|MockObject */ @@ -45,6 +48,7 @@ protected function setUp(): void { $this->userSession = $this->createMock(IUserSession::class); $this->cloudIdManager = $this->createMock(ICloudIdManager::class); $this->config = $this->createMock(IConfig::class); + $this->appConfig = $this->createMock(IAppConfig::class); $this->logger = $this->createMock(LoggerInterface::class); $this->clientService = $this->createMock(IClientService::class); $cloudId = $this->createMock(ICloudId::class); @@ -67,6 +71,7 @@ protected function setUp(): void { $this->plugin = new LookupPlugin( $this->config, + $this->appConfig, $this->clientService, $this->userSession, $this->cloudIdManager, diff --git a/tests/lib/Collaboration/Collaborators/SearchResultTest.php b/tests/lib/Collaboration/Collaborators/SearchResultTest.php index d2afc5b36897c..f9ded33178132 100644 --- a/tests/lib/Collaboration/Collaborators/SearchResultTest.php +++ b/tests/lib/Collaboration/Collaborators/SearchResultTest.php @@ -11,22 +11,24 @@ use OC\Collaboration\Collaborators\SearchResult; use OCP\Collaboration\Collaborators\ISearch; use OCP\Collaboration\Collaborators\SearchResultType; +use OCP\IAppConfig; use OCP\IContainer; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class SearchResultTest extends TestCase { - /** @var IContainer|\PHPUnit\Framework\MockObject\MockObject */ - protected $container; - /** @var ISearch */ - protected $search; + protected IContainer&MockObject $container; + protected IAppConfig&MockObject $appConfig; + protected ISearch $search; #[\Override] protected function setUp(): void { parent::setUp(); $this->container = $this->createMock(IContainer::class); + $this->appConfig = $this->createMock(IAppConfig::class); - $this->search = new Search($this->container); + $this->search = new Search($this->container, $this->appConfig); } public static function dataAddResultSet(): array { diff --git a/tests/lib/Collaboration/Collaborators/SearchTest.php b/tests/lib/Collaboration/Collaborators/SearchTest.php index 936bb03e5327d..c4a4097d48056 100644 --- a/tests/lib/Collaboration/Collaborators/SearchTest.php +++ b/tests/lib/Collaboration/Collaborators/SearchTest.php @@ -12,23 +12,25 @@ use OCP\Collaboration\Collaborators\ISearch; use OCP\Collaboration\Collaborators\ISearchPlugin; use OCP\Collaboration\Collaborators\SearchResultType; +use OCP\IAppConfig; use OCP\IContainer; use OCP\Share\IShare; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class SearchTest extends TestCase { - /** @var IContainer|\PHPUnit\Framework\MockObject\MockObject */ - protected $container; - /** @var ISearch */ - protected $search; + protected IContainer&MockObject $container; + protected IAppConfig&MockObject $appConfig; + protected ISearch $search; #[\Override] protected function setUp(): void { parent::setUp(); $this->container = $this->createMock(IContainer::class); + $this->appConfig = $this->createMock(IAppConfig::class); - $this->search = new Search($this->container); + $this->search = new Search($this->container, $this->appConfig); } #[\PHPUnit\Framework\Attributes\DataProvider('dataSearchSharees')]