Skip to content

Commit 0f356fa

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

7 files changed

Lines changed: 31 additions & 12 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,13 +7,15 @@
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\GlobalScale\IConfig as GlobalScaleConfig;
1617
use OCP\Http\Client\IClientService;
18+
use OCP\IAppConfig;
1719
use OCP\IConfig;
1820
use OCP\IUserSession;
1921
use OCP\Share\IShare;
@@ -24,6 +26,7 @@ class LookupPlugin implements ISearchPlugin {
2426
private string $currentUserRemote;
2527

2628
public function __construct(
29+
private readonly IAppConfig $appConfig,
2730
private readonly IConfig $config,
2831
private readonly IClientService $clientService,
2932
IUserSession $userSession,
@@ -77,7 +80,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
7780
]);
7881
continue;
7982
}
80-
if ($this->currentUserRemote === $remote) {
83+
if ($this->currentUserRemote === $remote && !$this->appConfig->getValueBool('core', ConfigLexicon::LOOKUP_LOCAL_ACCOUNT_SEARCH)) {
8184
continue;
8285
}
8386
$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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ public function __construct(
10381038
$this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class);
10391039

10401040
$this->registerService(ISearch::class, function (Server $c): ISearch {
1041-
$instance = new Search($c);
1041+
$instance = new Search($c, $c->get(IAppConfig::class));
10421042

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

tests/lib/Collaboration/Collaborators/LookupPluginTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use OCP\Http\Client\IClient;
2020
use OCP\Http\Client\IClientService;
2121
use OCP\Http\Client\IResponse;
22+
use OCP\IAppConfig;
2223
use OCP\IConfig;
2324
use OCP\IUser;
2425
use OCP\IUserSession;
@@ -29,6 +30,7 @@
2930

3031
class LookupPluginTest extends TestCase {
3132
protected IConfig&MockObject $config;
33+
protected IAppConfig&MockObject $appConfig;
3234
protected GlobalScaleConfig&MockObject $globalScaleConfig;
3335
protected IClientService&MockObject $clientService;
3436
protected IUserSession&MockObject $userSession;
@@ -44,6 +46,7 @@ protected function setUp(): void {
4446
$this->cloudIdManager = $this->createMock(ICloudIdManager::class);
4547
$this->config = $this->createMock(IConfig::class);
4648
$this->globalScaleConfig = $this->createMock(GlobalScaleConfig::class);
49+
$this->appConfig = $this->createMock(IAppConfig::class);
4750
$this->logger = $this->createMock(LoggerInterface::class);
4851
$this->clientService = $this->createMock(IClientService::class);
4952
$cloudId = $this->createMock(ICloudId::class);
@@ -66,6 +69,7 @@ protected function setUp(): void {
6669

6770
$this->plugin = new LookupPlugin(
6871
$this->config,
72+
$this->appConfig,
6973
$this->clientService,
7074
$this->userSession,
7175
$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)