Skip to content

Commit 58dcd3d

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 77c5d71 commit 58dcd3d

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

lib/private/GlobalScale/Config.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,24 @@ public function onlyInternalFederation(): bool {
3535

3636
return $enabled === 'internal';
3737
}
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+
}
3858
}

lib/public/GlobalScale/IConfig.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,33 @@ public function isGlobalScaleEnabled(): bool;
3131
* @since 12.0.1
3232
*/
3333
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;
3463
}

0 commit comments

Comments
 (0)