Skip to content

Commit a789288

Browse files
authored
Merge pull request #36792 from nextcloud/enh/noid/add-before-group-changed-event
New BeforeGroupChangedEvent before setDisplayName on groups
2 parents 8bc9e23 + d992580 commit a789288

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

lib/private/Group/Group.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use OCP\Group\Backend\IHideFromCollaborationBackend;
3939
use OCP\Group\Backend\INamedBackend;
4040
use OCP\Group\Backend\ISetDisplayNameBackend;
41+
use OCP\Group\Events\BeforeGroupChangedEvent;
4142
use OCP\Group\Events\GroupChangedEvent;
4243
use OCP\GroupInterface;
4344
use OCP\IGroup;
@@ -109,6 +110,7 @@ public function getDisplayName() {
109110
public function setDisplayName(string $displayName): bool {
110111
$displayName = trim($displayName);
111112
if ($displayName !== '') {
113+
$this->dispatcher->dispatch(new BeforeGroupChangedEvent($this, 'displayName', $displayName, $this->displayName));
112114
foreach ($this->backends as $backend) {
113115
if (($backend instanceof ISetDisplayNameBackend)
114116
&& $backend->setDisplayName($this->gid, $displayName)) {
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2023 Julien Veyssier <julien-nc@posteo.net>
7+
*
8+
* @author Julien Veyssier <julien-nc@posteo.net>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
namespace OCP\Group\Events;
27+
28+
use OCP\EventDispatcher\Event;
29+
use OCP\IGroup;
30+
31+
/**
32+
* @since 26.0.0
33+
*/
34+
class BeforeGroupChangedEvent extends Event {
35+
private IGroup $group;
36+
private string $feature;
37+
/** @var mixed */
38+
private $value;
39+
/** @var mixed */
40+
private $oldValue;
41+
42+
/**
43+
* @since 26.0.0
44+
*/
45+
public function __construct(IGroup $group,
46+
string $feature,
47+
$value,
48+
$oldValue = null) {
49+
parent::__construct();
50+
$this->group = $group;
51+
$this->feature = $feature;
52+
$this->value = $value;
53+
$this->oldValue = $oldValue;
54+
}
55+
56+
/**
57+
*
58+
* @since 26.0.0
59+
*
60+
* @return IGroup
61+
*/
62+
public function getGroup(): IGroup {
63+
return $this->group;
64+
}
65+
66+
/**
67+
*
68+
* @since 26.0.0
69+
*
70+
* @return string
71+
*/
72+
public function getFeature(): string {
73+
return $this->feature;
74+
}
75+
76+
/**
77+
* @since 26.0.0
78+
*
79+
* @return mixed
80+
*/
81+
public function getValue() {
82+
return $this->value;
83+
}
84+
85+
/**
86+
*
87+
* @since 26.0.0
88+
*
89+
* @return mixed
90+
*/
91+
public function getOldValue() {
92+
return $this->oldValue;
93+
}
94+
}

0 commit comments

Comments
 (0)