diff --git a/apps/files_sharing/lib/AppInfo/Application.php b/apps/files_sharing/lib/AppInfo/Application.php index fc305e58dbe45..4466246518139 100644 --- a/apps/files_sharing/lib/AppInfo/Application.php +++ b/apps/files_sharing/lib/AppInfo/Application.php @@ -42,6 +42,7 @@ use OCA\Files_Sharing\Listener\LoadSidebarListener; use OCA\Files_Sharing\Listener\ShareInteractionListener; use OCA\Files_Sharing\Listener\UserAddedToGroupListener; +use OCA\Files_Sharing\Listener\UserRemoveFromGroupListener; use OCA\Files_Sharing\Listener\UserShareAcceptanceListener; use OCA\Files_Sharing\Middleware\OCSShareAPIMiddleware; use OCA\Files_Sharing\Middleware\ShareInfoMiddleware; @@ -66,6 +67,7 @@ use OCP\Group\Events\GroupChangedEvent; use OCP\Group\Events\GroupDeletedEvent; use OCP\Group\Events\UserAddedEvent; +use OCP\Group\Events\UserRemovedEvent; use OCP\IDBConnection; use OCP\IGroup; use OCP\IUserSession; @@ -134,6 +136,7 @@ public function registerEventsScripts(IEventDispatcher $dispatcher): void { $dispatcher->addServiceListener(ShareCreatedEvent::class, ShareInteractionListener::class); $dispatcher->addServiceListener(ShareCreatedEvent::class, UserShareAcceptanceListener::class); $dispatcher->addServiceListener(UserAddedEvent::class, UserAddedToGroupListener::class); + $dispatcher->addServiceListener(UserRemovedEvent::class, UserRemoveFromGroupListener::class); $dispatcher->addListener(ResourcesLoadAdditionalScriptsEvent::class, function () { \OCP\Util::addScript('files_sharing', 'collaboration'); }); diff --git a/apps/files_sharing/lib/Listener/UserRemoveFromGroupListener.php b/apps/files_sharing/lib/Listener/UserRemoveFromGroupListener.php new file mode 100644 index 0000000000000..8553b8a92c83c --- /dev/null +++ b/apps/files_sharing/lib/Listener/UserRemoveFromGroupListener.php @@ -0,0 +1,52 @@ + + * + * @author Louis Chmn + * + * @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 . + * + */ +namespace OCA\Files_Sharing\Listener; + +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Group\Events\UserRemovedEvent; +use OCP\IConfig; +use OCP\Share\IManager; + +/** @template-implements IEventListener */ +class UserRemoveFromGroupListener implements IEventListener { + public function __construct( + private IManager $shareManager, + private IConfig $config, + ) { + } + + public function handle(Event $event): void { + if (!($event instanceof UserRemovedEvent)) { + return; + } + + $user = $event->getUser(); + $group = $event->getGroup(); + + $this->shareManager->userDeletedFromGroup($user->getUID(), $group->getGID()); + } +}