Skip to content

Commit

Permalink
feat(config): Add UserConfigChangedEvent whenever user config is updated
Browse files Browse the repository at this point in the history
Signed-off-by: Akhil <akhil@e.email>
  • Loading branch information
akhil1508 committed Sep 16, 2024
1 parent ff0cab5 commit b040664
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 5 additions & 4 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
);

public static $prefixLengthsPsr4 = array (
'O' =>
'O' =>
array (
'OC\\Core\\' => 8,
'OC\\' => 3,
Expand All @@ -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',
),
Expand Down Expand Up @@ -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',
Expand Down
11 changes: 11 additions & 0 deletions lib/private/AllConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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));
}
}

/**
Expand Down
98 changes: 98 additions & 0 deletions lib/public/User/Events/UserConfigChangedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2023 Murena SAS <akhil.potukuchi.ext@murena.com>
*
* @author Murena SAS <akhil.potukuchi.ext@murena.com>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/

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;
}
}

0 comments on commit b040664

Please sign in to comment.