From 8b768210d2ac28b236617b20c19498085ddcf328 Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Tue, 7 May 2024 12:31:47 +0200 Subject: [PATCH] fix(files_sharing): Update shares on group removal Signed-off-by: Louis Chemineau --- .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + .../files_sharing/lib/AppInfo/Application.php | 3 ++ .../Listener/UserRemoveFromGroupListener.php | 50 +++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 apps/files_sharing/lib/Listener/UserRemoveFromGroupListener.php diff --git a/apps/files_sharing/composer/composer/autoload_classmap.php b/apps/files_sharing/composer/composer/autoload_classmap.php index 142e13679178e..d0d9eb9c0510c 100644 --- a/apps/files_sharing/composer/composer/autoload_classmap.php +++ b/apps/files_sharing/composer/composer/autoload_classmap.php @@ -60,6 +60,7 @@ 'OCA\\Files_Sharing\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php', 'OCA\\Files_Sharing\\Listener\\ShareInteractionListener' => $baseDir . '/../lib/Listener/ShareInteractionListener.php', 'OCA\\Files_Sharing\\Listener\\UserAddedToGroupListener' => $baseDir . '/../lib/Listener/UserAddedToGroupListener.php', + 'OCA\\Files_Sharing\\Listener\\UserRemoveFromGroupListener' => $baseDir . '/../lib/Listener/UserRemoveFromGroupListener.php', 'OCA\\Files_Sharing\\Listener\\UserShareAcceptanceListener' => $baseDir . '/../lib/Listener/UserShareAcceptanceListener.php', 'OCA\\Files_Sharing\\Middleware\\OCSShareAPIMiddleware' => $baseDir . '/../lib/Middleware/OCSShareAPIMiddleware.php', 'OCA\\Files_Sharing\\Middleware\\ShareInfoMiddleware' => $baseDir . '/../lib/Middleware/ShareInfoMiddleware.php', diff --git a/apps/files_sharing/composer/composer/autoload_static.php b/apps/files_sharing/composer/composer/autoload_static.php index 087c7d4cd86ac..bfa2d99cb37d5 100644 --- a/apps/files_sharing/composer/composer/autoload_static.php +++ b/apps/files_sharing/composer/composer/autoload_static.php @@ -75,6 +75,7 @@ class ComposerStaticInitFiles_Sharing 'OCA\\Files_Sharing\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php', 'OCA\\Files_Sharing\\Listener\\ShareInteractionListener' => __DIR__ . '/..' . '/../lib/Listener/ShareInteractionListener.php', 'OCA\\Files_Sharing\\Listener\\UserAddedToGroupListener' => __DIR__ . '/..' . '/../lib/Listener/UserAddedToGroupListener.php', + 'OCA\\Files_Sharing\\Listener\\UserRemoveFromGroupListener' => __DIR__ . '/..' . '/../lib/Listener/UserRemoveFromGroupListener.php', 'OCA\\Files_Sharing\\Listener\\UserShareAcceptanceListener' => __DIR__ . '/..' . '/../lib/Listener/UserShareAcceptanceListener.php', 'OCA\\Files_Sharing\\Middleware\\OCSShareAPIMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/OCSShareAPIMiddleware.php', 'OCA\\Files_Sharing\\Middleware\\ShareInfoMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/ShareInfoMiddleware.php', 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..6b676ab091788 --- /dev/null +++ b/apps/files_sharing/lib/Listener/UserRemoveFromGroupListener.php @@ -0,0 +1,50 @@ + + * + * @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\Share\IManager; + +/** @template-implements IEventListener */ +class UserRemoveFromGroupListener implements IEventListener { + public function __construct( + private IManager $shareManager, + ) { + } + + public function handle(Event $event): void { + if (!($event instanceof UserRemovedEvent)) { + return; + } + + $user = $event->getUser(); + $group = $event->getGroup(); + + $this->shareManager->userDeletedFromGroup($user->getUID(), $group->getGID()); + } +}