mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 06:37:56 -04:00
Merge pull request #42039 from Murena-SAS/dev/user-preference-event
This commit is contained in:
commit
39e2997963
5 changed files with 79 additions and 1 deletions
|
|
@ -981,6 +981,7 @@ return array(
|
|||
'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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -23,9 +23,11 @@ use OCP\Config\ValueType;
|
|||
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 @@ class UserConfig implements IUserConfig {
|
|||
private readonly PresetManager $presetManager,
|
||||
protected LoggerInterface $logger,
|
||||
protected ICrypto $crypto,
|
||||
protected IEventDispatcher $dispatcher,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -1123,12 +1126,14 @@ class UserConfig implements IUserConfig {
|
|||
}
|
||||
}
|
||||
|
||||
$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 @@ class UserConfig implements IUserConfig {
|
|||
$update->executeStatement();
|
||||
}
|
||||
|
||||
$this->dispatcher->dispatchTyped(new UserConfigChangedEvent($userId, $app, $key, $value, $oldValue));
|
||||
|
||||
if ($refreshCache) {
|
||||
$this->clearCache($userId);
|
||||
return true;
|
||||
|
|
|
|||
65
lib/public/User/Events/UserConfigChangedEvent.php
Normal file
65
lib/public/User/Events/UserConfigChangedEvent.php
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Murena SAS <akhil.potukuchi.ext@murena.com>
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ use OCP\Config\Exceptions\TypeConflictException;
|
|||
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 @@ class UserConfigTest extends TestCase {
|
|||
$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 @@ class UserConfigTest extends TestCase {
|
|||
$this->presetManager,
|
||||
$this->logger,
|
||||
$this->crypto,
|
||||
$this->dispatcher
|
||||
);
|
||||
$msg = ' generateUserConfig() failed to confirm cache status';
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue