From 85f5c55531d4baa31ef533615e42eb20a7a7aeaa Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Wed, 29 Jul 2026 13:46:07 +0200 Subject: [PATCH] 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 --- lib/private/GlobalScale/Config.php | 21 +++++++++++++++++++++ lib/public/GlobalScale/IConfig.php | 30 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/lib/private/GlobalScale/Config.php b/lib/private/GlobalScale/Config.php index 4319a2fbb4285..be35487f3c314 100644 --- a/lib/private/GlobalScale/Config.php +++ b/lib/private/GlobalScale/Config.php @@ -6,6 +6,7 @@ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ + namespace OC\GlobalScale; use OCP\IConfig; @@ -34,4 +35,24 @@ public function onlyInternalFederation(): bool { return $enabled === 'internal'; } + + #[Override] + public function isPrimary(): bool { + return $this->isGlobalScaleEnabled() + && ($this->config->getSystemValueString('gss.mode', 'slave') === 'master' + || $this->config->getSystemValueString('gss.mode', 'slave') === 'primary'); + } + + #[Override] + public function isSecondary(): bool { + return $this->isGlobalScaleEnabled() + && ($this->config->getSystemValueString('gss.mode', 'slave') === 'slave' + || $this->config->getSystemValueString('gss.mode', 'slave') === 'secondary'); + } + + #[Override] + public function isPrimaryAdmin(string $userId): bool { + return in_array($userId, $this->config->getSystemValue('gss.master.admin', [])) + || in_array($userId, $this->config->getSystemValue('gss.primary.admin', [])); + } } diff --git a/lib/public/GlobalScale/IConfig.php b/lib/public/GlobalScale/IConfig.php index 38efce4b8b55e..bd71adbed0c20 100644 --- a/lib/public/GlobalScale/IConfig.php +++ b/lib/public/GlobalScale/IConfig.php @@ -4,6 +4,7 @@ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ + namespace OCP\GlobalScale; use OCP\AppFramework\Attribute\Consumable; @@ -30,4 +31,33 @@ public function isGlobalScaleEnabled(): bool; * @since 12.0.1 */ public function onlyInternalFederation(): bool; + + /** + * Check if the current instance is the primary instance. + * + * This instance is then only used to log in the users and then redirect them + * to their associated secondary instance. + * + * @since 34.0.3 + */ + public function isPrimary(): bool; + + /** + * Check if the current instance is one of the secondary instance. + * + * These instances are the actual instance of a user and hold all their data. + * + * @since 34.0.3 + */ + public function isSecondary(): bool; + + /** + * Check if the given user is one of the admin on the primary instance. + * + * These users won't be redirected to a secondary instance and instead will + * stay on the primary instance to manage the configuration of the instance. + * + * @since 34.0.3 + */ + public function isPrimaryAdmin(string $userId): bool; }