Skip to content

Commit

Permalink
fix(lookup-server): disable lookup server for non-global scale setups
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Mar 10, 2025
1 parent 98cfdea commit 4d95896
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 53 deletions.
11 changes: 8 additions & 3 deletions apps/federatedfilesharing/lib/FederatedShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,10 @@ public function isLookupServerQueriesEnabled(): bool {
if ($this->gsConfig->isGlobalScaleEnabled()) {
return true;
}
$result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no');
$result = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes';
// TODO: Reenable if lookup server is used again
// return $result;
return false;
}


Expand All @@ -1010,8 +1013,10 @@ public function isLookupServerUploadEnabled(): bool {
if ($this->gsConfig->isGlobalScaleEnabled()) {
return false;
}
$result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'no');
return $result === 'yes';
$result = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'no') === 'yes';
// TODO: Reenable if lookup server is used again
// return $result;
return false;
}

/**
Expand Down
26 changes: 16 additions & 10 deletions apps/federatedfilesharing/src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,23 @@
{{ t('federatedfilesharing', 'Allow people on this server to receive group shares from other servers') }}
</NcCheckboxRadioSwitch>

<NcCheckboxRadioSwitch type="switch"
:checked.sync="lookupServerEnabled"
@update:checked="update('lookupServerEnabled', lookupServerEnabled)">
{{ t('federatedfilesharing', 'Search global and public address book for people') }}
</NcCheckboxRadioSwitch>
<fieldset>
<legend>{{ t('federatedfilesharing', 'The lookup server is only available for global scale.') }}</legend>

<NcCheckboxRadioSwitch type="switch"
:checked.sync="lookupServerUploadEnabled"
@update:checked="update('lookupServerUploadEnabled', lookupServerUploadEnabled)">
{{ t('federatedfilesharing', 'Allow people to publish their data to a global and public address book') }}
</NcCheckboxRadioSwitch>
<NcCheckboxRadioSwitch type="switch"
:checked.sync="lookupServerEnabled"
disabled
@update:checked="update('lookupServerEnabled', lookupServerEnabled)">
{{ t('federatedfilesharing', 'Search global and public address book for people') }}
</NcCheckboxRadioSwitch>

<NcCheckboxRadioSwitch type="switch"
:checked.sync="lookupServerUploadEnabled"
disabled
@update:checked="update('lookupServerUploadEnabled', lookupServerUploadEnabled)">
{{ t('federatedfilesharing', 'Allow people to publish their data to a global and public address book') }}
</NcCheckboxRadioSwitch>
</fieldset>

<!-- Trusted server handling -->
<div class="settings-subsection">
Expand Down
14 changes: 10 additions & 4 deletions apps/federatedfilesharing/tests/FederatedShareProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -836,10 +836,13 @@ public function testIsLookupServerQueriesEnabled($gsEnabled, $isEnabled, $expect

public function dataTestIsLookupServerQueriesEnabled() {
return [
[false, 'yes', true],
[false, 'no', false],
[true, 'yes', true],
[true, 'no', true],
// TODO: reenable if we use the lookup server for non-global scale
// [false, 'yes', true],
// [false, 'no', false],
[false, 'no', false],
[false, 'yes', false],
];
}

Expand All @@ -863,10 +866,13 @@ public function testIsLookupServerUploadEnabled($gsEnabled, $isEnabled, $expecte

public function dataTestIsLookupServerUploadEnabled() {
return [
[false, 'yes', true],
[false, 'no', false],
[true, 'yes', false],
[true, 'no', false],
// TODO: reenable if we use the lookup server again
// [false, 'yes', true],
// [false, 'no', false],
[false, 'yes', false],
[false, 'no', false],
];
}

Expand Down
10 changes: 5 additions & 5 deletions apps/files_sharing/lib/Controller/ShareesAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use OCP\Collaboration\Collaborators\ISearchResult;
use OCP\Collaboration\Collaborators\SearchResultType;
use OCP\Constants;
use OCP\GlobalScale\IConfig as GlobalScaleIConfig;
use OCP\IConfig;
use OCP\IRequest;
use OCP\IURLGenerator;
Expand Down Expand Up @@ -175,12 +176,11 @@ public function search(string $search = '', ?string $itemType = null, int $page
$this->limit = $perPage;
$this->offset = $perPage * ($page - 1);

// In global scale mode we always search the loogup server
$lookup = $this->config->getSystemValueBool('gs.enabled', false)
|| $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes';
$this->result['lookupEnabled'] = $lookup;
// In global scale mode we always search the lookup server
$this->result['lookupEnabled'] = Server::get(GlobalScaleIConfig::class)->isGlobalScaleEnabled();
// TODO: Reconsider using lookup server for non-global-scale federation

[$result, $hasMoreResults] = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset);
[$result, $hasMoreResults] = $this->collaboratorSearch->search($search, $shareTypes, $this->result['lookupEnabled'], $this->limit, $this->offset);

// extra treatment for 'exact' subarray, with a single merge expected keys might be lost
if (isset($result['exact'])) {
Expand Down
11 changes: 6 additions & 5 deletions apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ public function start(IJobList $jobList): void {
* - max retries are reached (set to 5)
*/
protected function shouldRemoveBackgroundJob(): bool {
return $this->config->getSystemValueBool('has_internet_connection', true) === false ||
$this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com') === '' ||
$this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'no') !== 'yes' ||
$this->retries >= 5;
// TODO: Remove global scale condition once lookup server is used for non-global scale federation
return !$this->config->getSystemValueBool('gs.enabled', false)
|| $this->config->getSystemValueBool('has_internet_connection', true) === false
|| $this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com') === ''
|| $this->retries >= 5;
}

