From b04066494645a2cefdd7d239a8ea585a9c87bb52 Mon Sep 17 00:00:00 2001 From: Akhil Date: Tue, 5 Dec 2023 21:27:50 +0530 Subject: [PATCH] feat(config): Add UserConfigChangedEvent whenever user config is updated Signed-off-by: Akhil --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 9 +- lib/private/AllConfig.php | 11 +++ .../User/Events/UserConfigChangedEvent.php | 98 +++++++++++++++++++ 4 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 lib/public/User/Events/UserConfigChangedEvent.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 37013ecc1aecd..06de0ba358bbc 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -875,6 +875,7 @@ 'OCP\\User\\Events\\UserLoggedInEvent' => $baseDir . '/lib/public/User/Events/UserLoggedInEvent.php', 'OCP\\User\\Events\\UserLoggedInWithCookieEvent' => $baseDir . '/lib/public/User/Events/UserLoggedInWithCookieEvent.php', 'OCP\\User\\Events\\UserLoggedOutEvent' => $baseDir . '/lib/public/User/Events/UserLoggedOutEvent.php', + 'OCP\\User\\Events\\UserConfigChangedEvent' => $baseDir . '/lib/public/User/Events/UserConfigChangedEvent.php', 'OCP\\User\\GetQuotaEvent' => $baseDir . '/lib/public/User/GetQuotaEvent.php', 'OCP\\User\\IAvailabilityCoordinator' => $baseDir . '/lib/public/User/IAvailabilityCoordinator.php', 'OCP\\User\\IOutOfOfficeData' => $baseDir . '/lib/public/User/IOutOfOfficeData.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 293e79f80c64d..9d9540427011b 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -11,7 +11,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 ); public static $prefixLengthsPsr4 = array ( - 'O' => + 'O' => array ( 'OC\\Core\\' => 8, 'OC\\' => 3, @@ -20,15 +20,15 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 ); public static $prefixDirsPsr4 = array ( - 'OC\\Core\\' => + 'OC\\Core\\' => array ( 0 => __DIR__ . '/../../..' . '/core', ), - 'OC\\' => + 'OC\\' => array ( 0 => __DIR__ . '/../../..' . '/lib/private', ), - 'OCP\\' => + 'OCP\\' => array ( 0 => __DIR__ . '/../../..' . '/lib/public', ), @@ -899,6 +899,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/AllConfig.php b/lib/private/AllConfig.php index f08e5125a478f..100fbf391b0f1 100644 --- a/lib/private/AllConfig.php +++ b/lib/private/AllConfig.php @@ -11,6 +11,8 @@ use OCP\IConfig; use OCP\IDBConnection; use OCP\PreConditionNotMetException; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\User\Events\UserConfigChangedEvent; /** * Class to combine all the configuration options ownCloud offers @@ -256,6 +258,7 @@ public function setUserValue($userId, $appName, $key, $value, $preCondition = nu $qb->executeStatement(); $this->userCache[$userId][$appName][$key] = (string)$value; + $this->triggerUserValueChange($userId, $appName, $key, $value, $prevValue); return; } } @@ -282,6 +285,14 @@ public function setUserValue($userId, $appName, $key, $value, $preCondition = nu } $this->userCache[$userId][$appName][$key] = (string)$value; } + $this->triggerUserValueChange($userId, $appName, $key, $value, $prevValue); + } + + private function triggerUserValueChange($userId, $appId, $key, $value, $oldValue = null) { + if (\OC::$server instanceof \OCP\IServerContainer) { + $dispatcher = \OC::$server->get(IEventDispatcher::class); + $dispatcher->dispatchTyped(new UserConfigChangedEvent($userId, $appId, $key, $value, $oldValue)); + } } /** diff --git a/lib/public/User/Events/UserConfigChangedEvent.php b/lib/public/User/Events/UserConfigChangedEvent.php new file mode 100644 index 0000000000000..7a07f8b49e8b5 --- /dev/null +++ b/lib/public/User/Events/UserConfigChangedEvent.php @@ -0,0 +1,98 @@ + + * + * @author Murena SAS + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\User\Events; + +use OCP\EventDispatcher\Event; + +/** + * @since 30.0.0 + */ + +class UserConfigChangedEvent extends Event { + private string $userId; + private string $appId; + private string $key; + private mixed $value; + private mixed $oldValue; + + /** + * @since 30.0.0 + */ + + public function __construct(string $userId, + string $appId, + string $key, + mixed $value, + mixed $oldValue = null) { + parent::__construct(); + $this->userId = $userId; + $this->appId = $appId; + $this->key = $key; + $this->value = $value; + $this->oldValue = $oldValue; + } + + /** + * @return string + * @since 30.0.0 + */ + public function getUserId(): string { + return $this->userId; + } + + /** + * @return string + * @since 30.0.0 + */ + public function getAppId(): string { + return $this->appId; + } + + /** + * @return string + * @since 30.0.0 + */ + public function getKey(): string { + return $this->key; + } + + /** + * @return mixed + * @since 30.0.0 + */ + public function getValue() { + return $this->value; + } + + /** + * @return mixed + * @since 30.0.0 + */ + public function getOldValue() { + return $this->oldValue; + } +}