summaryrefslogtreecommitdiffstats
path: root/lib/private/Group/Group.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2019-02-22 13:07:26 +0100
committerJulius Härtl <jus@bitgrid.net>2019-03-01 20:56:59 +0100
commit01b4db62fbc4230cff953a2385d305b149744b86 (patch)
tree788b5edf5acba069bd6996466ab9b1b30a6804d4 /lib/private/Group/Group.php
parent55ae7fa2a48ce38e2807a40632f282740c0e8117 (diff)
downloadnextcloud-server-01b4db62fbc4230cff953a2385d305b149744b86.tar.gz
nextcloud-server-01b4db62fbc4230cff953a2385d305b149744b86.zip
Add dispatcher events to User and Group objects
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Group/Group.php')
-rw-r--r--lib/private/Group/Group.php66
1 files changed, 40 insertions, 26 deletions
diff --git a/lib/private/Group/Group.php b/lib/private/Group/Group.php
index df8de7af5d5..3876c575968 100644
--- a/lib/private/Group/Group.php
+++ b/lib/private/Group/Group.php
@@ -31,55 +31,50 @@
namespace OC\Group;
use OCP\Group\Backend\IHideFromCollaborationBackend;
+use OC\Hooks\PublicEmitter;
use OCP\GroupInterface;
use OCP\IGroup;
use OCP\IUser;
use OCP\Group\Backend\ICountDisabledInGroup;
+use OCP\IUserManager;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
+use Symfony\Component\EventDispatcher\GenericEvent;
class Group implements IGroup {
/** @var null|string */
protected $displayName;
- /**
- * @var string $id
- */
+ /** @var string */
private $gid;
- /**
- * @var \OC\User\User[] $users
- */
+ /** @var \OC\User\User[] */
private $users = array();
- /**
- * @var bool $usersLoaded
- */
+ /** @var bool */
private $usersLoaded;
- /**
- * @var \OC\Group\Backend[]|\OC\Group\Database[] $backend
- */
+ /** @var Backend[] */
private $backends;
-
- /**
- * @var \OC\Hooks\PublicEmitter $emitter
- */
+ /** @var EventDispatcherInterface */
+ private $dispatcher;
+ /** @var \OC\User\Manager|IUserManager */
+ private $userManager;
+ /** @var PublicEmitter */
private $emitter;
- /**
- * @var \OC\User\Manager $userManager
- */
- private $userManager;
/**
* @param string $gid
- * @param \OC\Group\Backend[] $backends
- * @param \OC\User\Manager $userManager
- * @param \OC\Hooks\PublicEmitter $emitter
+ * @param Backend[] $backends
+ * @param EventDispatcherInterface $dispatcher
+ * @param IUserManager $userManager
+ * @param PublicEmitter $emitter
* @param string $displayName
*/
- public function __construct($gid, $backends, $userManager, $emitter = null, $displayName = null) {
+ public function __construct(string $gid, array $backends, EventDispatcherInterface $dispatcher, IUserManager $userManager, PublicEmitter $emitter = null, ?string $displayName = null) {
$this->gid = $gid;
$this->backends = $backends;
+ $this->dispatcher = $dispatcher;
$this->userManager = $userManager;
$this->emitter = $emitter;
$this->displayName = $displayName;
@@ -151,6 +146,10 @@ class Group implements IGroup {
return;
}
+ $this->dispatcher->dispatch(IGroup::class . '::preAddUser', new GenericEvent($this, [
+ 'user' => $user,
+ ]));
+
if ($this->emitter) {
$this->emitter->emit('\OC\Group', 'preAddUser', array($this, $user));
}
@@ -160,6 +159,11 @@ class Group implements IGroup {
if ($this->users) {
$this->users[$user->getUID()] = $user;
}
+
+ $this->dispatcher->dispatch(IGroup::class . '::postAddUser', new GenericEvent($this, [
+ 'user' => $user,
+ ]));
+
if ($this->emitter) {
$this->emitter->emit('\OC\Group', 'postAddUser', array($this, $user));
}
@@ -175,6 +179,9 @@ class Group implements IGroup {
*/
public function removeUser($user) {
$result = false;
+ $this->dispatcher->dispatch(IGroup::class . '::preRemoveUser', new GenericEvent($this, [
+ 'user' => $user,
+ ]));
if ($this->emitter) {
$this->emitter->emit('\OC\Group', 'preRemoveUser', array($this, $user));
}
@@ -185,6 +192,9 @@ class Group implements IGroup {
}
}
if ($result) {
+ $this->dispatcher->dispatch(IGroup::class . '::postRemoveUser', new GenericEvent($this, [
+ 'user' => $user,
+ ]));
if ($this->emitter) {
$this->emitter->emit('\OC\Group', 'postRemoveUser', array($this, $user));
}
@@ -292,6 +302,7 @@ class Group implements IGroup {
}
$result = false;
+ $this->dispatcher->dispatch(IGroup::class . '::preDelete', new GenericEvent($this));
if ($this->emitter) {
$this->emitter->emit('\OC\Group', 'preDelete', array($this));
}
@@ -301,8 +312,11 @@ class Group implements IGroup {
$backend->deleteGroup($this->gid);
}
}
- if ($result and $this->emitter) {
- $this->emitter->emit('\OC\Group', 'postDelete', array($this));
+ if ($result) {
+ $this->dispatcher->dispatch(IGroup::class . '::postDelete', new GenericEvent($this));
+ if ($this->emitter) {
+ $this->emitter->emit('\OC\Group', 'postDelete', array($this));
+ }
}
return $result;
}