From c63ab0379991e9433091f0ed93d22fcfffbfd875 Mon Sep 17 00:00:00 2001 From: Akhil Date: Wed, 9 Aug 2023 22:56:58 +0530 Subject: [PATCH] Throw an exception if shop user has active subscription --- ...eletingUserWithActiveSubscriptionException.php | 9 +++++++++ lib/Listeners/BeforeUserDeletedListener.php | 15 +++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 lib/Exception/DeletingUserWithActiveSubscriptionException.php diff --git a/lib/Exception/DeletingUserWithActiveSubscriptionException.php b/lib/Exception/DeletingUserWithActiveSubscriptionException.php new file mode 100644 index 00000000..edbc393b --- /dev/null +++ b/lib/Exception/DeletingUserWithActiveSubscriptionException.php @@ -0,0 +1,9 @@ +getUser(); $email = $user->getEMailAddress(); $uid = $user->getUID(); + + // Handle shop accounts first; none of the other things should happen before the active subscription check + $this->handleShopAccounts($uid, $email); + $isUserOnLDAP = $this->LDAPConnectionService->isUserOnLDAPBackend($user); $this->logger->info("PostDelete user {user}", array('user' => $uid)); @@ -58,12 +63,22 @@ class BeforeUserDeletedListener implements IEventListener { } catch (Exception $e) { $this->logger->error('Error deleting aliases for user '. $uid . ' :' . $e->getMessage()); } + } + private function handleShopAccounts(string $uid, string $email) { $deleteShopAccount = $this->shopAccountService->getShopDeletePreference($uid); $shopUsers = $this->shopAccountService->getUsers($email); if (!empty($shopUsers)) { foreach ($shopUsers as $shopUser) { + if ($shopUser['has_active_subscription']) { + throw new DeletingUserWithActiveSubscriptionException('Cannot delete user ' . $uid . ' as an active subscription exists'); + } + + if (!isset($shopUser['id'])) { + continue; + } + if ($deleteShopAccount) { $this->shopAccountService->deleteUser($shopUser['shop_url'], $shopUser['id']); } else { -- GitLab