summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-10-28 21:53:04 +0100
committerMorris Jobke <hey@morrisjobke.de>2020-10-28 21:55:08 +0100
commite4f53ff91b985123b171dc23db8246c017af46f6 (patch)
tree0fa3b0ab3bc4cfda9c1c555b4085ef47b0b3549a /lib
parentef382f541c42f719b8dd30a4e0e248ef1bc39c84 (diff)
downloadnextcloud-server-e4f53ff91b985123b171dc23db8246c017af46f6.tar.gz
nextcloud-server-e4f53ff91b985123b171dc23db8246c017af46f6.zip
Add typed events for adding and removing a subadmin
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php2
-rw-r--r--lib/composer/composer/autoload_static.php2
-rw-r--r--lib/private/Group/Manager.php4
-rw-r--r--lib/private/SubAdmin.php18
-rw-r--r--lib/public/Group/Events/SubAdminAddedEvent.php67
-rw-r--r--lib/public/Group/Events/SubAdminRemovedEvent.php67
6 files changed, 156 insertions, 4 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index b3080a117dc..f5945a5eb08 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -347,6 +347,8 @@ return array(
'OCP\\Group\\Events\\BeforeUserRemovedEvent' => $baseDir . '/lib/public/Group/Events/BeforeUserRemovedEvent.php',
'OCP\\Group\\Events\\GroupCreatedEvent' => $baseDir . '/lib/public/Group/Events/GroupCreatedEvent.php',
'OCP\\Group\\Events\\GroupDeletedEvent' => $baseDir . '/lib/public/Group/Events/GroupDeletedEvent.php',
+ 'OCP\\Group\\Events\\SubAdminAddedEvent' => $baseDir . '/lib/public/Group/Events/SubAdminAddedEvent.php',
+ 'OCP\\Group\\Events\\SubAdminRemovedEvent' => $baseDir . '/lib/public/Group/Events/SubAdminRemovedEvent.php',
'OCP\\Group\\Events\\UserAddedEvent' => $baseDir . '/lib/public/Group/Events/UserAddedEvent.php',
'OCP\\Group\\Events\\UserRemovedEvent' => $baseDir . '/lib/public/Group/Events/UserRemovedEvent.php',
'OCP\\Group\\ISubAdmin' => $baseDir . '/lib/public/Group/ISubAdmin.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 02698a4f6e2..7663c43d283 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -376,6 +376,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OCP\\Group\\Events\\BeforeUserRemovedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/BeforeUserRemovedEvent.php',
'OCP\\Group\\Events\\GroupCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/GroupCreatedEvent.php',
'OCP\\Group\\Events\\GroupDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/GroupDeletedEvent.php',
+ 'OCP\\Group\\Events\\SubAdminAddedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/SubAdminAddedEvent.php',
+ 'OCP\\Group\\Events\\SubAdminRemovedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/SubAdminRemovedEvent.php',
'OCP\\Group\\Events\\UserAddedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/UserAddedEvent.php',
'OCP\\Group\\Events\\UserRemovedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/UserRemovedEvent.php',
'OCP\\Group\\ISubAdmin' => __DIR__ . '/../../..' . '/lib/public/Group/ISubAdmin.php',
diff --git a/lib/private/Group/Manager.php b/lib/private/Group/Manager.php
index 6056bcdb3e3..3d7c1ff176f 100644
--- a/lib/private/Group/Manager.php
+++ b/lib/private/Group/Manager.php
@@ -41,6 +41,7 @@
namespace OC\Group;
use OC\Hooks\PublicEmitter;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\GroupInterface;
use OCP\IGroup;
use OCP\IGroupManager;
@@ -416,7 +417,8 @@ class Manager extends PublicEmitter implements IGroupManager {
$this->subAdmin = new \OC\SubAdmin(
$this->userManager,
$this,
- \OC::$server->getDatabaseConnection()
+ \OC::$server->getDatabaseConnection(),
+ \OC::$server->get(IEventDispatcher::class)
);
}
diff --git a/lib/private/SubAdmin.php b/lib/private/SubAdmin.php
index a9e3855639c..3239fb27af8 100644
--- a/lib/private/SubAdmin.php
+++ b/lib/private/SubAdmin.php
@@ -32,6 +32,9 @@
namespace OC;
use OC\Hooks\PublicEmitter;
+use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Group\Events\SubAdminAddedEvent;
+use OCP\Group\Events\SubAdminRemovedEvent;
use OCP\Group\ISubAdmin;
use OCP\IDBConnection;
use OCP\IGroup;
@@ -50,6 +53,9 @@ class SubAdmin extends PublicEmitter implements ISubAdmin {
/** @var IDBConnection */
private $dbConn;
+ /** @var IEventDispatcher */
+ private $eventDispatcher;
+
/**
* @param IUserManager $userManager
* @param IGroupManager $groupManager
@@ -57,10 +63,12 @@ class SubAdmin extends PublicEmitter implements ISubAdmin {
*/
public function __construct(IUserManager $userManager,
IGroupManager $groupManager,
- IDBConnection $dbConn) {
+ IDBConnection $dbConn,
+ IEventDispatcher $eventDispatcher) {
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->dbConn = $dbConn;
+ $this->eventDispatcher = $eventDispatcher;
$this->userManager->listen('\OC\User', 'postDelete', function ($user) {
$this->post_deleteUser($user);
@@ -85,8 +93,10 @@ class SubAdmin extends PublicEmitter implements ISubAdmin {
])
->execute();
+ /** @depreacted 21.0.0 - use type SubAdminAddedEvent instead */
$this->emit('\OC\SubAdmin', 'postCreateSubAdmin', [$user, $group]);
- \OC_Hook::emit("OC_SubAdmin", "post_createSubAdmin", ["gid" => $group->getGID()]);
+ $event = new SubAdminAddedEvent($group, $user);
+ $this->eventDispatcher->dispatchTyped($event);
}
/**
@@ -102,8 +112,10 @@ class SubAdmin extends PublicEmitter implements ISubAdmin {
->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
->execute();
+ /** @depreacted 21.0.0 - use type SubAdminRemovedEvent instead */
$this->emit('\OC\SubAdmin', 'postDeleteSubAdmin', [$user, $group]);
- \OC_Hook::emit("OC_SubAdmin", "post_deleteSubAdmin", ["gid" => $group->getGID()]);
+ $event = new SubAdminRemovedEvent($group, $user);
+ $this->eventDispatcher->dispatchTyped($event);
}
/**
diff --git a/lib/public/Group/Events/SubAdminAddedEvent.php b/lib/public/Group/Events/SubAdminAddedEvent.php
new file mode 100644
index 00000000000..d73e691bbf0
--- /dev/null
+++ b/lib/public/Group/Events/SubAdminAddedEvent.php
@@ -0,0 +1,67 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @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\Group\Events;
+
+use OCP\EventDispatcher\Event;
+use OCP\IGroup;
+use OCP\IUser;
+
+/**
+ * @since 21.0.0
+ */
+class SubAdminAddedEvent extends Event {
+
+ /** @var IGroup */
+ private $group;
+
+ /*** @var IUser */
+ private $user;
+
+ /**
+ * @since 21.0.0
+ */
+ public function __construct(IGroup $group, IUser $user) {
+ parent::__construct();
+ $this->group = $group;
+ $this->user = $user;
+ }
+
+ /**
+ * @since 21.0.0
+ */
+ public function getGroup(): IGroup {
+ return $this->group;
+ }
+
+ /**
+ * @since 21.0.0
+ */
+ public function getUser(): IUser {
+ return $this->user;
+ }
+}
diff --git a/lib/public/Group/Events/SubAdminRemovedEvent.php b/lib/public/Group/Events/SubAdminRemovedEvent.php
new file mode 100644
index 00000000000..74f88bd8a3c
--- /dev/null
+++ b/lib/public/Group/Events/SubAdminRemovedEvent.php
@@ -0,0 +1,67 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author Christoph Wurst <christoph@winzerhof-wurst.at>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @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\Group\Events;
+
+use OCP\EventDispatcher\Event;
+use OCP\IGroup;
+use OCP\IUser;
+
+/**
+ * @since 21.0.0
+ */
+class SubAdminRemovedEvent extends Event {
+
+ /** @var IGroup */
+ private $group;
+
+ /*** @var IUser */
+ private $user;
+
+ /**
+ * @since 21.0.0
+ */
+ public function __construct(IGroup $group, IUser $user) {
+ parent::__construct();
+ $this->group = $group;
+ $this->user = $user;
+ }
+
+ /**
+ * @since 21.0.0
+ */
+ public function getGroup(): IGroup {
+ return $this->group;
+ }
+
+ /**
+ * @since 21.0.0
+ */
+ public function getUser(): IUser {
+ return $this->user;
+ }
+}