Skip to content

Commit 7ed11b6

Browse files
authored
Merge pull request #23765 from nextcloud/techdebt/noid/sudadmin-events-into-typed-events
Add typed events for adding and removing a subadmin
2 parents 28e2551 + 765ee60 commit 7ed11b6

7 files changed

Lines changed: 187 additions & 27 deletions

File tree

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@
347347
'OCP\\Group\\Events\\BeforeUserRemovedEvent' => $baseDir . '/lib/public/Group/Events/BeforeUserRemovedEvent.php',
348348
'OCP\\Group\\Events\\GroupCreatedEvent' => $baseDir . '/lib/public/Group/Events/GroupCreatedEvent.php',
349349
'OCP\\Group\\Events\\GroupDeletedEvent' => $baseDir . '/lib/public/Group/Events/GroupDeletedEvent.php',
350+
'OCP\\Group\\Events\\SubAdminAddedEvent' => $baseDir . '/lib/public/Group/Events/SubAdminAddedEvent.php',
351+
'OCP\\Group\\Events\\SubAdminRemovedEvent' => $baseDir . '/lib/public/Group/Events/SubAdminRemovedEvent.php',
350352
'OCP\\Group\\Events\\UserAddedEvent' => $baseDir . '/lib/public/Group/Events/UserAddedEvent.php',
351353
'OCP\\Group\\Events\\UserRemovedEvent' => $baseDir . '/lib/public/Group/Events/UserRemovedEvent.php',
352354
'OCP\\Group\\ISubAdmin' => $baseDir . '/lib/public/Group/ISubAdmin.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
376376
'OCP\\Group\\Events\\BeforeUserRemovedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/BeforeUserRemovedEvent.php',
377377
'OCP\\Group\\Events\\GroupCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/GroupCreatedEvent.php',
378378
'OCP\\Group\\Events\\GroupDeletedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/GroupDeletedEvent.php',
379+
'OCP\\Group\\Events\\SubAdminAddedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/SubAdminAddedEvent.php',
380+
'OCP\\Group\\Events\\SubAdminRemovedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/SubAdminRemovedEvent.php',
379381
'OCP\\Group\\Events\\UserAddedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/UserAddedEvent.php',
380382
'OCP\\Group\\Events\\UserRemovedEvent' => __DIR__ . '/../../..' . '/lib/public/Group/Events/UserRemovedEvent.php',
381383
'OCP\\Group\\ISubAdmin' => __DIR__ . '/../../..' . '/lib/public/Group/ISubAdmin.php',

lib/private/Group/Manager.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
namespace OC\Group;
4242

4343
use OC\Hooks\PublicEmitter;
44+
use OCP\EventDispatcher\IEventDispatcher;
4445
use OCP\GroupInterface;
4546
use OCP\IGroup;
4647
use OCP\IGroupManager;
@@ -416,7 +417,8 @@ public function getSubAdmin() {
416417
$this->subAdmin = new \OC\SubAdmin(
417418
$this->userManager,
418419
$this,
419-
\OC::$server->getDatabaseConnection()
420+
\OC::$server->getDatabaseConnection(),
421+
\OC::$server->get(IEventDispatcher::class)
420422
);
421423
}
422424

lib/private/SubAdmin.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
namespace OC;
3333

