summaryrefslogtreecommitdiffstats
path: root/lib/private/Group
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
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')
-rw-r--r--lib/private/Group/Group.php66
-rw-r--r--lib/private/Group/Manager.php63
2 files changed, 71 insertions, 58 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;
}
diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php
index f1bb6357d0a..7567f719b0a 100644
--- a/lib/private/Group/Manager.php
+++ b/lib/private/Group/Manager.php
@@ -44,6 +44,7 @@ use OCP\IGroup;
use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUser;
+use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
* Class Manager
@@ -61,39 +62,37 @@ use OCP\IUser;
* @package OC\Group
*/
class Manager extends PublicEmitter implements IGroupManager {
- /**
- * @var GroupInterface[] $backends
- */
- private $backends = array();
+ /** @var GroupInterface[] */
+ private $backends = [];
- /**
- * @var \OC\User\Manager $userManager
- */
+ /** @var \OC\User\Manager */
private $userManager;
+ /** @var EventDispatcherInterface */
+ private $dispatcher;
+ /** @var ILogger */
+ private $logger;
- /**
- * @var \OC\Group\Group[]
- */
- private $cachedGroups = array();
+ /** @var \OC\Group\Group[] */
+ private $cachedGroups = [];
- /**
- * @var \OC\Group\Group[]
- */
- private $cachedUserGroups = array();
+ /** @var \OC\Group\Group[] */
+ private $cachedUserGroups = [];
/** @var \OC\SubAdmin */
private $subAdmin = null;
- /** @var ILogger */
- private $logger;
-
/**
* @param \OC\User\Manager $userManager
+ * @param EventDispatcherInterface $dispatcher
* @param ILogger $logger
*/
- public function __construct(\OC\User\Manager $userManager, ILogger $logger) {
+ public function __construct(\OC\User\Manager $userManager,
+ EventDispatcherInterface $dispatcher,
+ ILogger $logger) {
$this->userManager = $userManager;
+ $this->dispatcher = $dispatcher;
$this->logger = $logger;
+
$cachedGroups = & $this->cachedGroups;
$cachedUserGroups = & $this->cachedUserGroups;
$this->listen('\OC\Group', 'postDelete', function ($group) use (&$cachedGroups, &$cachedUserGroups) {
@@ -101,19 +100,19 @@ class Manager extends PublicEmitter implements IGroupManager {
* @var \OC\Group\Group $group
*/
unset($cachedGroups[$group->getGID()]);
- $cachedUserGroups = array();
+ $cachedUserGroups = [];
});
$this->listen('\OC\Group', 'postAddUser', function ($group) use (&$cachedUserGroups) {
/**
* @var \OC\Group\Group $group
*/
- $cachedUserGroups = array();
+ $cachedUserGroups = [];
});
$this->listen('\OC\Group', 'postRemoveUser', function ($group) use (&$cachedUserGroups) {
/**
* @var \OC\Group\Group $group
*/
- $cachedUserGroups = array();
+ $cachedUserGroups = [];
});
}
@@ -144,7 +143,7 @@ class Manager extends PublicEmitter implements IGroupManager {
}
public function clearBackends() {
- $this->backends = array();
+ $this->backends = [];
$this->clearCaches();
}
@@ -158,8 +157,8 @@ class Manager extends PublicEmitter implements IGroupManager {
protected function clearCaches() {
- $this->cachedGroups = array();
- $this->cachedUserGroups = array();
+ $this->cachedGroups = [];
+ $this->cachedUserGroups = [];
}
/**
@@ -179,7 +178,7 @@ class Manager extends PublicEmitter implements IGroupManager {
* @return \OCP\IGroup
*/
protected function getGroupObject($gid, $displayName = null) {
- $backends = array();
+ $backends = [];
foreach ($this->backends as $backend) {
if ($backend->implementsActions(\OC\Group\Backend::GROUP_DETAILS)) {
$groupData = $backend->getGroupDetails($gid);
@@ -197,7 +196,7 @@ class Manager extends PublicEmitter implements IGroupManager {
if (count($backends) === 0) {
return null;
}
- $this->cachedGroups[$gid] = new Group($gid, $backends, $this->userManager, $this, $displayName);
+ $this->cachedGroups[$gid] = new Group($gid, $backends, $this->dispatcher, $this->userManager, $this, $displayName);
return $this->cachedGroups[$gid];
}
@@ -239,7 +238,7 @@ class Manager extends PublicEmitter implements IGroupManager {
* @return \OC\Group\Group[]
*/
public function search($search, $limit = null, $offset = null) {
- $groups = array();
+ $groups = [];
foreach ($this->backends as $backend) {
$groupIds = $backend->getGroups($search, $limit, $offset);
foreach ($groupIds as $groupId) {
@@ -276,7 +275,7 @@ class Manager extends PublicEmitter implements IGroupManager {
if (isset($this->cachedUserGroups[$uid])) {
return $this->cachedUserGroups[$uid];
}
- $groups = array();
+ $groups = [];
foreach ($this->backends as $backend) {
$groupIds = $backend->getUserGroups($uid);
if (is_array($groupIds)) {
@@ -351,11 +350,11 @@ class Manager extends PublicEmitter implements IGroupManager {
public function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$group = $this->get($gid);
if(is_null($group)) {
- return array();
+ return [];
}
$search = trim($search);
- $groupUsers = array();
+ $groupUsers = [];
if(!empty($search)) {
// only user backends have the capability to do a complex search for users
@@ -384,7 +383,7 @@ class Manager extends PublicEmitter implements IGroupManager {
$groupUsers = $group->searchUsers('', $limit, $offset);
}
- $matchingUsers = array();
+ $matchingUsers = [];
foreach($groupUsers as $groupUser) {
$matchingUsers[$groupUser->getUID()] = $groupUser->getDisplayName();
}