diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 8bc0887be64fb..4cbade8e68e3b 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -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', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 631b7664b6643..79f4c88358f00 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -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', diff --git a/lib/private/Config/UserConfig.php b/lib/private/Config/UserConfig.php index 05018adc3f8fe..f7d135c134d7b 100644 --- a/lib/private/Config/UserConfig.php +++ b/lib/private/Config/UserConfig.php @@ -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; /** @@ -75,6 +77,7 @@ public function __construct( private readonly PresetManager $presetManager, protected LoggerInterface $logger, protected ICrypto $crypto, + protected IEventDispatcher $dispatcher, ) { } @@ -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; } @@ -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; diff --git a/lib/public/User/Events/UserConfigChangedEvent.php b/lib/public/User/Events/UserConfigChangedEvent.php new file mode 100644 index 0000000000000..27b10cdba35de --- /dev/null +++ b/lib/public/User/Events/UserConfigChangedEvent.php @@ -0,0 +1,65 @@ + + * 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; + } +} diff --git a/tests/lib/Config/UserConfigTest.php b/tests/lib/Config/UserConfigTest.php index 9dd5ab1008484..d570bf020f16b 100644 --- a/tests/lib/Config/UserConfigTest.php +++ b/tests/lib/Config/UserConfigTest.php @@ -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; @@ -35,6 +36,7 @@ class UserConfigTest extends TestCase { private PresetManager $presetManager; private LoggerInterface $logger; private ICrypto $crypto; + private IEventDispatcher $dispatcher; private array $originalPreferences; /** @@ -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(); @@ -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';