Skip to content

Commit 51ec51e

Browse files
committed
feat(lookup): search for local account only via lookupserver
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 182e403 commit 51ec51e

7 files changed

Lines changed: 33 additions & 13 deletions

File tree

core/AppInfo/ConfigLexicon.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ConfigLexicon implements ILexicon {
2828
public const SHARE_LINK_EXPIRE_DATE_ENFORCED = 'shareapi_enforce_expire_date';
2929
public const USER_LANGUAGE = 'lang';
3030
public const OCM_DISCOVERY_ENABLED = 'ocm_discovery_enabled';
31+
public const LOOKUP_LOCAL_ACCOUNT_SEARCH = 'lus_local_account_search';
3132

3233
public const USER_LOCALE = 'locale';
3334
public const USER_TIMEZONE = 'timezone';
@@ -93,6 +94,7 @@ public function getAppConfigs(): array {
9394
),
9495
new Entry(self::LASTCRON_TIMESTAMP, ValueType::INT, 0, 'timestamp of last cron execution'),
9596
new Entry(self::OCM_DISCOVERY_ENABLED, ValueType::BOOL, true, 'enable/disable OCM'),
97+
new Entry(self::LOOKUP_LOCAL_ACCOUNT_SEARCH, ValueType::BOOL, false, 'use lookup result only when searching for local account'),
9698
new Entry(self::UNIFIED_SEARCH_MIN_SEARCH_LENGTH, ValueType::INT, 1, 'Minimum search length to trigger the request', rename: 'unified-search.min-search-length'),
9799
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'),
98100
new Entry(

lib/private/Collaboration/Collaborators/LookupPlugin.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
namespace OC\Collaboration\Collaborators;
99

10+
use OC\Core\AppInfo\ConfigLexicon;
1011
use OCA\Federation\TrustedServers;
1112
use OCP\Collaboration\Collaborators\ISearchPlugin;
1213
use OCP\Collaboration\Collaborators\ISearchResult;
1314
use OCP\Collaboration\Collaborators\SearchResultType;
1415
use OCP\Federation\ICloudIdManager;
1516
use OCP\Http\Client\IClientService;
17+
use OCP\IAppConfig;
1618
use OCP\IConfig;
1719
use OCP\IUserSession;
1820
use OCP\Share\IShare;
@@ -24,6 +26,7 @@ class LookupPlugin implements ISearchPlugin {
2426

2527
public function __construct(
2628
private IConfig $config,
29+
private readonly IAppConfig $appConfig,
2730
private IClientService $clientService,
2831
IUserSession $userSession,
2932
private ICloudIdManager $cloudIdManager,
@@ -75,7 +78,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
7578
]);
7679
continue;
7780
}
78-
if ($this->currentUserRemote === $remote) {
81+
if ($this->currentUserRemote === $remote && !$this->appConfig->getValueBool('core', ConfigLexicon::LOOKUP_LOCAL_ACCOUNT_SEARCH)) {
7982
continue;
8083
}
8184
$name = $lookup['name']['value'] ?? '';

lib/private/Collaboration/Collaborators/Search.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
namespace OC\Collaboration\Collaborators;
99

10+
use OC\Core\AppInfo\ConfigLexicon;
1011
use OCP\AppFramework\QueryException;
1112
use OCP\Collaboration\Collaborators\ISearch;
1213
use OCP\Collaboration\Collaborators\ISearchPlugin;
1314
use OCP\Collaboration\Collaborators\ISearchResult;
1415
use OCP\Collaboration\Collaborators\SearchResultType;
16+
use OCP\IAppConfig;
1517
use OCP\IContainer;
1618
use OCP\Share\IShare;
1719

@@ -20,6 +22,7 @@ class Search implements ISearch {
2022

2123
public function __construct(
2224
private IContainer $container,
25+
private readonly IAppConfig $appConfig,
2326
) {
2427
}
2528

@@ -47,6 +50,9 @@ public function search($search, array $shareTypes, $lookup, $limit, $offset): ar
4750
foreach ($this->pluginList[$type] as $plugin) {
4851
/** @var ISearchPlugin $searchPlugin */
4952
$searchPlugin = $this->container->resolve($plugin);
53+
if ($searchPlugin instanceof UserPlugin && $lookup && $this->appConfig->getValueBool('core', ConfigLexicon::LOOKUP_LOCAL_ACCOUNT_SEARCH)) {
54+
continue;
55+
}
5056
$hasMoreResults = $searchPlugin->search($search, $limit, $offset, $searchResult) || $hasMoreResults;
5157
}
5258
}

lib/private/Server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,8 @@ public function __construct(
10351035

10361036
$this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class);
10371037

1038-
$this->registerService(ISearch::class, function (Server $c): ISearch {
1039-
$instance = new Search($c);
1038+
$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c): \OCP\Collaboration\Collaborators\ISearch {
1039+
$instance = new \OC\Collaboration\Collaborators\Search($c, $c->get(IAppConfig::class));
10401040

10411041
// register default plugins
10421042
$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);

tests/lib/Collaboration/Collaborators/LookupPluginTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use OCP\Http\Client\IClient;
1717
use OCP\Http\Client\IClientService;
1818
use OCP\Http\Client\IResponse;
19+
use OCP\IAppConfig;
1920
use OCP\IConfig;
2021
use OCP\IUser;
2122
use OCP\IUserSession;
@@ -27,6 +28,8 @@
2728
class LookupPluginTest extends TestCase {
2829
/** @var IConfig|MockObject */
2930
protected $config;
31+
/** @var IAppConfig|MockObject */
32+
protected $appConfig;
3033
/** @var IClientService|MockObject */
3134
protected $clientService;
3235
/** @var IUserSession|MockObject */
@@ -45,6 +48,7 @@ protected function setUp(): void {
4548
$this->userSession = $this->createMock(IUserSession::class);
4649
$this->cloudIdManager = $this->createMock(ICloudIdManager::class);
4750
$this->config = $this->createMock(IConfig::class);
51+
$this->appConfig = $this->createMock(IAppConfig::class);
4852
$this->logger = $this->createMock(LoggerInterface::class);
4953
$this->clientService = $this->createMock(IClientService::class);
5054
$cloudId = $this->createMock(ICloudId::class);
@@ -67,6 +71,7 @@ protected function setUp(): void {
6771

6872
$this->plugin = new LookupPlugin(
6973
$this->config,
74+
$this->appConfig,
7075
$this->clientService,
7176
$this->userSession,
7277
$this->cloudIdManager,

tests/lib/Collaboration/Collaborators/SearchResultTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,24 @@
1111
use OC\Collaboration\Collaborators\SearchResult;
1212
use OCP\Collaboration\Collaborators\ISearch;
1313
use OCP\Collaboration\Collaborators\SearchResultType;
14+
use OCP\IAppConfig;
1415
use OCP\IContainer;
16+
use PHPUnit\Framework\MockObject\MockObject;
1517
use Test\TestCase;
1618

1719
class SearchResultTest extends TestCase {
18-
/** @var IContainer|\PHPUnit\Framework\MockObject\MockObject */
19-
protected $container;
20-
/** @var ISearch */
21-
protected $search;
20+
protected IContainer&MockObject $container;
21+
protected IAppConfig&MockObject $appConfig;
22+
protected ISearch $search;
2223

2324
#[\Override]
2425
protected function setUp(): void {
2526
parent::setUp();
2627

2728
$this->container = $this->createMock(IContainer::class);
29+
$this->appConfig = $this->createMock(IAppConfig::class);
2830

29-
$this->search = new Search($this->container);
31+
$this->search = new Search($this->container, $this->appConfig);
3032
}
3133

3234
public static function dataAddResultSet(): array {

tests/lib/Collaboration/Collaborators/SearchTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,25 @@
1212
use OCP\Collaboration\Collaborators\ISearch;
1313
use OCP\Collaboration\Collaborators\ISearchPlugin;
1414
use OCP\Collaboration\Collaborators\SearchResultType;
15+
use OCP\IAppConfig;
1516
use OCP\IContainer;
1617
use OCP\Share\IShare;
18+
use PHPUnit\Framework\MockObject\MockObject;
1719
use Test\TestCase;
1820

1921
class SearchTest extends TestCase {
20-
/** @var IContainer|\PHPUnit\Framework\MockObject\MockObject */
21-
protected $container;
22-
/** @var ISearch */
23-
protected $search;
22+
protected IContainer&MockObject $container;
23+
protected IAppConfig&MockObject $appConfig;
24+
protected ISearch $search;
2425

2526
#[\Override]
2627
protected function setUp(): void {
2728
parent::setUp();
2829

2930
$this->container = $this->createMock(IContainer::class);
31+
$this->appConfig = $this->createMock(IAppConfig::class);
3032

31-
$this->search = new Search($this->container);
33+
$this->search = new Search($this->container, $this->appConfig);
3234
}
3335

3436
#[\PHPUnit\Framework\Attributes\DataProvider('dataSearchSharees')]

0 commit comments

Comments
 (0)