Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/mail.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2020-04-27 15:25:32 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2020-05-05 22:12:08 +0300
commit0246f033b02bbb511308a9b0c2434046f82a68d8 (patch)
tree30d56ae6a626886bcc6e68b6c1d771059cbe1cc4 /lib/Listener
parente2a1ad2bbdd70db554f321b9b0dc29b9cbc82c49 (diff)
Delete all user's accounts when the user is deleted
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/Listener')
-rw-r--r--lib/Listener/UserDeletedListener.php70
1 files changed, 70 insertions, 0 deletions
diff --git a/lib/Listener/UserDeletedListener.php b/lib/Listener/UserDeletedListener.php
new file mode 100644
index 000000000..08cf6387e
--- /dev/null
+++ b/lib/Listener/UserDeletedListener.php
@@ -0,0 +1,70 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @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\Mail\Listener;
+
+use OCA\Mail\Exception\ClientException;
+use OCA\Mail\Service\AccountService;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\ILogger;
+use OCP\User\Events\BeforeUserDeletedEvent;
+
+class UserDeletedListener implements IEventListener {
+
+ /** @var AccountService */
+ private $accountService;
+
+ /** @var ILogger */
+ private $logger;
+
+ public function __construct(AccountService $accountService,
+ ILogger $logger) {
+ $this->accountService = $accountService;
+ $this->logger = $logger;
+ }
+
+ public function handle(Event $event): void {
+ if (!($event instanceof BeforeUserDeletedEvent)) {
+ // Unrelated
+ return;
+ }
+
+ $user = $event->getUser();
+ foreach ($this->accountService->findByUserId($user->getUID()) as $account) {
+ try {
+ $this->accountService->delete(
+ $user->getUID(),
+ $account->getId()
+ );
+ } catch (ClientException $e) {
+ $this->logger->logException($e, [
+ 'message' => 'Could not delete user\'s Mail account: ' . $e->getMessage(),
+ 'level' => ILogger::ERROR,
+ ]);
+ }
+ }
+ }
+}