Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/dav/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
use OCP\User\Events\UserFirstTimeLoggedInEvent;
use OCP\User\Events\UserIdAssignedEvent;
use OCP\User\Events\UserIdUnassignedEvent;
use OCP\Group\Events\GroupDeletedEvent;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Throwable;
Expand Down Expand Up @@ -205,6 +206,7 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(UserCreatedEvent::class, UserEventsListener::class);
$context->registerEventListener(UserChangedEvent::class, UserEventsListener::class);
$context->registerEventListener(UserUpdatedEvent::class, UserEventsListener::class);
$context->registerEventListener(GroupDeletedEvent::class, UserEventsListener::class);

$context->registerEventListener(SabrePluginAuthInitEvent::class, SabrePluginAuthInitListener::class);

Expand Down
11 changes: 10 additions & 1 deletion apps/dav/lib/Listener/UserEventsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
use OCP\User\Events\UserFirstTimeLoggedInEvent;
use OCP\User\Events\UserIdAssignedEvent;
use OCP\User\Events\UserIdUnassignedEvent;
use OCP\Group\Events\BeforeGroupDeletedEvent;
use OCP\Group\Events\GroupDeletedEvent;
use Psr\Log\LoggerInterface;

/** @template-implements IEventListener<UserFirstTimeLoggedInEvent|UserIdAssignedEvent|BeforeUserIdUnassignedEvent|UserIdUnassignedEvent|BeforeUserDeletedEvent|UserDeletedEvent|UserCreatedEvent|UserChangedEvent|UserUpdatedEvent> */
/** @template-implements IEventListener<UserFirstTimeLoggedInEvent|UserIdAssignedEvent|BeforeUserIdUnassignedEvent|UserIdUnassignedEvent|BeforeUserDeletedEvent|UserDeletedEvent|UserCreatedEvent|UserChangedEvent|UserUpdatedEvent|BeforeGroupDeletedEvent|GroupDeletedEvent> */
class UserEventsListener implements IEventListener {

/** @var IUser[] */
Expand Down Expand Up @@ -77,6 +79,8 @@ public function handle(Event $event): void {
$this->firstLogin($event->getUser());
} elseif ($event instanceof UserUpdatedEvent) {
$this->updateUser($event->getUser());
} elseif ($event instanceof GroupDeletedEvent) {
$this->postDeleteGroup($event->getGroup()->getGID());
}
}

Expand Down Expand Up @@ -135,6 +139,11 @@ public function postDeleteUser(string $uid): void {
unset($this->addressBooksToDelete[$uid]);
}

public function postDeleteGroup(string $gid): void {
$this->calDav->deleteAllSharesByUser('principals/groups/' . $gid);
$this->cardDav->deleteAllSharesByUser('principals/groups/' . $gid);
}
Comment on lines 142 to 146
Copy link
Contributor

@SebastianKrupinski SebastianKrupinski Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks for groups with special characters like spaces that get replaced with "+"... Tested with "Test Group A"...

$event->getGroup()->getGID() returns "Test Group A" but the actual uri is "Test+Group+A" so the deletion fails and the group is not deleted.

Image Image

Also tested with a renamed group, started with "Test Group 2" then renamed to "Test Group B" although the label of the group is changed... the uri stays the same... and the group is not deleted.

Copy link
Contributor Author

@max65482 max65482 Jan 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find!
Pushed a new commit. This should fix the first case.
I could not reproduce the second case. Can you check it again with a changed group name without spaces (you have both cases otherwise)?


public function changeUser(IUser $user, string $feature): void {
// This case is already covered by the account manager firing up a signal
// later on
Expand Down
11 changes: 11 additions & 0 deletions apps/dav/tests/unit/DAV/Listener/UserEventsListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,15 @@ public function testDeleteUserAutomationEvent(): void {
$this->userEventsListener->preDeleteUser($user);
$this->userEventsListener->postDeleteUser('newUser');
}

public function testDeleteGroup(): void {
$this->calDavBackend->expects($this->once())
->method('deleteAllSharesByUser')
->with('principals/groups/testGroup');
$this->cardDavBackend->expects($this->once())
->method('deleteAllSharesByUser')
->with('principals/groups/testGroup');

$this->userEventsListener->postDeleteGroup('testGroup');
}
}