Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/AppInfo/ConfigLexicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion lib/private/Collaboration/Collaborators/LookupPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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'] ?? '';
Expand Down
6 changes: 6 additions & 0 deletions lib/private/Collaboration/Collaborators/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

public function __construct(
private IContainer $container,
private readonly IAppConfig $appConfig,
) {
}

Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/Collaboration/Collaborators/LookupPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
Expand All @@ -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);
Expand All @@ -67,6 +71,7 @@ protected function setUp(): void {

$this->plugin = new LookupPlugin(
$this->config,
$this->appConfig,
$this->clientService,
$this->userSession,
$this->cloudIdManager,
Expand Down
12 changes: 7 additions & 5 deletions tests/lib/Collaboration/Collaborators/SearchResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 7 additions & 5 deletions tests/lib/Collaboration/Collaborators/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
Expand Down
Loading