Loading lib/Listeners/BeforeUserDeletedListener.php +6 −9 Original line number Diff line number Diff line Loading @@ -45,15 +45,12 @@ class BeforeUserDeletedListener implements IEventListener { $isUserOnLDAP = $this->LDAPConnectionService->isUserOnLDAPBackend($user); try { $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->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(); Loading lib/Service/UserService.php +19 −22 Original line number Diff line number Diff line Loading @@ -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 $endpoint = $commonApiVersion . '/emails/' . $email; $url = $commonServicesURL . $endpoint; // DELETE /v2/emails/@email $params = []; $token = $this->apiConfig['commonServicesToken']; $headers = [ "Authorization: Bearer $token" ]; $answer = $this->curl->post($postDeleteUrl, $params); $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 { Loading Loading
lib/Listeners/BeforeUserDeletedListener.php +6 −9 Original line number Diff line number Diff line Loading @@ -45,15 +45,12 @@ class BeforeUserDeletedListener implements IEventListener { $isUserOnLDAP = $this->LDAPConnectionService->isUserOnLDAPBackend($user); try { $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->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(); Loading
lib/Service/UserService.php +19 −22 Original line number Diff line number Diff line Loading @@ -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 $endpoint = $commonApiVersion . '/emails/' . $email; $url = $commonServicesURL . $endpoint; // DELETE /v2/emails/@email $params = []; $token = $this->apiConfig['commonServicesToken']; $headers = [ "Authorization: Bearer $token" ]; $answer = $this->curl->post($postDeleteUrl, $params); $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 { Loading