Files
nextcloud-server-mirror/apps/settings/lib/Controller/PresetController.php
Ghassen kefi 81ce503a20 feat(settings): log credential, security and server settings changes
Audit entries are added for app password creation, deletion and scope
changes, remote wipe requests, WebAuthn devices, two-factor
enforcement, mail server settings and credentials, admin delegation,
presets, declarative settings and log file downloads.

The existing AI settings entry keeps its message and now carries an
operation (settings.ai.updated) and named parameters.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Ghassen kefi <ghassen.kefi.dev@gmail.com>
2026-11-05 16:35:13 +01:00

63 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Settings\Controller;
use OC\Config\PresetManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\Config\Lexicon\Preset;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IRequest;
use OCP\Log\Audit\CriticalActionPerformedEvent;
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
class PresetController extends Controller {
public function __construct(
string $appName,
IRequest $request,
private readonly PresetManager $presetManager,
private readonly IEventDispatcher $eventDispatcher,
) {
parent::__construct($appName, $request);
}
public function getCurrentPreset(): DataResponse {
return new DataResponse($this->presetManager->getLexiconPreset()->name);
}
public function setCurrentPreset(string $presetName): DataResponse {
foreach (Preset::cases() as $case) {
if ($case->name === $presetName) {
$this->presetManager->setLexiconPreset($case);
$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent(
'Configuration preset "%s" was applied',
['presetName' => $case->name],
false,
'settings.preset.applied',
));
return $this->getCurrentPreset();
}
}
throw new OCSBadRequestException('Invalid preset name provided');
}
public function getPreset(): DataResponse {
return new DataResponse(
[
'preset' => $this->presetManager->retrieveLexiconPreset(),
'apps' => $this->presetManager->retrieveLexiconPresetApps()
]
);
}
}