From 6cee45c5c83d5f5549ed3bea655cb3001108a5a6 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 15 Jan 2024 16:00:33 -0800 Subject: [PATCH 01/11] Delete Mailfolder at delete listener --- lib/Listeners/BeforeUserDeletedListener.php | 6 +++++ lib/Service/UserService.php | 27 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/Listeners/BeforeUserDeletedListener.php b/lib/Listeners/BeforeUserDeletedListener.php index 66d483d6..bdb96ae1 100644 --- a/lib/Listeners/BeforeUserDeletedListener.php +++ b/lib/Listeners/BeforeUserDeletedListener.php @@ -63,6 +63,12 @@ class BeforeUserDeletedListener implements IEventListener { } catch (Exception $e) { $this->logger->error('Error deleting aliases for user '. $uid . ' :' . $e->getMessage()); } + + try { + $this->userService->deleteMailFolder($email); + } catch (Exception $e) { + $this->logger->error('Error deleting mail folder for user '. $uid . ' :' . $e->getMessage()); + } } private function handleShopAccounts(string $uid, string $email) { diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 221cae5c..e736bf6d 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -454,4 +454,31 @@ class UserService { throw new Exception('Error adding username ' . $username . ' to common data store'); } } + + public function deleteMailFolder(string $email) : void { + $commonServicesURL = $this->apiConfig['commonServicesURL']; + $commonApiVersion = $this->apiConfig['commonApiVersion']; + + if (!isset($commonServicesURL) || empty($commonServicesURL)) { + return; + } + + $endpoint = $commonApiVersion . '/emails/'; + $url = $commonServicesURL . $endpoint ; // DELETE /v2/emails/@email + + $params = [ + 'email' => $email + ]; + + $token = $this->apiConfig['commonServicesToken']; + $headers = [ + "Authorization: Bearer $token" + ]; + + $this->curl->delete($url, $params, $headers); + + if ($this->curl->getLastStatusCode() !== 200) { + throw new Exception('Error deleting mail folder of' . $email . '. Status Code: '.$this->curl->getLastStatusCode()); + } + } } -- GitLab From 4eb40808c5cd8121be13dd85e840b46f5443124b Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 15 Jan 2024 16:14:06 -0800 Subject: [PATCH 02/11] php fixer --- lib/Service/UserService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index e736bf6d..a53e916c 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -463,7 +463,7 @@ class UserService { return; } - $endpoint = $commonApiVersion . '/emails/'; + $endpoint = $commonApiVersion . '/emails/'; $url = $commonServicesURL . $endpoint ; // DELETE /v2/emails/@email $params = [ -- GitLab From c49d633c0dfe07e42814c5209d601d30dd010423 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 15 Jan 2024 16:15:57 -0800 Subject: [PATCH 03/11] php fixer --- lib/Service/UserService.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index a53e916c..2ec85b81 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -463,12 +463,10 @@ class UserService { return; } - $endpoint = $commonApiVersion . '/emails/'; - $url = $commonServicesURL . $endpoint ; // DELETE /v2/emails/@email - - $params = [ - 'email' => $email - ]; + $endpoint = $commonApiVersion . '/emails/' . $email; + $url = $commonServicesURL . $endpoint; // DELETE /v2/emails/@email + + $params = []; $token = $this->apiConfig['commonServicesToken']; $headers = [ -- GitLab From 61896736fcff234653457031bfd1ab8c5d1c4e3b Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 15 Jan 2024 22:54:21 -0800 Subject: [PATCH 04/11] test --- lib/Listeners/BeforeUserDeletedListener.php | 1 + lib/Service/UserService.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Listeners/BeforeUserDeletedListener.php b/lib/Listeners/BeforeUserDeletedListener.php index bdb96ae1..753af61c 100644 --- a/lib/Listeners/BeforeUserDeletedListener.php +++ b/lib/Listeners/BeforeUserDeletedListener.php @@ -65,6 +65,7 @@ class BeforeUserDeletedListener implements IEventListener { } try { + $this->logger->info("deleteMailFolder for ".$email); $this->userService->deleteMailFolder($email); } catch (Exception $e) { $this->logger->error('Error deleting mail folder for user '. $uid . ' :' . $e->getMessage()); diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 2ec85b81..3e0cd843 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -465,7 +465,7 @@ class UserService { $endpoint = $commonApiVersion . '/emails/' . $email; $url = $commonServicesURL . $endpoint; // DELETE /v2/emails/@email - + $this->logger->info("deleteMailFolder for URL ".$url); $params = []; $token = $this->apiConfig['commonServicesToken']; -- GitLab From 6765c7d875cdb0153127c75008ed80622b27f79f Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 15 Jan 2024 23:02:34 -0800 Subject: [PATCH 05/11] test --- lib/Listeners/BeforeUserDeletedListener.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Listeners/BeforeUserDeletedListener.php b/lib/Listeners/BeforeUserDeletedListener.php index 753af61c..8507c4c4 100644 --- a/lib/Listeners/BeforeUserDeletedListener.php +++ b/lib/Listeners/BeforeUserDeletedListener.php @@ -32,6 +32,7 @@ class BeforeUserDeletedListener implements IEventListener { public function handle(Event $event): void { + $this->logger->info("deleteMailFolder handle called"); if (!($event instanceof BeforeUserDeletedEvent)) { return; } -- GitLab From 690bdb68e8c09341aafe053f5618cc3361734cbd Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 15 Jan 2024 23:12:16 -0800 Subject: [PATCH 06/11] test --- lib/Listeners/BeforeUserDeletedListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Listeners/BeforeUserDeletedListener.php b/lib/Listeners/BeforeUserDeletedListener.php index 8507c4c4..c05d3ef9 100644 --- a/lib/Listeners/BeforeUserDeletedListener.php +++ b/lib/Listeners/BeforeUserDeletedListener.php @@ -32,7 +32,7 @@ class BeforeUserDeletedListener implements IEventListener { public function handle(Event $event): void { - $this->logger->info("deleteMailFolder handle called"); + $this->logger->error("deleteMailFolder handle called"); if (!($event instanceof BeforeUserDeletedEvent)) { return; } @@ -46,7 +46,7 @@ class BeforeUserDeletedListener implements IEventListener { $isUserOnLDAP = $this->LDAPConnectionService->isUserOnLDAPBackend($user); - $this->logger->info("PostDelete user {user}", array('user' => $uid)); + $this->logger->error("PostDelete user {user}", array('user' => $uid)); $this->userService->ecloudDelete( $uid, $this->config->getSystemValue('e_welcome_domain'), -- GitLab From 46787bc33b3955a69ff14487f0768d12d81f0de2 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 15 Jan 2024 23:26:41 -0800 Subject: [PATCH 07/11] removed logger --- lib/Listeners/BeforeUserDeletedListener.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Listeners/BeforeUserDeletedListener.php b/lib/Listeners/BeforeUserDeletedListener.php index c05d3ef9..1553c808 100644 --- a/lib/Listeners/BeforeUserDeletedListener.php +++ b/lib/Listeners/BeforeUserDeletedListener.php @@ -32,7 +32,6 @@ class BeforeUserDeletedListener implements IEventListener { public function handle(Event $event): void { - $this->logger->error("deleteMailFolder handle called"); if (!($event instanceof BeforeUserDeletedEvent)) { return; } @@ -66,7 +65,6 @@ class BeforeUserDeletedListener implements IEventListener { } try { - $this->logger->info("deleteMailFolder for ".$email); $this->userService->deleteMailFolder($email); } catch (Exception $e) { $this->logger->error('Error deleting mail folder for user '. $uid . ' :' . $e->getMessage()); -- GitLab From 430ac05c6d10a58b952de511d58bca737c7a977c Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Mon, 15 Jan 2024 23:28:22 -0800 Subject: [PATCH 08/11] removed logger --- lib/Listeners/BeforeUserDeletedListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Listeners/BeforeUserDeletedListener.php b/lib/Listeners/BeforeUserDeletedListener.php index 1553c808..bdb96ae1 100644 --- a/lib/Listeners/BeforeUserDeletedListener.php +++ b/lib/Listeners/BeforeUserDeletedListener.php @@ -45,7 +45,7 @@ class BeforeUserDeletedListener implements IEventListener { $isUserOnLDAP = $this->LDAPConnectionService->isUserOnLDAPBackend($user); - $this->logger->error("PostDelete user {user}", array('user' => $uid)); + $this->logger->info("PostDelete user {user}", array('user' => $uid)); $this->userService->ecloudDelete( $uid, $this->config->getSystemValue('e_welcome_domain'), -- GitLab From 5943bb9adf0cc9f381770849e2dd1fa37393a8c1 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 16 Jan 2024 15:47:19 -0800 Subject: [PATCH 09/11] changed the method --- lib/Listeners/BeforeUserDeletedListener.php | 14 +---- lib/Service/UserService.php | 66 ++++++--------------- 2 files changed, 20 insertions(+), 60 deletions(-) diff --git a/lib/Listeners/BeforeUserDeletedListener.php b/lib/Listeners/BeforeUserDeletedListener.php index bdb96ae1..0b148c30 100644 --- a/lib/Listeners/BeforeUserDeletedListener.php +++ b/lib/Listeners/BeforeUserDeletedListener.php @@ -46,13 +46,7 @@ class BeforeUserDeletedListener implements IEventListener { $isUserOnLDAP = $this->LDAPConnectionService->isUserOnLDAPBackend($user); $this->logger->info("PostDelete user {user}", array('user' => $uid)); - $this->userService->ecloudDelete( - $uid, - $this->config->getSystemValue('e_welcome_domain'), - $this->config->getSystemValue('e_welcome_secret'), - $email, - $isUserOnLDAP - ); + $this->userService->ecloudDelete($email); try { if ($this->LDAPConnectionService->isLDAPEnabled() && $isUserOnLDAP) { @@ -63,12 +57,6 @@ class BeforeUserDeletedListener implements IEventListener { } catch (Exception $e) { $this->logger->error('Error deleting aliases for user '. $uid . ' :' . $e->getMessage()); } - - try { - $this->userService->deleteMailFolder($email); - } catch (Exception $e) { - $this->logger->error('Error deleting mail folder for user '. $uid . ' :' . $e->getMessage()); - } } private function handleShopAccounts(string $uid, string $email) { diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 3e0cd843..94230c77 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -138,32 +138,29 @@ class UserService { * @param $welcomeSecret string generated at ecloud selfhosting install and added as a custom var in NC's config * @return mixed response of the external endpoint */ - public function ecloudDelete(string $userID, string $welcomeDomain, string $welcomeSecret, string $email, bool $isUserOnLDAP = false) { - $endpoint = '/postDelete.php'; - if ($isUserOnLDAP) { - $endpoint = '/postDeleteLDAP.php'; + public function ecloudDelete(string $email) { + $commonServicesURL = $this->apiConfig['commonServicesURL']; + $commonApiVersion = $this->apiConfig['commonApiVersion']; + + if (!isset($commonServicesURL) || empty($commonServicesURL)) { + return; } - $postDeleteUrl = "https://" . $welcomeDomain . $endpoint; - /** - * send action to docker_welcome - * Handling the non NC part of deletion process - */ - try { - $params = [ - 'sec' => $welcomeSecret, - 'uid' => $userID, - 'email' => $email - ]; - $answer = $this->curl->post($postDeleteUrl, $params); + $endpoint = $commonApiVersion . '/emails/' . $email; + $url = $commonServicesURL . $endpoint; // DELETE /v2/emails/@email + $this->logger->info("deleteMailFolder for URL ".$url); + $params = []; - return json_decode($answer, true); - } catch (\Exception $e) { - $this->logger->error('There has been an issue while contacting the external deletion script'); - $this->logger->logException($e, ['app' => Application::APP_ID]); - } + $token = $this->apiConfig['commonServicesToken']; + $headers = [ + "Authorization: Bearer $token" + ]; + + $this->curl->delete($url, $params, $headers); - return null; + if ($this->curl->getLastStatusCode() !== 200) { + throw new Exception('Error deleting mail folder of' . $email . '. Status Code: '.$this->curl->getLastStatusCode()); + } } public function sendWelcomeEmail(string $displayname, string $username, string $userEmail, string $language = 'en') : void { @@ -454,29 +451,4 @@ class UserService { throw new Exception('Error adding username ' . $username . ' to common data store'); } } - - public function deleteMailFolder(string $email) : void { - $commonServicesURL = $this->apiConfig['commonServicesURL']; - $commonApiVersion = $this->apiConfig['commonApiVersion']; - - if (!isset($commonServicesURL) || empty($commonServicesURL)) { - return; - } - - $endpoint = $commonApiVersion . '/emails/' . $email; - $url = $commonServicesURL . $endpoint; // DELETE /v2/emails/@email - $this->logger->info("deleteMailFolder for URL ".$url); - $params = []; - - $token = $this->apiConfig['commonServicesToken']; - $headers = [ - "Authorization: Bearer $token" - ]; - - $this->curl->delete($url, $params, $headers); - - if ($this->curl->getLastStatusCode() !== 200) { - throw new Exception('Error deleting mail folder of' . $email . '. Status Code: '.$this->curl->getLastStatusCode()); - } - } } -- GitLab From 29b6c82596c0c2bed362626b49213be7f07a6c9a Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 16 Jan 2024 15:48:15 -0800 Subject: [PATCH 10/11] changes --- lib/Listeners/BeforeUserDeletedListener.php | 9 ++++++--- lib/Service/UserService.php | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Listeners/BeforeUserDeletedListener.php b/lib/Listeners/BeforeUserDeletedListener.php index 0b148c30..86eefa49 100644 --- a/lib/Listeners/BeforeUserDeletedListener.php +++ b/lib/Listeners/BeforeUserDeletedListener.php @@ -45,9 +45,12 @@ class BeforeUserDeletedListener implements IEventListener { $isUserOnLDAP = $this->LDAPConnectionService->isUserOnLDAPBackend($user); - $this->logger->info("PostDelete user {user}", array('user' => $uid)); - $this->userService->ecloudDelete($email); - + try { + $this->logger->info("PostDelete user {user}", array('user' => $uid)); + $this->userService->deleteEcloudMailFolder($email); + } catch (Exception $e) { + $this->logger->error('Error deleting mail folder for user '. $uid . ' :' . $e->getMessage()); + } try { if ($this->LDAPConnectionService->isLDAPEnabled() && $isUserOnLDAP) { $conn = $this->LDAPConnectionService->getLDAPConnection(); diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 94230c77..792ed19f 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -138,7 +138,7 @@ class UserService { * @param $welcomeSecret string generated at ecloud selfhosting install and added as a custom var in NC's config * @return mixed response of the external endpoint */ - public function ecloudDelete(string $email) { + public function deleteEcloudMailFolder(string $email) { $commonServicesURL = $this->apiConfig['commonServicesURL']; $commonApiVersion = $this->apiConfig['commonApiVersion']; -- GitLab From 86b664a9102463d9d667b39b844e993398bbd6e8 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 18 Jan 2024 17:45:34 -0800 Subject: [PATCH 11/11] removed changes --- lib/Listeners/BeforeUserDeletedListener.php | 2 +- lib/Service/UserService.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Listeners/BeforeUserDeletedListener.php b/lib/Listeners/BeforeUserDeletedListener.php index 86eefa49..aa4a21eb 100644 --- a/lib/Listeners/BeforeUserDeletedListener.php +++ b/lib/Listeners/BeforeUserDeletedListener.php @@ -47,7 +47,7 @@ class BeforeUserDeletedListener implements IEventListener { try { $this->logger->info("PostDelete user {user}", array('user' => $uid)); - $this->userService->deleteEcloudMailFolder($email); + $this->userService->deleteEmailAccount($email); } catch (Exception $e) { $this->logger->error('Error deleting mail folder for user '. $uid . ' :' . $e->getMessage()); } diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 792ed19f..d8995194 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -138,7 +138,7 @@ class UserService { * @param $welcomeSecret string generated at ecloud selfhosting install and added as a custom var in NC's config * @return mixed response of the external endpoint */ - public function deleteEcloudMailFolder(string $email) { + public function deleteEmailAccount(string $email) { $commonServicesURL = $this->apiConfig['commonServicesURL']; $commonApiVersion = $this->apiConfig['commonApiVersion']; @@ -148,7 +148,7 @@ class UserService { $endpoint = $commonApiVersion . '/emails/' . $email; $url = $commonServicesURL . $endpoint; // DELETE /v2/emails/@email - $this->logger->info("deleteMailFolder for URL ".$url); + $params = []; $token = $this->apiConfig['commonServicesToken']; -- GitLab