Skip to content

Commit 037ad05

Browse files
committed
feat(config): Add UserConfigChangedEvent whenever user config is updated
Signed-off-by: Akhil <akhil@e.email>
1 parent ff0cab5 commit 037ad05

4 files changed

Lines changed: 86 additions & 4 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@
875875
'OCP\\User\\Events\\UserLoggedInEvent' => $baseDir . '/lib/public/User/Events/UserLoggedInEvent.php',
876876
'OCP\\User\\Events\\UserLoggedInWithCookieEvent' => $baseDir . '/lib/public/User/Events/UserLoggedInWithCookieEvent.php',
877877
'OCP\\User\\Events\\UserLoggedOutEvent' => $baseDir . '/lib/public/User/Events/UserLoggedOutEvent.php',
878+
'OCP\\User\\Events\\UserConfigChangedEvent' => $baseDir . '/lib/public/User/Events/UserConfigChangedEvent.php',
878879
'OCP\\User\\GetQuotaEvent' => $baseDir . '/lib/public/User/GetQuotaEvent.php',
879880
'OCP\\User\\IAvailabilityCoordinator' => $baseDir . '/lib/public/User/IAvailabilityCoordinator.php',
880881
'OCP\\User\\IOutOfOfficeData' => $baseDir . '/lib/public/User/IOutOfOfficeData.php',

lib/composer/composer/autoload_static.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
1111
);
1212

1313
public static $prefixLengthsPsr4 = array (
14-
'O' =>
14+
'O' =>
1515
array (
1616
'OC\\Core\\' => 8,
1717
'OC\\' => 3,
@@ -20,15 +20,15 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
2020
);
2121

2222
public static $prefixDirsPsr4 = array (
23-
'OC\\Core\\' =>
23+
'OC\\Core\\' =>
2424
array (
2525
0 => __DIR__ . '/../../..' . '/core',
2626
),
27-
'OC\\' =>
27+
'OC\\' =>
2828
array (
2929
0 => __DIR__ . '/../../..' . '/lib/private',
3030
),
31-
'OCP\\' =>
31+
'OCP\\' =>
3232
array (
3333
0 => __DIR__ . '/../../..' . '/lib/public',
3434
),
@@ -899,6 +899,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
899899
'OCP\\User\\Events\\PasswordUpdatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/PasswordUpdatedEvent.php',
900900
'OCP\\User\\Events\\PostLoginEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/PostLoginEvent.php',
901901
'OCP\\User\\Events\\UserChangedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserChangedEvent.php',
902+
'OCP\\User\\Events\\UserConfigChangedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserConfigChangedEvent.php',
902903
'OCP\\User\\Events\\UserCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserCreatedEvent.php',
903904
'OCP\\User\\Events\\UserDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserDeletedEvent.php',
904905
'OCP\\User\\Events\\UserFirstTimeLoggedInEvent' => __DIR__ . '/../../..' . '/lib/public/User/Events/UserFirstTimeLoggedInEvent.php',

lib/private/AllConfig.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use OCP\IConfig;
1212
use OCP\IDBConnection;
1313
use OCP\PreConditionNotMetException;
14+
use OCP\EventDispatcher\IEventDispatcher;
15+
use OCP\User\Events\UserConfigChangedEvent;
1416

1517
/**
1618
* Class to combine all the configuration options ownCloud offers
@@ -256,6 +258,7 @@ public function setUserValue($userId, $appName, $key, $value, $preCondition = nu
256258
$qb->executeStatement();
257259

258260
$this->userCache[$userId][$appName][$key] = (string)$value;
261+
$this->triggerUserValueChange($userId, $appName, $key, $value, $prevValue);
259262
return;
260263
}
261264
}
@@ -282,6 +285,14 @@ public function setUserValue($userId, $appName, $key, $value, $preCondition = nu
282285
}
283286
$this->userCache[$userId][$appName][$key] = (string)$value;
284287
}
288+
$this->triggerUserValueChange($userId, $appName, $key, $value, $prevValue);
289+
}
290+
291+
private function triggerUserValueChange($userId, $appId, $key, $value, $oldValue = null) {
292+
if (\OC::$server instanceof \OCP\IServerContainer) {
293+
$dispatcher = \OC::$server->get(IEventDispatcher::class);
294+
$dispatcher->dispatchTyped(new UserConfigChangedEvent($userId, $appId, $key, $value, $oldValue));
295+
}
285296
}
286297

287298
/**
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2023 Murena SAS <akhil.potukuchi.ext@murena.com>
7+
*
8+
* @author Murena SAS <akhil.potukuchi.ext@murena.com>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OCP\User\Events;
28+
29+
use OCP\EventDispatcher\Event;
30+
31+
class UserConfigChangedEvent extends Event {
32+
private string $userId;
33+
private string $appId;
34+
private string $key;
35+
private mixed $value;
36+
private mixed $oldValue;
37+
38+
public function __construct(string $userId,
39+
string $appId,
40+
string $key,
41+
mixed $value,
42+
mixed $oldValue = null) {
43+
parent::__construct();
44+
$this->userId = $userId;
45+
$this->appId = $appId;
46+
$this->key = $key;
47+
$this->value = $value;
48+
$this->oldValue = $oldValue;
49+
}
50+
51+
public function getUserId(): string {
52+
return $this->userId;
53+
}
54+
55+
public function getAppId(): string {
56+
return $this->appId;
57+
}
58+
public function getKey(): string {
59+
return $this->key;
60+
}
61+
62+
public function getValue() {
63+
return $this->value;
64+
}
65+
66+
public function getOldValue() {
67+
return $this->oldValue;
68+
}
69+
}

0 commit comments

Comments
 (0)