Skip to content

Commit 58878ae

Browse files
authored
Merge pull request #62799 from nextcloud/backport/62701/stable32
[stable32] Expend a bit OCP\GlobalScale\IConfig
2 parents 56f3309 + d297a44 commit 58878ae

2 files changed

Lines changed: 68 additions & 30 deletions

File tree

lib/private/GlobalScale/Config.php

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,30 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
57
* SPDX-License-Identifier: AGPL-3.0-or-later
68
*/
9+
710
namespace OC\GlobalScale;
811

912
use OCP\IConfig;
13+
use Override;
1014

1115
class Config implements \OCP\GlobalScale\IConfig {
12-
/** @var IConfig */
13-
private $config;
14-
15-
/**
16-
* Config constructor.
17-
*
18-
* @param IConfig $config
19-
*/
20-
public function __construct(IConfig $config) {
21-
$this->config = $config;
16+
public function __construct(
17+
private readonly IConfig $config,
18+
) {
2219
}
2320

24-
/**
25-
* check if global scale is enabled
26-
*
27-
* @since 12.0.1
28-
* @return bool
29-
*/
30-
public function isGlobalScaleEnabled() {
21+
#[Override]
22+
public function isGlobalScaleEnabled(): bool {
3123
return $this->config->getSystemValueBool('gs.enabled', false);
3224
}
3325

34-
/**
35-
* check if federation should only be used internally in a global scale setup
36-
*
37-
* @since 12.0.1
38-
* @return bool
39-
*/
40-
public function onlyInternalFederation() {
26+
#[Override]
27+
public function onlyInternalFederation(): bool {
4128
// if global scale is disabled federation works always globally
4229
$gsEnabled = $this->isGlobalScaleEnabled();
4330
if ($gsEnabled === false) {
@@ -48,4 +35,24 @@ public function onlyInternalFederation() {
4835

4936
return $enabled === 'internal';
5037
}
38+
39+
#[Override]
40+
public function isPrimary(): bool {
41+
return $this->isGlobalScaleEnabled()
42+
&& ($this->config->getSystemValueString('gss.mode', 'slave') === 'master'
43+
|| $this->config->getSystemValueString('gss.mode', 'slave') === 'primary');
44+
}
45+
46+
#[Override]
47+
public function isSecondary(): bool {
48+
return $this->isGlobalScaleEnabled()
49+
&& ($this->config->getSystemValueString('gss.mode', 'slave') === 'slave'
50+
|| $this->config->getSystemValueString('gss.mode', 'slave') === 'secondary');
51+
}
52+
53+
#[Override]
54+
public function isPrimaryAdmin(string $userId): bool {
55+
return in_array($userId, $this->config->getSystemValue('gss.master.admin', []))
56+
|| in_array($userId, $this->config->getSystemValue('gss.primary.admin', []));
57+
}
5158
}

lib/public/GlobalScale/IConfig.php

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,60 @@
44
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
55
* SPDX-License-Identifier: AGPL-3.0-or-later
66
*/
7+
78
namespace OCP\GlobalScale;
89

10+
use OCP\AppFramework\Attribute\Consumable;
11+
912
/**
1013
* Interface IConfig
1114
*
1215
* Configuration of the global scale architecture
1316
*
1417
* @since 12.0.1
1518
*/
19+
#[Consumable(since: '12.0.1')]
1620
interface IConfig {
1721
/**
18-
* check if global scale is enabled
22+
* Check if global scale is enabled.
1923
*
2024
* @since 12.0.1
21-
* @return bool
2225
*/
23-
public function isGlobalScaleEnabled();
26+
public function isGlobalScaleEnabled(): bool;
2427

2528
/**
26-
* check if federation should only be used internally in a global scale setup
29+
* Check if federation should only be used internally in a global scale setup.
2730
*
2831
* @since 12.0.1
29-
* @return bool
3032
*/
31-
public function onlyInternalFederation();
33+
public function onlyInternalFederation(): bool;
34+
35+
/**
36+
* Check if the current instance is the primary instance.
37+
*
38+
* This instance is then only used to log in the users and then redirect them
39+
* to their associated secondary instance.
40+
*
41+
* @since 34.0.3
42+
*/
43+
public function isPrimary(): bool;
44+
45+
/**
46+
* Check if the current instance is one of the secondary instance.
47+
*
48+
* These instances are the actual instance of a user and hold all their data.
49+
*
50+
* @since 34.0.3
51+
*/
52+
public function isSecondary(): bool;
53+
54+
/**
55+
* Check if the given user is one of the admin on the primary instance.
56+
*
57+
* These users won't be redirected to a secondary instance and instead will
58+
* stay on the primary instance to manage the configuration of the instance.
59+
*
60+
* @since 34.0.3
61+
*/
62+
public function isPrimaryAdmin(string $userId): bool;
3263
}

0 commit comments

Comments
 (0)