Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/private/GlobalScale/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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', []));
}
}
30 changes: 30 additions & 0 deletions lib/public/GlobalScale/IConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Loading