diff --git a/lib/Listeners/BeforeUserDeletedListener.php b/lib/Listeners/BeforeUserDeletedListener.php index 66d483d653860f5dac14534cd3df8da1b0596a32..aa4a21eb8401d6ea24d4234b9abd407153df3a04 100644 --- a/lib/Listeners/BeforeUserDeletedListener.php +++ b/lib/Listeners/BeforeUserDeletedListener.php @@ -45,15 +45,12 @@ 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 - ); - + try { + $this->logger->info("PostDelete user {user}", array('user' => $uid)); + $this->userService->deleteEmailAccount($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 221cae5cfcd1bf154097c257a802f173c5ebfe71..d8995194dd49a64bcd857b47f827cf9accfb8216 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 deleteEmailAccount(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 + + $params = []; + + $token = $this->apiConfig['commonServicesToken']; + $headers = [ + "Authorization: Bearer $token" + ]; + + $this->curl->delete($url, $params, $headers); - 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]); + if ($this->curl->getLastStatusCode() !== 200) { + throw new Exception('Error deleting mail folder of' . $email . '. Status Code: '.$this->curl->getLastStatusCode()); } - - return null; } public function sendWelcomeEmail(string $displayname, string $username, string $userEmail, string $language = 'en') : void {