Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Remove symfony EventDispatcherInterface from OC\User and OC\Group #39595

Merged
merged 3 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
use OC\User\User;
use OCA\Files_External\Controller\GlobalStoragesController;
use OCA\Files_External\Service\BackendService;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class GlobalStoragesControllerTest extends StoragesControllerTest {
protected function setUp(): void {
Expand All @@ -53,7 +53,7 @@ protected function setUp(): void {
private function createController($allowCreateLocal = true) {
$session = $this->createMock(IUserSession::class);
$session->method('getUser')
->willReturn(new User('test', null, $this->createMock(EventDispatcherInterface::class)));
->willReturn(new User('test', null, $this->createMock(IEventDispatcher::class)));

$config = $this->createMock(IConfig::class);
$config->method('getSystemValue')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\BackendService;
use OCP\AppFramework\Http;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class UserStoragesControllerTest extends StoragesControllerTest {

Expand All @@ -61,7 +61,7 @@ protected function setUp(): void {
private function createController($allowCreateLocal = true) {
$session = $this->createMock(IUserSession::class);
$session->method('getUser')
->willReturn(new User('test', null, $this->createMock(EventDispatcherInterface::class)));
->willReturn(new User('test', null, $this->createMock(IEventDispatcher::class)));

$config = $this->createMock(IConfig::class);
$config->method('getSystemValue')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\StoragesService;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserSession;
Expand Down Expand Up @@ -66,7 +67,7 @@ protected function setUp(): void {

$this->globalStoragesService = $this->service;

$this->user = new \OC\User\User(self::USER_ID, null, \OC::$server->getEventDispatcher());
$this->user = new \OC\User\User(self::USER_ID, null, \OC::$server->get(IEventDispatcher::class));
/** @var \OCP\IUserSession|\PHPUnit\Framework\MockObject\MockObject $userSession */
$userSession = $this->createMock(IUserSession::class);
$userSession
Expand Down
2 changes: 0 additions & 2 deletions apps/user_ldap/tests/LDAPProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use OCP\ICacheFactory;
use OCP\IConfig;
use OCP\IServerContainer;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Class LDAPProviderTest
Expand Down Expand Up @@ -76,7 +75,6 @@ private function getUserManagerMock(IUserLDAP $userBackend) {
->setMethods(['getBackends'])
->setConstructorArgs([
$this->createMock(IConfig::class),
$this->createMock(EventDispatcherInterface::class),
$this->createMock(ICacheFactory::class),
$this->createMock(IEventDispatcher::class),
])
Expand Down
6 changes: 3 additions & 3 deletions lib/private/Collaboration/Resources/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IGroup;
use OCP\IUser;
use OCP\User\Events\UserDeletedEvent;
use Symfony\Component\EventDispatcher\GenericEvent;

class Listener {
Expand All @@ -47,9 +48,8 @@ public static function register(SymfonyAdapter $symfonyDispatcher, IEventDispatc
$symfonyDispatcher->addListener(IGroup::class . '::postAddUser', $listener);
$symfonyDispatcher->addListener(IGroup::class . '::postRemoveUser', $listener);

$symfonyDispatcher->addListener(IUser::class . '::postDelete', function (GenericEvent $event) {
/** @var IUser $user */
$user = $event->getSubject();
$eventDispatcher->addListener(UserDeletedEvent::class, function (UserDeletedEvent $event) {
$user = $event->getUser();
/** @var IManager $resourceManager */
$resourceManager = \OCP\Server::get(IManager::class);

Expand Down
46 changes: 17 additions & 29 deletions lib/private/Group/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@

use OC\Hooks\PublicEmitter;
use OC\User\LazyUser;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\BeforeGroupDeletedEvent;
use OCP\Group\Events\BeforeUserAddedEvent;
use OCP\Group\Events\BeforeUserRemovedEvent;
use OCP\Group\Events\GroupDeletedEvent;
use OCP\Group\Events\UserAddedEvent;
use OCP\Group\Events\UserRemovedEvent;
use OCP\GroupInterface;
use OCP\Group\Backend\ICountDisabledInGroup;
use OCP\Group\Backend\IGetDisplayNameBackend;
Expand All @@ -46,8 +53,6 @@
use OCP\IGroup;
use OCP\IUser;
use OCP\IUserManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

class Group implements IGroup {
/** @var null|string */
Expand All @@ -64,23 +69,14 @@ class Group implements IGroup {

/** @var Backend[] */
private $backends;
/** @var EventDispatcherInterface */
/** @var IEventDispatcher */
private $dispatcher;
/** @var \OC\User\Manager|IUserManager */
private $userManager;
/** @var PublicEmitter */
private $emitter;


/**
* @param string $gid
* @param Backend[] $backends
* @param EventDispatcherInterface $dispatcher
* @param IUserManager $userManager
* @param PublicEmitter $emitter
* @param string $displayName
*/
public function __construct(string $gid, array $backends, EventDispatcherInterface $dispatcher, IUserManager $userManager, PublicEmitter $emitter = null, ?string $displayName = null) {
public function __construct(string $gid, array $backends, IEventDispatcher $dispatcher, IUserManager $userManager, PublicEmitter $emitter = null, ?string $displayName = null) {
$this->gid = $gid;
$this->backends = $backends;
$this->dispatcher = $dispatcher;
Expand Down Expand Up @@ -112,12 +108,12 @@ public function getDisplayName() {
public function setDisplayName(string $displayName): bool {
$displayName = trim($displayName);
if ($displayName !== '') {
$this->dispatcher->dispatch(new BeforeGroupChangedEvent($this, 'displayName', $displayName, $this->displayName));
$this->dispatcher->dispatchTyped(new BeforeGroupChangedEvent($this, 'displayName', $displayName, $this->displayName));
foreach ($this->backends as $backend) {
if (($backend instanceof ISetDisplayNameBackend)
&& $backend->setDisplayName($this->gid, $displayName)) {
$this->displayName = $displayName;
$this->dispatcher->dispatch(new GroupChangedEvent($this, 'displayName', $displayName, ''));
$this->dispatcher->dispatchTyped(new GroupChangedEvent($this, 'displayName', $displayName, ''));
return true;
}
}
Expand Down Expand Up @@ -180,9 +176,7 @@ public function addUser(IUser $user) {
return;
}

$this->dispatcher->dispatch(IGroup::class . '::preAddUser', new GenericEvent($this, [
'user' => $user,
]));
$this->dispatcher->dispatchTyped(new BeforeUserAddedEvent($this, $user));

if ($this->emitter) {
$this->emitter->emit('\OC\Group', 'preAddUser', [$this, $user]);
Expand All @@ -194,9 +188,7 @@ public function addUser(IUser $user) {
$this->users[$user->getUID()] = $user;
}

$this->dispatcher->dispatch(IGroup::class . '::postAddUser', new GenericEvent($this, [
'user' => $user,
]));
$this->dispatcher->dispatchTyped(new UserAddedEvent($this, $user));

if ($this->emitter) {
$this->emitter->emit('\OC\Group', 'postAddUser', [$this, $user]);
Expand All @@ -213,9 +205,7 @@ public function addUser(IUser $user) {
*/
public function removeUser($user) {
$result = false;
$this->dispatcher->dispatch(IGroup::class . '::preRemoveUser', new GenericEvent($this, [
'user' => $user,
]));
$this->dispatcher->dispatchTyped(new BeforeUserRemovedEvent($this, $user));
if ($this->emitter) {
$this->emitter->emit('\OC\Group', 'preRemoveUser', [$this, $user]);
}
Expand All @@ -226,9 +216,7 @@ public function removeUser($user) {
}
}
if ($result) {
$this->dispatcher->dispatch(IGroup::class . '::postRemoveUser', new GenericEvent($this, [
'user' => $user,
]));
$this->dispatcher->dispatchTyped(new UserRemovedEvent($this, $user));
if ($this->emitter) {
$this->emitter->emit('\OC\Group', 'postRemoveUser', [$this, $user]);
}
Expand Down Expand Up @@ -352,7 +340,7 @@ public function delete() {
}

$result = false;
$this->dispatcher->dispatch(IGroup::class . '::preDelete', new GenericEvent($this));
$this->dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($this));
if ($this->emitter) {
$this->emitter->emit('\OC\Group', 'preDelete', [$this]);
}
Expand All @@ -362,7 +350,7 @@ public function delete() {
}
}
if ($result) {
$this->dispatcher->dispatch(IGroup::class . '::postDelete', new GenericEvent($this));
$this->dispatcher->dispatchTyped(new GroupDeletedEvent($this));
if ($this->emitter) {
$this->emitter->emit('\OC\Group', 'postDelete', [$this]);
}
Expand Down
12 changes: 7 additions & 5 deletions lib/private/Group/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@

use OC\Hooks\PublicEmitter;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Group\Events\BeforeGroupCreatedEvent;
use OCP\Group\Events\GroupCreatedEvent;
use OCP\GroupInterface;
use OCP\ICacheFactory;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Class Manager
Expand All @@ -70,8 +71,7 @@ class Manager extends PublicEmitter implements IGroupManager {

/** @var \OC\User\Manager */
private $userManager;
/** @var EventDispatcherInterface */
private $dispatcher;
private IEventDispatcher $dispatcher;
private LoggerInterface $logger;

/** @var \OC\Group\Group[] */
Expand All @@ -86,7 +86,7 @@ class Manager extends PublicEmitter implements IGroupManager {
private DisplayNameCache $displayNameCache;

public function __construct(\OC\User\Manager $userManager,
EventDispatcherInterface $dispatcher,
IEventDispatcher $dispatcher,
LoggerInterface $logger,
ICacheFactory $cacheFactory) {
$this->userManager = $userManager;
Expand Down Expand Up @@ -220,11 +220,13 @@ public function createGroup($gid) {
} elseif ($group = $this->get($gid)) {
return $group;
} else {
$this->dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
$this->emit('\OC\Group', 'preCreate', [$gid]);
foreach ($this->backends as $backend) {
if ($backend->implementsActions(Backend::CREATE_GROUP)) {
if ($backend->createGroup($gid)) {
$group = $this->getGroupObject($gid);
$this->dispatcher->dispatchTyped(new GroupCreatedEvent($group));
$this->emit('\OC\Group', 'postCreate', [$group]);
return $group;
}
Expand Down Expand Up @@ -424,7 +426,7 @@ public function getSubAdmin() {
$this->userManager,
$this,
\OC::$server->getDatabaseConnection(),
\OC::$server->get(IEventDispatcher::class)
$this->dispatcher
);
}

Expand Down
Loading
Loading