diff options
author | Christopher Ng <chrng8@gmail.com> | 2023-08-03 15:42:14 -0700 |
---|---|---|
committer | Christopher Ng <chrng8@gmail.com> | 2023-08-08 16:29:12 -0700 |
commit | d3991ee4a8cc4f49cd855875c9b3ae2efdaebf9c (patch) | |
tree | 7f2578d221e0ab8de2d97dc45956c1608bbf2513 /apps/files_reminders | |
parent | dfba8f4e5933f05fe6dbe0e98ebeb7138f3c518c (diff) | |
download | nextcloud-server-d3991ee4a8cc4f49cd855875c9b3ae2efdaebf9c.tar.gz nextcloud-server-d3991ee4a8cc4f49cd855875c9b3ae2efdaebf9c.zip |
enh: handle user deleted
Signed-off-by: Christopher Ng <chrng8@gmail.com>
(cherry picked from commit a806bd0d3c53d7d12fe2c0e9a6559f1ac71ca86f)
Diffstat (limited to 'apps/files_reminders')
6 files changed, 62 insertions, 2 deletions
diff --git a/apps/files_reminders/composer/composer/autoload_classmap.php b/apps/files_reminders/composer/composer/autoload_classmap.php index fb17eb7a1b6..4f81cd387da 100644 --- a/apps/files_reminders/composer/composer/autoload_classmap.php +++ b/apps/files_reminders/composer/composer/autoload_classmap.php @@ -17,6 +17,7 @@ return array( 'OCA\\FilesReminders\\Exception\\NodeNotFoundException' => $baseDir . '/../lib/Exception/NodeNotFoundException.php', 'OCA\\FilesReminders\\Exception\\UserNotFoundException' => $baseDir . '/../lib/Exception/UserNotFoundException.php', 'OCA\\FilesReminders\\Listener\\NodeDeletedListener' => $baseDir . '/../lib/Listener/NodeDeletedListener.php', + 'OCA\\FilesReminders\\Listener\\UserDeletedListener' => $baseDir . '/../lib/Listener/UserDeletedListener.php', 'OCA\\FilesReminders\\Migration\\Version10000Date20230725162149' => $baseDir . '/../lib/Migration/Version10000Date20230725162149.php', 'OCA\\FilesReminders\\Model\\RichReminder' => $baseDir . '/../lib/Model/RichReminder.php', 'OCA\\FilesReminders\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php', diff --git a/apps/files_reminders/composer/composer/autoload_static.php b/apps/files_reminders/composer/composer/autoload_static.php index 1a2bc0d1bd1..eff14f8f569 100644 --- a/apps/files_reminders/composer/composer/autoload_static.php +++ b/apps/files_reminders/composer/composer/autoload_static.php @@ -32,6 +32,7 @@ class ComposerStaticInitFilesReminders 'OCA\\FilesReminders\\Exception\\NodeNotFoundException' => __DIR__ . '/..' . '/../lib/Exception/NodeNotFoundException.php', 'OCA\\FilesReminders\\Exception\\UserNotFoundException' => __DIR__ . '/..' . '/../lib/Exception/UserNotFoundException.php', 'OCA\\FilesReminders\\Listener\\NodeDeletedListener' => __DIR__ . '/..' . '/../lib/Listener/NodeDeletedListener.php', + 'OCA\\FilesReminders\\Listener\\UserDeletedListener' => __DIR__ . '/..' . '/../lib/Listener/UserDeletedListener.php', 'OCA\\FilesReminders\\Migration\\Version10000Date20230725162149' => __DIR__ . '/..' . '/../lib/Migration/Version10000Date20230725162149.php', 'OCA\\FilesReminders\\Model\\RichReminder' => __DIR__ . '/..' . '/../lib/Model/RichReminder.php', 'OCA\\FilesReminders\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php', diff --git a/apps/files_reminders/composer/composer/installed.php b/apps/files_reminders/composer/composer/installed.php index f120393f41b..b962688d0b9 100644 --- a/apps/files_reminders/composer/composer/installed.php +++ b/apps/files_reminders/composer/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'cce2e1543b16a04e6b9fc1ba3f89fbc47f12e773', + 'reference' => '5a11535c51ae0277f6bb0af048215e329b6068d0', 'type' => 'library', 'install_path' => __DIR__ . '/../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'cce2e1543b16a04e6b9fc1ba3f89fbc47f12e773', + 'reference' => '5a11535c51ae0277f6bb0af048215e329b6068d0', 'type' => 'library', 'install_path' => __DIR__ . '/../', 'aliases' => array(), diff --git a/apps/files_reminders/lib/AppInfo/Application.php b/apps/files_reminders/lib/AppInfo/Application.php index 1e4813e1ec7..d35bd5c5de2 100644 --- a/apps/files_reminders/lib/AppInfo/Application.php +++ b/apps/files_reminders/lib/AppInfo/Application.php @@ -27,12 +27,14 @@ declare(strict_types=1); namespace OCA\FilesReminders\AppInfo; use OCA\FilesReminders\Listener\NodeDeletedListener; +use OCA\FilesReminders\Listener\UserDeletedListener; use OCA\FilesReminders\Notification\Notifier; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; use OCP\AppFramework\Bootstrap\IRegistrationContext; use OCP\Files\Events\Node\NodeDeletedEvent; +use OCP\User\Events\UserDeletedEvent; class Application extends App implements IBootstrap { public const APP_ID = 'files_reminders'; @@ -46,6 +48,8 @@ class Application extends App implements IBootstrap { public function register(IRegistrationContext $context): void { $context->registerNotifierService(Notifier::class); + $context->registerEventListener(NodeDeletedEvent::class, NodeDeletedListener::class); + $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); } } diff --git a/apps/files_reminders/lib/Listener/UserDeletedListener.php b/apps/files_reminders/lib/Listener/UserDeletedListener.php new file mode 100644 index 00000000000..b95102c1cc2 --- /dev/null +++ b/apps/files_reminders/lib/Listener/UserDeletedListener.php @@ -0,0 +1,47 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2023 Christopher Ng <chrng8@gmail.com> + * + * @author Christopher Ng <chrng8@gmail.com> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\FilesReminders\Listener; + +use OCA\FilesReminders\Service\ReminderService; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\User\Events\UserDeletedEvent; + +class UserDeletedListener implements IEventListener { + public function __construct( + private ReminderService $reminderService, + ) {} + + public function handle(Event $event): void { + if (!($event instanceof UserDeletedEvent)) { + return; + } + + $user = $event->getUser(); + $this->reminderService->removeAllForUser($user); + } +} diff --git a/apps/files_reminders/lib/Service/ReminderService.php b/apps/files_reminders/lib/Service/ReminderService.php index 91652a4e0be..5c7193259c1 100644 --- a/apps/files_reminders/lib/Service/ReminderService.php +++ b/apps/files_reminders/lib/Service/ReminderService.php @@ -128,6 +128,13 @@ class ReminderService { } } + public function removeAllForUser(IUser $user): void { + $reminders = $this->reminderMapper->findAllForUser($user); + foreach ($reminders as $reminder) { + $this->reminderMapper->delete($reminder); + } + } + /** * @throws DoesNotExistException * @throws UserNotFoundException |