mirror of
https://github.com/nextcloud/server.git
synced 2026-11-26 16:15:53 +01:00
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>
71 lines
2.1 KiB
PHP
71 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
namespace OCA\Settings\Controller;
|
|
|
|
use OCA\Settings\Settings\Admin\ArtificialIntelligence;
|
|
use OCP\AppFramework\Controller;
|
|
use OCP\AppFramework\Http;
|
|
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
|
|
use OCP\AppFramework\Http\DataResponse;
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
|
use OCP\IAppConfig;
|
|
use OCP\IRequest;
|
|
use OCP\Log\Audit\CriticalActionPerformedEvent;
|
|
|
|
class AISettingsController extends Controller {
|
|
|
|
public function __construct(
|
|
$appName,
|
|
IRequest $request,
|
|
private string $userId,
|
|
private IAppConfig $appConfig,
|
|
private IEventDispatcher $eventDispatcher,
|
|
) {
|
|
parent::__construct($appName, $request);
|
|
}
|
|
|
|
/**
|
|
* Sets the AI settings
|
|
*
|
|
* @param array $settings
|
|
* @return DataResponse
|
|
*/
|
|
#[AuthorizedAdminSetting(settings: ArtificialIntelligence::class)]
|
|
public function update($settings) {
|
|
$keys = ['ai.stt_provider', 'ai.textprocessing_provider_preferences', 'ai.taskprocessing_provider_preferences','ai.taskprocessing_type_preferences', 'ai.translation_provider_preferences', 'ai.text2image_provider', 'ai.taskprocessing_guests'];
|
|
foreach ($keys as $key) {
|
|
if (!isset($settings[$key])) {
|
|
continue;
|
|
}
|
|
try {
|
|
$settings[$key] = json_encode($settings[$key], flags: \JSON_THROW_ON_ERROR);
|
|
} catch (\JsonException) {
|
|
return new DataResponse(['error' => "Setting value for '$key' must be JSON-compatible"], Http::STATUS_BAD_REQUEST);
|
|
}
|
|
}
|
|
foreach ($keys as $key) {
|
|
if (!isset($settings[$key])) {
|
|
continue;
|
|
}
|
|
$changed = $this->appConfig->setValueString('core', $key, $settings[$key], lazy: in_array($key, \OC\TaskProcessing\Manager::LAZY_CONFIG_KEYS, true));
|
|
if ($changed) {
|
|
$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent(
|
|
'AI configuration was changed by user %s: %s was set to %s',
|
|
['userId' => $this->userId, 'configKey' => $key, 'configValue' => $settings[$key]],
|
|
false,
|
|
'settings.ai.updated',
|
|
));
|
|
}
|
|
}
|
|
|
|
return new DataResponse();
|
|
}
|
|
}
|