From 036ec8f88cbf9ab4e5d009479c2e6c42f606ed9a 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 | 55 +++++++++++++++++------------- lib/public/GlobalScale/IConfig.php | 43 +++++++++++++++++++---- 2 files changed, 68 insertions(+), 30 deletions(-) diff --git a/lib/private/GlobalScale/Config.php b/lib/private/GlobalScale/Config.php index 2f729c2702ee1..be35487f3c314 100644 --- a/lib/private/GlobalScale/Config.php +++ b/lib/private/GlobalScale/Config.php @@ -1,43 +1,30 @@ config = $config; + public function __construct( + private readonly IConfig $config, + ) { } - /** - * check if global scale is enabled - * - * @since 12.0.1 - * @return bool - */ - public function isGlobalScaleEnabled() { + #[Override] + public function isGlobalScaleEnabled(): bool { return $this->config->getSystemValueBool('gs.enabled', false); } - /** - * check if federation should only be used internally in a global scale setup - * - * @since 12.0.1 - * @return bool - */ - public function onlyInternalFederation() { + #[Override] + public function onlyInternalFederation(): bool { // if global scale is disabled federation works always globally $gsEnabled = $this->isGlobalScaleEnabled(); if ($gsEnabled === false) { @@ -48,4 +35,24 @@ public function onlyInternalFederation() { 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 bae5dd7aa66a3..bd71adbed0c20 100644 --- a/lib/public/GlobalScale/IConfig.php +++ b/lib/public/GlobalScale/IConfig.php @@ -4,8 +4,11 @@ * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ + namespace OCP\GlobalScale; +use OCP\AppFramework\Attribute\Consumable; + /** * Interface IConfig * @@ -13,20 +16,48 @@ * * @since 12.0.1 */ +#[Consumable(since: '12.0.1')] interface IConfig { /** - * check if global scale is enabled + * Check if global scale is enabled. * * @since 12.0.1 - * @return bool */ - public function isGlobalScaleEnabled(); + public function isGlobalScaleEnabled(): bool; /** - * check if federation should only be used internally in a global scale setup + * Check if federation should only be used internally in a global scale setup. * * @since 12.0.1 - * @return bool */ - public function onlyInternalFederation(); + 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; }