protected function shouldRun(): bool {
Expand Down Expand Up @@ -149,7 +150,7 @@ protected function run($argument): void {
$user->getUID(),
'lookup_server_connector',
'update_retries',
$this->retries + 1
(string)($this->retries + 1),
);
}
}
Expand Down
7 changes: 4 additions & 3 deletions apps/lookup_server_connector/lib/UpdateLookupServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public function userUpdated(IUser $user): void {
* @return bool
*/
private function shouldUpdateLookupServer(): bool {
return $this->config->getSystemValueBool('has_internet_connection', true) === true &&
$this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'no') === 'yes' &&
$this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com') !== '';
// TODO: Consider reenable for non-global-scale setups by checking "'files_sharing', 'lookupServerUploadEnabled'" instead of "gs.enabled"
return $this->config->getSystemValueBool('gs.enabled', false)
&& $this->config->getSystemValueBool('has_internet_connection', true)
&& $this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com') !== '';
}
}
8 changes: 5 additions & 3 deletions apps/settings/lib/BackgroundJobs/VerifyUserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ protected function verifyWebsite(array $argument) {
}

protected function verifyViaLookupServer(array $argument, string $dataType): bool {
if (empty($this->lookupServerUrl) ||
$this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'no') !== 'yes' ||
$this->config->getSystemValue('has_internet_connection', true) === false) {
// TODO: Consider to enable for non-global-scale setups by checking 'files_sharing', 'lookupServerUploadEnabled'
if (!$this->config->getSystemValueBool('gs.enabled', false)
|| empty($this->lookupServerUrl)
|| $this->config->getSystemValue('has_internet_connection', true) === false
) {
return true;
}

Expand Down
6 changes: 4 additions & 2 deletions lib/private/Collaboration/Collaborators/LookupPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ public function search($search, $limit, $offset, ISearchResult $searchResult): b
$isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes';
$hasInternetConnection = $this->config->getSystemValueBool('has_internet_connection', true);

// if case of Global Scale we always search the lookup server
if (!$isGlobalScaleEnabled && (!$isLookupServerEnabled || !$hasInternetConnection)) {
// If case of Global Scale we always search the lookup server
// TODO: Reconsider using the lookup server for non-global scale
// if (!$isGlobalScaleEnabled && (!$isLookupServerEnabled || !$hasInternetConnection || $disableLookupServer)) {
if (!$isGlobalScaleEnabled) {
return false;
}

Expand Down
35 changes: 17 additions & 18 deletions tests/lib/Collaboration/Collaborators/LookupPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ protected function setUp(): void {
public function testSearchNoLookupServerURI(): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('files_sharing', 'lookupServerEnabled', 'yes')
->with('files_sharing', 'lookupServerEnabled', 'no')
->willReturn('yes');
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
->withConsecutive(
['gs.enabled', false],
['has_internet_connection', true],
)->willReturnOnConsecutiveCalls(
false,
true,
true,
);

Expand All @@ -101,7 +101,7 @@ public function testSearchNoLookupServerURI(): void {
public function testSearchNoInternet(): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('files_sharing', 'lookupServerEnabled', 'yes')
->with('files_sharing', 'lookupServerEnabled', 'no')
->willReturn('yes');
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
Expand Down Expand Up @@ -137,15 +137,15 @@ public function testSearch(array $searchParams): void {

$this->config->expects($this->once())
->method('getAppValue')
->with('files_sharing', 'lookupServerEnabled', 'yes')
->with('files_sharing', 'lookupServerEnabled', 'no')
->willReturn('yes');
$this->config->expects($this->exactly(2))
->method('getSystemValueBool')
->withConsecutive(
['gs.enabled', false],
['has_internet_connection', true],
)->willReturnOnConsecutiveCalls(
false,
true,
true,
);

Expand Down Expand Up @@ -197,9 +197,9 @@ public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnab

$this->config->expects($this->once())
->method('getAppValue')
->with('files_sharing', 'lookupServerEnabled', 'yes')
->with('files_sharing', 'lookupServerEnabled', 'no')
->willReturn($LookupEnabled ? 'yes' : 'no');
if ($GSEnabled || $LookupEnabled) {
if ($GSEnabled) {
$searchResult->expects($this->once())
->method('addResultSet')
->with($type, $searchParams['expectedResult'], []);
Expand Down Expand Up @@ -258,11 +258,13 @@ public function testSearchEnableDisableLookupServer(array $searchParams, $GSEnab
}


public function testSearchLookupServerDisabled(): void {
$this->config->expects($this->once())
->method('getAppValue')
->with('files_sharing', 'lookupServerEnabled', 'yes')
->willReturn('no');
public function testSearchGSDisabled(): void {
$this->config->expects($this->atLeastOnce())
->method('getSystemValueBool')
->willReturnMap([
['has_internet_connection', true, true],
['gs.enabled', false, false],
]);

/** @var ISearchResult|MockObject $searchResult */
$searchResult = $this->createMock(ISearchResult::class);
Expand Down Expand Up @@ -381,7 +383,6 @@ public function dataSearchEnableDisableLookupServer() {
'label' => $fedIDs[0],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => false,
'shareWith' => $fedIDs[0]
],
'extra' => ['federationId' => $fedIDs[0]],
Expand All @@ -390,7 +391,6 @@ public function dataSearchEnableDisableLookupServer() {
'label' => $fedIDs[1],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => false,
'shareWith' => $fedIDs[1]
],
'extra' => ['federationId' => $fedIDs[1]],
Expand All @@ -399,7 +399,6 @@ public function dataSearchEnableDisableLookupServer() {
'label' => $fedIDs[2],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => false,
'shareWith' => $fedIDs[2]
],
'extra' => ['federationId' => $fedIDs[2]],
Expand Down Expand Up @@ -474,7 +473,7 @@ public function searchDataProvider() {
'label' => $fedIDs[0],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => false,
'globalScale' => true,
'shareWith' => $fedIDs[0]
],
'extra' => ['federationId' => $fedIDs[0]],
Expand All @@ -483,7 +482,7 @@ public function searchDataProvider() {
'label' => $fedIDs[1],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => false,
'globalScale' => true,
'shareWith' => $fedIDs[1]
],
'extra' => ['federationId' => $fedIDs[1]],
Expand All @@ -492,7 +491,7 @@ public function searchDataProvider() {
'label' => $fedIDs[2],
'value' => [
'shareType' => IShare::TYPE_REMOTE,
'globalScale' => false,
'globalScale' => true,
'shareWith' => $fedIDs[2]
],
'extra' => ['federationId' => $fedIDs[2]],
Expand Down

0 comments on commit 4d95896

Please sign in to comment.