Skip to content
Merged
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
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@
'OCP\\User\\Events\\PasswordUpdatedEvent' => $baseDir . '/lib/public/User/Events/PasswordUpdatedEvent.php',
'OCP\\User\\Events\\PostLoginEvent' => $baseDir . '/lib/public/User/Events/PostLoginEvent.php',
'OCP\\User\\Events\\UserChangedEvent' => $baseDir . '/lib/public/User/Events/UserChangedEvent.php',
'OCP\\User\\Events\\UserConfigChangedEvent' => $baseDir . '/lib/public/User/Events/UserConfigChangedEvent.php',
'OCP\\User\\Events\\UserCreatedEvent' => $baseDir . '/lib/public/User/Events/UserCreatedEvent.php',
'OCP\\User\\Events\\UserDeletedEvent' => $baseDir . '/lib/public/User/Events/UserDeletedEvent.php',
'OCP\\User\\Events\\UserFirstTimeLoggedInEvent' => $baseDir . '/lib/public/User/Events/UserFirstTimeLoggedInEvent.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\User\\Events\\PasswordUpdatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/PasswordUpdatedEvent.php',
'OCP\\User\\Events\\PostLoginEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/PostLoginEvent.php',
'OCP\\User\\Events\\UserChangedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserChangedEvent.php',
'OCP\\User\\Events\\UserConfigChangedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserConfigChangedEvent.php',
'OCP\\User\\Events\\UserCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserCreatedEvent.php',
'OCP\\User\\Events\\UserDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserDeletedEvent.php',
'OCP\\User\\Events\\UserFirstTimeLoggedInEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserFirstTimeLoggedInEvent.php',
Expand Down
9 changes: 8 additions & 1 deletion lib/private/Config/UserConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
use OCP\DB\Exception as DBException;
use OCP\DB\IResult;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Security\ICrypto;
use OCP\User\Events\UserConfigChangedEvent;
use Psr\Log\LoggerInterface;

/**
Expand Down Expand Up @@ -75,6 +77,7 @@ public function __construct(
private readonly PresetManager $presetManager,
protected LoggerInterface $logger,
protected ICrypto $crypto,
protected IEventDispatcher $dispatcher,
) {
}

Expand Down Expand Up @@ -1123,12 +1126,14 @@ private function setTypedValue(
}
}

$oldValue = null;
if ($this->hasKey($userId, $app, $key, $lazy)) {
/**
* no update if key is already known with set lazy status and value is
* not different, unless sensitivity is switched from false to true.
*/
if ($origValue === $this->getTypedValue($userId, $app, $key, $value, $lazy, $type)
$oldValue = $this->getTypedValue($userId, $app, $key, $value, $lazy, $type);
if ($origValue === $oldValue
&& (!$sensitive || $this->isSensitive($userId, $app, $key, $lazy))) {
return false;
}
Expand Down Expand Up @@ -1210,6 +1215,8 @@ private function setTypedValue(
$update->executeStatement();
}

$this->dispatcher->dispatchTyped(new UserConfigChangedEvent($userId, $app, $key, $value, $oldValue));

if ($refreshCache) {
$this->clearCache($userId);
return true;
Expand Down
65 changes: 65 additions & 0 deletions lib/public/User/Events/UserConfigChangedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Murena SAS <[email protected]>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCP\User\Events;

use OCP\AppFramework\Attribute\Listenable;
use OCP\EventDispatcher\Event;

/** @since 33.0.0 */
#[Listenable(since: '33.0.0')]
class UserConfigChangedEvent extends Event {
/**
* @since 33.0.0
*/
public function __construct(
private string $userId,
private string $appId,
private string $key,
private mixed $value,
private mixed $oldValue = null,
) {
parent::__construct();
}

/**
* @since 33.0.0
*/
public function getUserId(): string {
return $this->userId;
}

/**
* @since 33.0.0
*/
public function getAppId(): string {
return $this->appId;
}

/**
* @since 33.0.0
*/
public function getKey(): string {
return $this->key;
}

/**
* @since 33.0.0
*/
public function getValue(): mixed {
return $this->value;
}

/**
* @since 33.0.0
*/
public function getOldValue(): mixed {
return $this->oldValue;
}
}
4 changes: 4 additions & 0 deletions tests/lib/Config/UserConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\Config\Exceptions\UnknownKeyException;
use OCP\Config\IUserConfig;
use OCP\Config\ValueType;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\Security\ICrypto;
Expand All @@ -35,6 +36,7 @@ class UserConfigTest extends TestCase {
private PresetManager $presetManager;
private LoggerInterface $logger;
private ICrypto $crypto;
private IEventDispatcher $dispatcher;
private array $originalPreferences;

/**
Expand Down Expand Up @@ -181,6 +183,7 @@ protected function setUp(): void {
$this->presetManager = Server::get(PresetManager::class);
$this->logger = Server::get(LoggerInterface::class);
$this->crypto = Server::get(ICrypto::class);
$this->dispatcher = Server::get(IEventDispatcher::class);

// storing current preferences and emptying the data table
$sql = $this->connection->getQueryBuilder();
Expand Down Expand Up @@ -292,6 +295,7 @@ private function generateUserConfig(array $preLoading = []): IUserConfig {
$this->presetManager,
$this->logger,
$this->crypto,
$this->dispatcher
);
$msg = ' generateUserConfig() failed to confirm cache status';

Expand Down
Loading