Skip to content

Commit 2c1e744

Browse files
committed
refactor: Use GlobalScale/IConfig everywhere
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 854e203 commit 2c1e744

4 files changed

Lines changed: 23 additions & 22 deletions

File tree

apps/lookup_server_connector/lib/BackgroundJobs/RetryJob.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use OCP\AppFramework\Utility\ITimeFactory;
1515
use OCP\BackgroundJob\IJobList;
1616
use OCP\BackgroundJob\Job;
17+
use OCP\GlobalScale\IConfig as GlobalScaleConfig;
1718
use OCP\Http\Client\IClientService;
1819
use OCP\IConfig;
1920
use OCP\IUser;
@@ -39,6 +40,7 @@ public function __construct(
3940
private IUserManager $userManager,
4041
private IAccountManager $accountManager,
4142
private Signer $signer,
43+
private GlobalScaleConfig $globalScaleConfig,
4244
) {
4345
parent::__construct($time);
4446

@@ -86,7 +88,7 @@ public function start(IJobList $jobList): void {
8688
protected function shouldRemoveBackgroundJob(): bool {
8789
// TODO: Remove global scale condition once lookup server is used for non-global scale federation
8890
// return $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'no') !== 'yes'
89-
return !$this->config->getSystemValueBool('gs.enabled', false)
91+
return !$this->globalScaleConfig->isGlobalScaleEnabled()
9092
|| $this->config->getSystemValueBool('has_internet_connection', true) === false
9193
|| $this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com') === ''
9294
|| $this->retries >= 5;

apps/lookup_server_connector/lib/UpdateLookupServer.php

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
use OCA\LookupServerConnector\BackgroundJobs\RetryJob;
1313
use OCP\BackgroundJob\IJobList;
14+
use OCP\Config\IUserConfig;
15+
use OCP\GlobalScale\IConfig as GlobalScaleConfig;
1416
use OCP\IConfig;
1517
use OCP\IUser;
1618

@@ -20,26 +22,21 @@
2022
* @package OCA\LookupServerConnector
2123
*/
2224
class UpdateLookupServer {
23-
/**
24-
* @param IJobList $jobList
25-
* @param IConfig $config
26-
*/
2725
public function __construct(
28-
private IJobList $jobList,
29-
private IConfig $config,
26+
private readonly IJobList $jobList,
27+
private readonly IConfig $config,
28+
private readonly IUserConfig $userConfig,
29+
private readonly GlobalScaleConfig $globalScaleConfig,
3030
) {
3131
}
3232

33-
/**
34-
* @param IUser $user
35-
*/
3633
public function userUpdated(IUser $user): void {
3734
if (!$this->shouldUpdateLookupServer()) {
3835
return;
3936
}
4037

4138
// Reset retry counter
42-
$this->config->deleteUserValue(
39+
$this->userConfig->deleteUserConfig(
4340
$user->getUID(),
4441
'lookup_server_connector',
4542
'update_retries'
@@ -48,17 +45,15 @@ public function userUpdated(IUser $user): void {
4845
}
4946

5047
/**
51-
* check if we should update the lookup server, we only do it if
48+
* Check if we should update the lookup server, we only do it if
5249
*
5350
* + we have an internet connection
5451
* + the lookup server update was not disabled by the admin
5552
* + we have a valid lookup server URL
56-
*
57-
* @return bool
5853
*/
5954
private function shouldUpdateLookupServer(): bool {
6055
// TODO: Consider reenable for non-global-scale setups by checking "'files_sharing', 'lookupServerUploadEnabled'" instead of "gs.enabled"
61-
return $this->config->getSystemValueBool('gs.enabled', false)
56+
return $this->globalScaleConfig->isGlobalScaleEnabled()
6257
&& $this->config->getSystemValueBool('has_internet_connection', true)
6358
&& $this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com') !== '';
6459
}

apps/settings/lib/BackgroundJobs/VerifyUserData.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCP\AppFramework\Utility\ITimeFactory;
1616
use OCP\BackgroundJob\IJobList;
1717
use OCP\BackgroundJob\Job;
18+
use OCP\GlobalScale\IConfig as GlobalScaleConfig;
1819
use OCP\Http\Client\IClientService;
1920
use OCP\IConfig;
2021
use OCP\IUserManager;
@@ -38,6 +39,7 @@ public function __construct(
3839
private LoggerInterface $logger,
3940
ITimeFactory $timeFactory,
4041
private IConfig $config,
42+
private GlobalScaleConfig $globalScaleConfig,
4143
) {
4244
parent::__construct($timeFactory);
4345

@@ -124,7 +126,7 @@ protected function verifyWebsite(array $argument) {
124126

125127
protected function verifyViaLookupServer(array $argument, string $dataType): bool {
126128
// TODO: Consider to enable for non-global-scale setups by checking 'files_sharing', 'lookupServerUploadEnabled'
127-
if (!$this->config->getSystemValueBool('gs.enabled', false)
129+
if (!$this->globalScaleConfig->isGlobalScaleEnabled()
128130
|| empty($this->lookupServerUrl)
129131
|| $this->config->getSystemValue('has_internet_connection', true) === false
130132
) {

lib/private/Collaboration/Collaborators/LookupPlugin.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCP\Collaboration\Collaborators\ISearchResult;
1313
use OCP\Collaboration\Collaborators\SearchResultType;
1414
use OCP\Federation\ICloudIdManager;
15+
use OCP\GlobalScale\IConfig as GlobalScaleConfig;
1516
use OCP\Http\Client\IClientService;
1617
use OCP\IConfig;
1718
use OCP\IUserSession;
@@ -23,20 +24,21 @@ class LookupPlugin implements ISearchPlugin {
2324
private string $currentUserRemote;
2425

2526
public function __construct(
26-
private IConfig $config,
27-
private IClientService $clientService,
27+
private readonly IConfig $config,
28+
private readonly IClientService $clientService,
2829
IUserSession $userSession,
29-
private ICloudIdManager $cloudIdManager,
30-
private LoggerInterface $logger,
31-
private ?TrustedServers $trustedServers,
30+
private readonly ICloudIdManager $cloudIdManager,
31+
private readonly LoggerInterface $logger,
32+
private readonly ?TrustedServers $trustedServers,
33+
private readonly GlobalScaleConfig $globalScaleConfig,
3234
) {
3335
$currentUserCloudId = $userSession->getUser()->getCloudId();
3436
$this->currentUserRemote = $cloudIdManager->resolveCloudId($currentUserCloudId)->getRemote();
3537
}
3638

3739
#[\Override]
3840
public function search($search, $limit, $offset, ISearchResult $searchResult): bool {
39-
$isGlobalScaleEnabled = $this->config->getSystemValueBool('gs.enabled', false);
41+
$isGlobalScaleEnabled = $this->globalScaleConfig->isGlobalScaleEnabled();
4042
$isLookupServerEnabled = $this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') === 'yes';
4143
$hasInternetConnection = $this->config->getSystemValueBool('has_internet_connection', true);
4244

0 commit comments

Comments
 (0)