Skip to content

Commit e3e6d47

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

7 files changed

Lines changed: 32 additions & 12 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,

tests/lib/Collaboration/Collaborators/SearchResultTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@
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
protected function setUp(): void {
2425
parent::setUp();
2526

2627
$this->container = $this->createMock(IContainer::class);
28+
$this->appConfig = $this->createMock(IAppConfig::class);
2729

28-
$this->search = new Search($this->container);
30+
$this->search = new Search($this->container, $this->appConfig);
2931
}
3032

3133
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,22 +12,24 @@
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
protected function setUp(): void {
2627
parent::setUp();
2728

2829
$this->container = $this->createMock(IContainer::class);
30+
$this->appConfig = $this->createMock(IAppConfig::class);
2931

30-
$this->search = new Search($this->container);
32+
$this->search = new Search($this->container, $this->appConfig);
3133
}
3234

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

0 commit comments

Comments
 (0)