Skip to content

Commit 6c8f727

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

8 files changed

Lines changed: 94 additions & 82 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/oauth2/lib/Controller/LoginRedirectorController.php

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,16 @@
3030

3131
#[OpenAPI(scope: OpenAPI::SCOPE_DEFAULT)]
3232
class LoginRedirectorController extends Controller {
33-
/**
34-
* @param string $appName
35-
* @param IRequest $request
36-
* @param IURLGenerator $urlGenerator
37-
* @param ClientMapper $clientMapper
38-
* @param ISession $session
39-
* @param IL10N $l
40-
*/
4133
public function __construct(
4234
string $appName,
4335
IRequest $request,
44-
private IURLGenerator $urlGenerator,
45-
private ClientMapper $clientMapper,
46-
private ISession $session,
47-
private IL10N $l,
48-
private ISecureRandom $random,
49-
private IAppConfig $appConfig,
50-
private IConfig $config,
36+
private readonly IURLGenerator $urlGenerator,
37+
private readonly ClientMapper $clientMapper,
38+
private readonly ISession $session,
39+
private readonly IL10N $l,
40+
private readonly ISecureRandom $random,
41+
private readonly IAppConfig $appConfig,
42+
private readonly IConfig $config,
5143
) {
5244
parent::__construct($appName, $request);
5345
}
@@ -62,15 +54,14 @@ public function __construct(
6254
* @return TemplateResponse<Http::STATUS_OK, array{}>|RedirectResponse<Http::STATUS_SEE_OTHER, array{}>
6355
*
6456
* 200: Client not found
65-
* 303: Redirect to login URL
57+
* 303: Redirect to the login URL
6658
*/
6759
#[PublicPage]
6860
#[NoCSRFRequired]
6961
#[UseSession]
70-
public function authorize($client_id,
71-
$state,
72-
$response_type,
73-
string $redirect_uri = ''): TemplateResponse|RedirectResponse {
62+
public function authorize(
63+
string $client_id, string $state, string $response_type, string $redirect_uri = '',
64+
): TemplateResponse|RedirectResponse {
7465
try {
7566
$client = $this->clientMapper->getByIdentifier($client_id);
7667
} catch (ClientNotFoundException $e) {

apps/oauth2/lib/Controller/OauthApiController.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use OCP\Authentication\Exceptions\ExpiredTokenException;
2626
use OCP\Authentication\Exceptions\InvalidTokenException;
2727
use OCP\DB\Exception;
28+
use OCP\GlobalScale\IConfig as GlobalScaleConfig;
2829
use OCP\IDBConnection;
2930
use OCP\IRequest;
3031
use OCP\Security\Bruteforce\IThrottler;
@@ -40,16 +41,17 @@ class OauthApiController extends Controller {
4041
public function __construct(
4142
string $appName,
4243
IRequest $request,
43-
private ICrypto $crypto,
44-
private AccessTokenMapper $accessTokenMapper,
45-
private ClientMapper $clientMapper,
46-
private TokenProvider $tokenProvider,
47-
private ISecureRandom $secureRandom,
48-
private ITimeFactory $time,
49-
private LoggerInterface $logger,
50-
private IThrottler $throttler,
51-
private ITimeFactory $timeFactory,
52-
private IDBConnection $db,
44+
private readonly ICrypto $crypto,
45+
private readonly AccessTokenMapper $accessTokenMapper,
46+
private readonly ClientMapper $clientMapper,
47+
private readonly TokenProvider $tokenProvider,
48+
private readonly ISecureRandom $secureRandom,
49+
private readonly ITimeFactory $time,
50+
private readonly LoggerInterface $logger,
51+
private readonly IThrottler $throttler,
52+
private readonly ITimeFactory $timeFactory,
53+
private readonly IDBConnection $db,
54+
private readonly GlobalScaleConfig $globalScaleConfig,
5355
) {
5456
parent::__construct($appName, $request);
5557
}
@@ -229,6 +231,11 @@ public function getToken(
229231

230232
$this->throttler->resetDelay($this->request->getRemoteAddress(), 'login', ['user' => $appToken->getUID()]);
231233

234+
if ($this->globalScaleConfig->isGlobalScaleEnabled() && $this->globalScaleConfig->isPrimary()) {
235+
// Also make sure the access token is available on the secondary instance
236+
237+
}
238+
232239
return new JSONResponse(
233240
[
234241
'access_token' => $newToken,

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
) {

build/psalm-baseline.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2209,11 +2209,6 @@
22092209
<code><![CDATA[setUserValue]]></code>
22102210
</DeprecatedMethod>
22112211
</file>
2212-
<file src="apps/lookup_server_connector/lib/UpdateLookupServer.php">
2213-
<DeprecatedMethod>
2214-
<code><![CDATA[deleteUserValue]]></code>
2215-
</DeprecatedMethod>
2216-
</file>
22172212
<file src="apps/oauth2/lib/Controller/LoginRedirectorController.php">
22182213
<DeprecatedMethod>
22192214
<code><![CDATA[generate]]></code>

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)