Skip to content

Commit 85f5c55

Browse files
committed
feat(globalscale): Expose more configs
These are the configs used in a bunch of applications (e.g. user_saml and user_oidc). Standarize them. Signed-off-by: Carl Schwan <carl@carlschwan.eu>
1 parent 8698ea8 commit 85f5c55

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

lib/private/GlobalScale/Config.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
77
* SPDX-License-Identifier: AGPL-3.0-or-later
88
*/
9+
910
namespace OC\GlobalScale;
1011

1112
use OCP\IConfig;
@@ -34,4 +35,24 @@ public function onlyInternalFederation(): bool {
3435

3536
return $enabled === 'internal';
3637
}
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+
}
3758
}

lib/public/GlobalScale/IConfig.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
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

910
use OCP\AppFramework\Attribute\Consumable;
@@ -30,4 +31,33 @@ public function isGlobalScaleEnabled(): bool;
3031
* @since 12.0.1
3132
*/
3233
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;
3363
}

0 commit comments

Comments
 (0)