From e3e6d47269a6bac0ab213612ee2a1c884c93d609 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 25 Feb 2026 11:19:53 -0100 Subject: [PATCH] feat(lookup): search for local account only via lookupserver Signed-off-by: Maxence Lange --- core/AppInfo/ConfigLexicon.php | 2 ++ .../Collaboration/Collaborators/LookupPlugin.php | 5 ++++- lib/private/Collaboration/Collaborators/Search.php | 6 ++++++ lib/private/Server.php | 2 +- .../Collaboration/Collaborators/LookupPluginTest.php | 5 +++++ .../Collaboration/Collaborators/SearchResultTest.php | 12 +++++++----- tests/lib/Collaboration/Collaborators/SearchTest.php | 12 +++++++----- 7 files changed, 32 insertions(+), 12 deletions(-) diff --git a/core/AppInfo/ConfigLexicon.php b/core/AppInfo/ConfigLexicon.php index 508a090e8a4ff..f7b55288c52ee 100644 --- a/core/AppInfo/ConfigLexicon.php +++ b/core/AppInfo/ConfigLexicon.php @@ -29,6 +29,7 @@ class ConfigLexicon implements ILexicon { public const USER_LANGUAGE = 'lang'; public const OCM_DISCOVERY_ENABLED = 'ocm_discovery_enabled'; public const OCM_INVITE_ACCEPT_DIALOG = 'ocm_invite_accept_dialog'; + 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::OCM_INVITE_ACCEPT_DIALOG, ValueType::STRING, '', 'route to local invite accept dialog', note: 'set as empty string to disable feature'), + 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 b65431fe34796..7cc1a188cfde1 100644 --- a/lib/private/Collaboration/Collaborators/LookupPlugin.php +++ b/lib/private/Collaboration/Collaborators/LookupPlugin.php @@ -6,12 +6,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; @@ -23,6 +25,7 @@ class LookupPlugin implements ISearchPlugin { public function __construct( private IConfig $config, + private readonly IAppConfig $appConfig, private IClientService $clientService, IUserSession $userSession, private ICloudIdManager $cloudIdManager, @@ -73,7 +76,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 4fbfb787996ed..8f9c6e5921b63 100644 --- a/lib/private/Collaboration/Collaborators/Search.php +++ b/lib/private/Collaboration/Collaborators/Search.php @@ -6,11 +6,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; @@ -19,6 +21,7 @@ class Search implements ISearch { public function __construct( private IContainer $container, + private readonly IAppConfig $appConfig, ) { } @@ -45,6 +48,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 f608d3ee26d28..3a258d53bd05e 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1139,7 +1139,7 @@ public function __construct( $this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class); $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c): \OCP\Collaboration\Collaborators\ISearch { - $instance = new \OC\Collaboration\Collaborators\Search($c); + $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 d7d4c87c99cfd..4573e55a821ef 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 */ @@ -44,6 +47,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 687901c47a650..f4bc02303ca57 100644 --- a/tests/lib/Collaboration/Collaborators/SearchResultTest.php +++ b/tests/lib/Collaboration/Collaborators/SearchResultTest.php @@ -11,21 +11,23 @@ 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; 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 7cff155a0c0bf..f5609a5ad6456 100644 --- a/tests/lib/Collaboration/Collaborators/SearchTest.php +++ b/tests/lib/Collaboration/Collaborators/SearchTest.php @@ -12,22 +12,24 @@ 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; 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')]