3434
use OC\Hooks\PublicEmitter;
35+
use OCP\EventDispatcher\IEventDispatcher;
36+
use OCP\Group\Events\SubAdminAddedEvent;
37+
use OCP\Group\Events\SubAdminRemovedEvent;
3538
use OCP\Group\ISubAdmin;
3639
use OCP\IDBConnection;
3740
use OCP\IGroup;
@@ -50,17 +53,22 @@ class SubAdmin extends PublicEmitter implements ISubAdmin {
5053
/** @var IDBConnection */
5154
private $dbConn;
5255

56+
/** @var IEventDispatcher */
57+
private $eventDispatcher;
58+
5359
/**
5460
* @param IUserManager $userManager
5561
* @param IGroupManager $groupManager
5662
* @param IDBConnection $dbConn
5763
*/
5864
public function __construct(IUserManager $userManager,
5965
IGroupManager $groupManager,
60-
IDBConnection $dbConn) {
66+
IDBConnection $dbConn,
67+
IEventDispatcher $eventDispatcher) {
6168
$this->userManager = $userManager;
6269
$this->groupManager = $groupManager;
6370
$this->dbConn = $dbConn;
71+
$this->eventDispatcher = $eventDispatcher;
6472

6573
$this->userManager->listen('\OC\User', 'postDelete', function ($user) {
6674
$this->post_deleteUser($user);
@@ -85,8 +93,10 @@ public function createSubAdmin(IUser $user, IGroup $group): void {
8593
])
8694
->execute();
8795

96+
/** @depreacted 21.0.0 - use type SubAdminAddedEvent instead */
8897
$this->emit('\OC\SubAdmin', 'postCreateSubAdmin', [$user, $group]);
89-
\OC_Hook::emit("OC_SubAdmin", "post_createSubAdmin", ["gid" => $group->getGID()]);
98+
$event = new SubAdminAddedEvent($group, $user);
99+
$this->eventDispatcher->dispatchTyped($event);
90100
}
91101

92102
/**
@@ -102,8 +112,10 @@ public function deleteSubAdmin(IUser $user, IGroup $group): void {
102112
->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
103113
->execute();
104114

115+
/** @depreacted 21.0.0 - use type SubAdminRemovedEvent instead */
105116
$this->emit('\OC\SubAdmin', 'postDeleteSubAdmin', [$user, $group]);
106-
\OC_Hook::emit("OC_SubAdmin", "post_deleteSubAdmin", ["gid" => $group->getGID()]);
117+
$event = new SubAdminRemovedEvent($group, $user);
118+
$this->eventDispatcher->dispatchTyped($event);
107119
}
108120

109121
/**
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
7+
*
8+
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
9+
* @author Morris Jobke <hey@morrisjobke.de>
10+
*
11+
* @license GNU AGPL version 3 or any later version
12+
*
13+
* This program is free software: you can redistribute it and/or modify
14+
* it under the terms of the GNU Affero General Public License as
15+
* published by the Free Software Foundation, either version 3 of the
16+
* License, or (at your option) any later version.
17+
*
18+
* This program is distributed in the hope that it will be useful,
19+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
* GNU Affero General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU Affero General Public License
24+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25+
*
26+
*/
27+
28+
namespace OCP\Group\Events;
29+
30+
use OCP\EventDispatcher\Event;
31+
use OCP\IGroup;
32+
use OCP\IUser;
33+
34+
/**
35+
* @since 21.0.0
36+
*/
37+
class SubAdminAddedEvent extends Event {
38+
39+
/** @var IGroup */
40+
private $group;
41+
42+
/*** @var IUser */
43+
private $user;
44+
45+
/**
46+
* @since 21.0.0
47+
*/
48+
public function __construct(IGroup $group, IUser $user) {
49+
parent::__construct();
50+
$this->group = $group;
51+
$this->user = $user;
52+
}
53+
54+
/**
55+
* @since 21.0.0
56+
*/
57+
public function getGroup(): IGroup {
58+
return $this->group;
59+
}
60+
61+
/**
62+
* @since 21.0.0
63+
*/
64+
public function getUser(): IUser {
65+
return $this->user;
66+
}
67+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
7+
*
8+
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
9+
* @author Morris Jobke <hey@morrisjobke.de>
10+
*
11+
* @license GNU AGPL version 3 or any later version
12+
*
13+
* This program is free software: you can redistribute it and/or modify
14+
* it under the terms of the GNU Affero General Public License as
15+
* published by the Free Software Foundation, either version 3 of the
16+
* License, or (at your option) any later version.
17+
*
18+
* This program is distributed in the hope that it will be useful,
19+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
* GNU Affero General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU Affero General Public License
24+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25+
*
26+
*/
27+
28+
namespace OCP\Group\Events;
29+
30+
use OCP\EventDispatcher\Event;
31+
use OCP\IGroup;
32+
use OCP\IUser;
33+
34+
/**
35+
* @since 21.0.0
36+
*/
37+
class SubAdminRemovedEvent extends Event {
38+
39+
/** @var IGroup */
40+
private $group;
41+
42+
/*** @var IUser */
43+
private $user;
44+
45+
/**
46+
* @since 21.0.0
47+
*/
48+
public function __construct(IGroup $group, IUser $user) {
49+
parent::__construct();
50+
$this->group = $group;
51+
$this->user = $user;
52+
}
53+
54+
/**
55+
* @since 21.0.0
56+
*/
57+
public function getGroup(): IGroup {
58+
return $this->group;
59+
}
60+
61+
/**
62+
* @since 21.0.0
63+
*/
64+
public function getUser(): IUser {
65+
return $this->user;
66+
}
67+
}

0 commit comments

Comments
 (0)