Skip to content

Commit e9fe64e

Browse files
Merge pull request #2327 from nextcloud/backport/2324/stable33
[stable33] admin settings endpoint
2 parents f384a6f + 5d96dbf commit e9fe64e

File tree

3 files changed

+111
-1
lines changed

3 files changed

+111
-1
lines changed

appinfo/routes.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@
7979
['name' => 'Admin#editDescription', 'url' => '/admin/{emulated}/circles/{circleId}/description', 'verb' => 'PUT'],
8080
['name' => 'Admin#editSetting', 'url' => '/admin/{emulated}/circles/{circleId}/setting', 'verb' => 'PUT'],
8181
['name' => 'Admin#editConfig', 'url' => '/admin/{emulated}/circles/{circleId}/config', 'verb' => 'PUT'],
82-
['name' => 'Admin#link', 'url' => '/admin/{emulated}/link/{circleId}/{singleId}', 'verb' => 'GET']
82+
['name' => 'Admin#link', 'url' => '/admin/{emulated}/link/{circleId}/{singleId}', 'verb' => 'GET'],
83+
84+
['name' => 'Settings#getValues', 'url' => '/settings/', 'verb' => 'GET'],
85+
['name' => 'Settings#setValue', 'url' => '/settings/{key}/', 'verb' => 'POST'],
8386
],
8487

8588
'routes' => [

lib/ConfigLexicon.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121
*/
2222
class ConfigLexicon implements ILexicon {
2323
public const USER_SINGLE_ID = 'userSingleId';
24+
public const FEDERATED_TEAMS_ENABLED = 'federated_teams_enabled';
25+
public const FEDERATED_TEAMS_FRONTAL = 'federated_teams_frontal';
2426

2527
public function getStrictness(): Strictness {
2628
return Strictness::IGNORE;
2729
}
2830

2931
public function getAppConfigs(): array {
3032
return [
33+
new Entry(key: self::FEDERATED_TEAMS_ENABLED, type: ValueType::BOOL, defaultRaw: false, definition: 'disable/enable Federated Teams', lazy: true),
34+
new Entry(key: self::FEDERATED_TEAMS_FRONTAL, type: ValueType::STRING, defaultRaw: '', definition: 'domain name used to auth public request', lazy: true),
3135
];
3236
}
3337

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\Circles\Controller;
11+
12+
use OCA\Circles\ConfigLexicon;
13+
use OCA\Circles\Service\ConfigService;
14+
use OCP\AppFramework\Http;
15+
use OCP\AppFramework\Http\DataResponse;
16+
use OCP\AppFramework\OCSController;
17+
use OCP\AppFramework\Services\IAppConfig;
18+
use OCP\IRequest;
19+
20+
class SettingsController extends OCSController {
21+
public function __construct(
22+
string $appName,
23+
IRequest $request,
24+
private readonly IAppConfig $appConfig,
25+
) {
26+
parent::__construct($appName, $request);
27+
}
28+
29+
public function setValue(string $key, string $value): DataResponse {
30+
if ($key === ConfigLexicon::FEDERATED_TEAMS_FRONTAL) {
31+
if ($this->setFrontalValue($value)) {
32+
return $this->getValues();
33+
}
34+
35+
return new DataResponse(['data' => ['message' => 'wrongly formated value']], Http::STATUS_BAD_REQUEST);
36+
}
37+
38+
if ($key === ConfigLexicon::FEDERATED_TEAMS_ENABLED) {
39+
$this->appConfig->setAppValueBool(ConfigLexicon::FEDERATED_TEAMS_ENABLED, $value === 'yes');
40+
return $this->getValues();
41+
}
42+
43+
return new DataResponse(['data' => ['message' => 'unsupported key']], Http::STATUS_BAD_REQUEST);
44+
}
45+
46+
public function getValues(): DataResponse {
47+
return new DataResponse([
48+
ConfigLexicon::FEDERATED_TEAMS_FRONTAL => $this->getFrontalValue() ?? '',
49+
ConfigLexicon::FEDERATED_TEAMS_ENABLED => $this->appConfig->getAppValueBool(ConfigLexicon::FEDERATED_TEAMS_ENABLED),
50+
]);
51+
}
52+
53+
private function setFrontalValue(string $url): bool {
54+
[$scheme, $cloudId, $path] = $this->parseFrontalAddress($url);
55+
if (is_null($scheme)) {
56+
return false;
57+
}
58+
59+
$this->appConfig->setAppValueString(ConfigLexicon::FEDERATED_TEAMS_FRONTAL, $url);
60+
$this->appConfig->setAppValueString(ConfigService::FRONTAL_CLOUD_SCHEME, $scheme);
61+
$this->appConfig->setAppValueString(ConfigService::FRONTAL_CLOUD_ID, $cloudId);
62+
$this->appConfig->setAppValueString(ConfigService::FRONTAL_CLOUD_PATH, $path);
63+
64+
return true;
65+
}
66+
67+
private function getFrontalValue(): ?string {
68+
if ($this->appConfig->hasAppKey(ConfigLexicon::FEDERATED_TEAMS_FRONTAL)) {
69+
return $this->appConfig->getAppValueString(ConfigLExicon::FEDERATED_TEAMS_FRONTAL);
70+
}
71+
72+
if (!$this->appConfig->hasAppKey(ConfigService::FRONTAL_CLOUD_SCHEME)
73+
|| !$this->appConfig->hasAppKey(ConfigService::FRONTAL_CLOUD_ID)
74+
|| !$this->appConfig->hasAppKey(ConfigService::FRONTAL_CLOUD_PATH)) {
75+
return null;
76+
}
77+
78+
return $this->appConfig->getAppValueString(ConfigService::FRONTAL_CLOUD_SCHEME) . '://' .
79+
$this->appConfig->getAppValueString(ConfigService::FRONTAL_CLOUD_ID) .
80+
$this->appConfig->getAppValueString(ConfigService::FRONTAL_CLOUD_PATH) . '/';
81+
}
82+
83+
private function parseFrontalAddress(string $url): ?array {
84+
$scheme = parse_url($url, PHP_URL_SCHEME);
85+
$cloudId = parse_url($url, PHP_URL_HOST);
86+
$cloudIdPort = parse_url($url, PHP_URL_PORT);
87+
$path = parse_url($url, PHP_URL_PATH);
88+
89+
if (is_bool($scheme) || is_bool($cloudId) || is_null($scheme) || is_null($cloudId)) {
90+
return null;
91+
}
92+
93+
if (is_null($path) || is_bool($path)) {
94+
$path = '';
95+
}
96+
$path = rtrim($path, '/');
97+
if (!is_null($cloudIdPort)) {
98+
$cloudId .= ':' . ((string)$cloudIdPort);
99+
}
100+
101+
return [$scheme, $cloudId, $path];
102+
}
103+
}

0 commit comments

Comments
 (0)