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
5 changes: 4 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@
['name' => 'Admin#editDescription', 'url' => '/admin/{emulated}/circles/{circleId}/description', 'verb' => 'PUT'],
['name' => 'Admin#editSetting', 'url' => '/admin/{emulated}/circles/{circleId}/setting', 'verb' => 'PUT'],
['name' => 'Admin#editConfig', 'url' => '/admin/{emulated}/circles/{circleId}/config', 'verb' => 'PUT'],
['name' => 'Admin#link', 'url' => '/admin/{emulated}/link/{circleId}/{singleId}', 'verb' => 'GET']
['name' => 'Admin#link', 'url' => '/admin/{emulated}/link/{circleId}/{singleId}', 'verb' => 'GET'],

['name' => 'Settings#getValues', 'url' => '/settings/', 'verb' => 'GET'],
['name' => 'Settings#setValue', 'url' => '/settings/{key}/', 'verb' => 'POST'],
],

'routes' => [
Expand Down
4 changes: 4 additions & 0 deletions lib/ConfigLexicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
*/
class ConfigLexicon implements ILexicon {
public const USER_SINGLE_ID = 'userSingleId';
public const FEDERATED_TEAMS_ENABLED = 'federated_teams_enabled';
public const FEDERATED_TEAMS_FRONTAL = 'federated_teams_frontal';

public function getStrictness(): Strictness {
return Strictness::IGNORE;
}

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

Expand Down
103 changes: 103 additions & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Circles\Controller;

use OCA\Circles\ConfigLexicon;
use OCA\Circles\Service\ConfigService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\AppFramework\Services\IAppConfig;
use OCP\IRequest;

class SettingsController extends OCSController {
public function __construct(
string $appName,
IRequest $request,
private readonly IAppConfig $appConfig,
) {
parent::__construct($appName, $request);
}

public function setValue(string $key, string $value): DataResponse {
if ($key === ConfigLexicon::FEDERATED_TEAMS_FRONTAL) {
if ($this->setFrontalValue($value)) {
return $this->getValues();
}

return new DataResponse(['data' => ['message' => 'wrongly formated value']], Http::STATUS_BAD_REQUEST);
}

if ($key === ConfigLexicon::FEDERATED_TEAMS_ENABLED) {
$this->appConfig->setAppValueBool(ConfigLexicon::FEDERATED_TEAMS_ENABLED, $value === 'yes');
return $this->getValues();
}

return new DataResponse(['data' => ['message' => 'unsupported key']], Http::STATUS_BAD_REQUEST);
}

public function getValues(): DataResponse {
return new DataResponse([
ConfigLexicon::FEDERATED_TEAMS_FRONTAL => $this->getFrontalValue() ?? '',
ConfigLexicon::FEDERATED_TEAMS_ENABLED => $this->appConfig->getAppValueBool(ConfigLexicon::FEDERATED_TEAMS_ENABLED),
]);
}

private function setFrontalValue(string $url): bool {
[$scheme, $cloudId, $path] = $this->parseFrontalAddress($url);
if (is_null($scheme)) {
return false;
}

$this->appConfig->setAppValueString(ConfigLexicon::FEDERATED_TEAMS_FRONTAL, $url);
$this->appConfig->setAppValueString(ConfigService::FRONTAL_CLOUD_SCHEME, $scheme);
$this->appConfig->setAppValueString(ConfigService::FRONTAL_CLOUD_ID, $cloudId);
$this->appConfig->setAppValueString(ConfigService::FRONTAL_CLOUD_PATH, $path);

return true;
}

private function getFrontalValue(): ?string {
if ($this->appConfig->hasAppKey(ConfigLexicon::FEDERATED_TEAMS_FRONTAL)) {
return $this->appConfig->getAppValueString(ConfigLExicon::FEDERATED_TEAMS_FRONTAL);
}

if (!$this->appConfig->hasAppKey(ConfigService::FRONTAL_CLOUD_SCHEME)
|| !$this->appConfig->hasAppKey(ConfigService::FRONTAL_CLOUD_ID)
|| !$this->appConfig->hasAppKey(ConfigService::FRONTAL_CLOUD_PATH)) {
return null;
}

return $this->appConfig->getAppValueString(ConfigService::FRONTAL_CLOUD_SCHEME) . '://' .
$this->appConfig->getAppValueString(ConfigService::FRONTAL_CLOUD_ID) .
$this->appConfig->getAppValueString(ConfigService::FRONTAL_CLOUD_PATH) . '/';
}

private function parseFrontalAddress(string $url): ?array {
$scheme = parse_url($url, PHP_URL_SCHEME);
$cloudId = parse_url($url, PHP_URL_HOST);
$cloudIdPort = parse_url($url, PHP_URL_PORT);
$path = parse_url($url, PHP_URL_PATH);

if (is_bool($scheme) || is_bool($cloudId) || is_null($scheme) || is_null($cloudId)) {
return null;
}

if (is_null($path) || is_bool($path)) {
$path = '';
}
$path = rtrim($path, '/');
if (!is_null($cloudIdPort)) {
$cloudId .= ':' . ((string)$cloudIdPort);
}

return [$scheme, $cloudId, $path];
}
}
Loading