Skip to content

Commit 3249da4

Browse files
committed
feat(lookup): search for local account only via lookupserver
1 parent af98eed commit 3249da4

5 files changed

Lines changed: 18 additions & 2 deletions

File tree

core/AppInfo/ConfigLexicon.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class ConfigLexicon implements ILexicon {
2929
public const USER_LANGUAGE = 'lang';
3030
public const OCM_DISCOVERY_ENABLED = 'ocm_discovery_enabled';
3131
public const OCM_INVITE_ACCEPT_DIALOG = 'ocm_invite_accept_dialog';
32+
public const LOOKUP_LOCAL_ACCOUNT_SEARCH = 'lus_local_account_search';
3233

3334
public const USER_LOCALE = 'locale';
3435
public const USER_TIMEZONE = 'timezone';
@@ -93,6 +94,7 @@ public function getAppConfigs(): array {
9394
new Entry(self::LASTCRON_TIMESTAMP, ValueType::INT, 0, 'timestamp of last cron execution'),
9495
new Entry(self::OCM_DISCOVERY_ENABLED, ValueType::BOOL, true, 'enable/disable OCM'),
9596
new Entry(self::OCM_INVITE_ACCEPT_DIALOG, ValueType::STRING, '', 'route to local invite accept dialog', note: 'set as empty string to disable feature'),
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
@@ -6,12 +6,14 @@
66
*/
77
namespace OC\Collaboration\Collaborators;
88

9+
use OC\Core\AppInfo\ConfigLexicon;
910
use OCA\Federation\TrustedServers;
1011
use OCP\Collaboration\Collaborators\ISearchPlugin;
1112
use OCP\Collaboration\Collaborators\ISearchResult;
1213
use OCP\Collaboration\Collaborators\SearchResultType;
1314
use OCP\Federation\ICloudIdManager;
1415
use OCP\Http\Client\IClientService;
16+
use OCP\IAppConfig;
1517
use OCP\IConfig;
1618
use OCP\IUserSession;
1719
use OCP\Share\IShare;
@@ -23,6 +25,7 @@ class LookupPlugin implements ISearchPlugin {
2325

2426
public function __construct(
2527
private IConfig $config,
28+
private readonly IAppConfig $appConfig,
2629
private IClientService $clientService,
2730
IUserSession $userSession,
2831
private ICloudIdManager $cloudIdManager,
@@ -73,7 +76,7 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
7376
]);
7477
continue;
7578
}
76-
if ($this->currentUserRemote === $remote) {
79+
if ($this->currentUserRemote === $remote && !$this->appConfig->getValueBool('core', ConfigLexicon::LOOKUP_LOCAL_ACCOUNT_SEARCH)) {
7780
continue;
7881
}
7982
$name = $lookup['name']['value'] ?? '';

lib/private/Collaboration/Collaborators/Search.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
*/
77
namespace OC\Collaboration\Collaborators;
88

9+
use OC\Core\AppInfo\ConfigLexicon;
910
use OCP\AppFramework\QueryException;
1011
use OCP\Collaboration\Collaborators\ISearch;
1112
use OCP\Collaboration\Collaborators\ISearchPlugin;
1213
use OCP\Collaboration\Collaborators\ISearchResult;
1314
use OCP\Collaboration\Collaborators\SearchResultType;
15+
use OCP\IAppConfig;
1416
use OCP\IContainer;
1517
use OCP\Share\IShare;
1618

@@ -19,6 +21,7 @@ class Search implements ISearch {
1921

2022
public function __construct(
2123
private IContainer $container,
24+
private readonly IAppConfig $appConfig,
2225
) {
2326
}
2427

@@ -45,6 +48,9 @@ public function search($search, array $shareTypes, $lookup, $limit, $offset): ar
4548
foreach ($this->pluginList[$type] as $plugin) {
4649
/** @var ISearchPlugin $searchPlugin */
4750
$searchPlugin = $this->container->resolve($plugin);
51+
if ($searchPlugin instanceof UserPlugin && $lookup && $this->appConfig->getValueBool('core', ConfigLexicon::LOOKUP_LOCAL_ACCOUNT_SEARCH)) {
52+
continue;
53+
}
4854
$hasMoreResults = $searchPlugin->search($search, $limit, $offset, $searchResult) || $hasMoreResults;
4955
}
5056
}

lib/private/Server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1139,7 +1139,7 @@ public function __construct(
11391139
$this->registerAlias(\OCP\Share\IManager::class, \OC\Share20\Manager::class);
11401140

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

11441144
// register default plugins
11451145
$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 */
@@ -44,6 +47,7 @@ protected function setUp(): void {
4447
$this->userSession = $this->createMock(IUserSession::class);
4548
$this->cloudIdManager = $this->createMock(ICloudIdManager::class);
4649
$this->config = $this->createMock(IConfig::class);
50+
$this->appConfig = $this->createMock(IAppConfig::class);
4751
$this->logger = $this->createMock(LoggerInterface::class);
4852
$this->clientService = $this->createMock(IClientService::class);
4953
$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,

0 commit comments

Comments
 (0)