Skip to content

Commit dc8409d

Browse files
committed
feat(settings): Log AI config changes to audit log
Signed-off-by: Marcel Klehr <[email protected]>
1 parent 0cf140e commit dc8409d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

apps/settings/lib/Controller/AISettingsController.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@
1212
use OCP\AppFramework\Controller;
1313
use OCP\AppFramework\Http\Attribute\AuthorizedAdminSetting;
1414
use OCP\AppFramework\Http\DataResponse;
15+
use OCP\EventDispatcher\IEventDispatcher;
1516
use OCP\IAppConfig;
1617
use OCP\IRequest;
18+
use OCP\Log\Audit\CriticalActionPerformedEvent;
19+
use function OCP\Log\logger;
1720

1821
class AISettingsController extends Controller {
1922

2023
public function __construct(
2124
$appName,
2225
IRequest $request,
26+
private string $userId,
2327
private IAppConfig $appConfig,
28+
private IEventDispatcher $eventDispatcher,
2429
) {
2530
parent::__construct($appName, $request);
2631
}
@@ -38,7 +43,13 @@ public function update($settings) {
3843
if (!isset($settings[$key])) {
3944
continue;
4045
}
41-
$this->appConfig->setValueString('core', $key, json_encode($settings[$key]), lazy: in_array($key, \OC\TaskProcessing\Manager::LAZY_CONFIG_KEYS, true));
46+
$changed = $this->appConfig->setValueString('core', $key, json_encode($settings[$key]), lazy: in_array($key, \OC\TaskProcessing\Manager::LAZY_CONFIG_KEYS, true));
47+
if ($changed) {
48+
$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent(
49+
'AI configuration was changed by user %s: %s was set to %s',
50+
[$this->userId, $key, json_encode($settings[$key])]
51+
));
52+
}
4253
}
4354

4455
return new DataResponse();

0 commit comments

Comments
 (0)