From f2abca419d7821a477dc8c483b6c07fba98accad Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 19 Jun 2024 10:23:57 +0530 Subject: [PATCH 01/41] resolved conflicts --- lib/Service/UserService.php | 38 ++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 1b8d5f46..6113c1de 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -12,6 +12,8 @@ use OCA\EcloudAccounts\Exception\AddUsernameToCommonStoreException; use OCA\EcloudAccounts\Exception\BlacklistedEmailException; use OCA\EcloudAccounts\Exception\LDAPUserCreationException; use OCP\Defaults; +use OCP\Files\IAppData; +use OCP\Files\NotFoundException; use OCP\IConfig; use OCP\ILogger; use OCP\IUser; @@ -41,8 +43,12 @@ class UserService { private $apiConfig; /** @var LDAPConnectionService */ private $LDAPConnectionService; + /** + * @var IAppData + */ + private $appData; - public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger, Defaults $defaults, IFactory $l10nFactory, LDAPConnectionService $LDAPConnectionService) { + public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger, Defaults $defaults, IFactory $l10nFactory, LDAPConnectionService $LDAPConnectionService, IAppData $appData) { $this->userManager = $userManager; $this->config = $config; $this->appConfig = $this->config->getSystemValue($appName); @@ -51,6 +57,7 @@ class UserService { $this->defaults = $defaults; $this->l10nFactory = $l10nFactory; $this->LDAPConnectionService = $LDAPConnectionService; + $this->appData = $appData; $commonServiceURL = $this->config->getSystemValue('common_services_url', ''); if (!empty($commonServiceURL)) { @@ -585,4 +592,33 @@ class UserService { private function getDefaultQuota() { return $this->config->getSystemValueInt('default_quota_in_megabytes', 1024); } + public function updateBlacklistedDomains() { + $blacklisted_domain_url = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; + $json_data = file_get_contents($blacklisted_domain_url); + $filename = 'blacklisted_domains.json'; + $this->setBlacklistedDomainFile($filename, $json_data); + } + private function getBlacklistedDomainFolder() { + try { + return $this->appData->getFolder('blacklisted_domains'); + } catch (NotFoundException $e) { + return $this->appData->newFolder('blacklisted_domains'); + } + } + /** + * Store a file for theming in AppData + * + * @param string $filename + * @param string $data + */ + private function setBlacklistedDomainFile(string $filename, string $data) { + $currentFolder = $this->getBlacklistedDomainFolder(); + if ($currentFolder->fileExists($filename)) { + $file = $currentFolder->getFile($filename); + } else { + $file = $currentFolder->newFile($filename); + } + $file->putContent($data); + return $file; + } } -- GitLab From c6e86d069aac1ab011b4b0e731e081629012d650 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 18 Jun 2024 14:21:14 +0530 Subject: [PATCH 02/41] Storing blacklisted domains in appdata --- lib/Service/UserService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 6113c1de..3d2f28ba 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -596,7 +596,7 @@ class UserService { $blacklisted_domain_url = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; $json_data = file_get_contents($blacklisted_domain_url); $filename = 'blacklisted_domains.json'; - $this->setBlacklistedDomainFile($filename, $json_data); + $this->setBlacklistedDomainData($filename, $json_data); } private function getBlacklistedDomainFolder() { try { @@ -611,7 +611,7 @@ class UserService { * @param string $filename * @param string $data */ - private function setBlacklistedDomainFile(string $filename, string $data) { + private function setBlacklistedDomainData(string $filename, string $data) { $currentFolder = $this->getBlacklistedDomainFolder(); if ($currentFolder->fileExists($filename)) { $file = $currentFolder->getFile($filename); -- GitLab From 5cf2a1856b126bddfdefccdfaac75cbc1d3a1d4a Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 18 Jun 2024 14:40:30 +0530 Subject: [PATCH 03/41] blacklisted domains --- lib/Service/UserService.php | 53 ++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 3d2f28ba..e39946d8 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -47,6 +47,8 @@ class UserService { * @var IAppData */ private $appData; + public const BLACKLISTED_DOMAIN_FOLDER_NAME = 'blacklisted_domains'; + public const BLACKLISTED_DOMAIN_FILE_NAME = 'blacklisted_domains.json'; public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger, Defaults $defaults, IFactory $l10nFactory, LDAPConnectionService $LDAPConnectionService, IAppData $appData) { $this->userManager = $userManager; @@ -293,7 +295,7 @@ class UserService { */ public function isBlacklistedEmail(string $email): bool { // Get the blacklisted domains from configuration - $blacklistedDomainsInJson = $this->config->getAppValue(Application::APP_ID, 'blacklisted_domains'); + $blacklistedDomainsInJson = $this->getBlacklistedDomainData(); if (empty($blacklistedDomainsInJson)) { return false; } @@ -592,33 +594,52 @@ class UserService { private function getDefaultQuota() { return $this->config->getSystemValueInt('default_quota_in_megabytes', 1024); } - public function updateBlacklistedDomains() { + public function updateBlacklistedDomains(): void { $blacklisted_domain_url = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; $json_data = file_get_contents($blacklisted_domain_url); - $filename = 'blacklisted_domains.json'; - $this->setBlacklistedDomainData($filename, $json_data); + $this->setBlacklistedDomainsData($json_data); } - private function getBlacklistedDomainFolder() { + /** + * Get or create the folder for storing blacklisted domain data. + * + */ + private function getBlacklistedDomainsFolder() { + $foldername = self::BLACKLISTED_DOMAIN_FOLDER_NAME; try { - return $this->appData->getFolder('blacklisted_domains'); + return $this->appData->getFolder($foldername); } catch (NotFoundException $e) { - return $this->appData->newFolder('blacklisted_domains'); + return $this->appData->newFolder($foldername); } } + + /** + * Store blacklisted domain data in a file within AppData. + * + * @param string $data The data to be stored in the file. + */ + private function setBlacklistedDomainsData(string $data) { + $file = $this->getBlacklistedDomainsFilePath(); + $file->putContent($data); + return $file; + } + /** + * Get blacklisted domain data. + * + */ + private function getBlacklistedDomainData() { + return $this->getBlacklistedDomainsFilePath(); + } /** - * Store a file for theming in AppData + * Fetch the contents of a file from a given URL. * - * @param string $filename - * @param string $data */ - private function setBlacklistedDomainData(string $filename, string $data) { - $currentFolder = $this->getBlacklistedDomainFolder(); + private function getBlacklistedDomainsFilePath() { + $filename = self::BLACKLISTED_DOMAIN_FILE_NAME; + $currentFolder = $this->getBlacklistedDomainsFolder(); if ($currentFolder->fileExists($filename)) { - $file = $currentFolder->getFile($filename); + return $currentFolder->getFile($filename); } else { - $file = $currentFolder->newFile($filename); + return $currentFolder->newFile($filename); } - $file->putContent($data); - return $file; } } -- GitLab From 704a767f53d2ab61da1f47157e12c0629290fc50 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Tue, 18 Jun 2024 14:44:09 +0530 Subject: [PATCH 04/41] blacklisted domains --- lib/Service/UserService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index e39946d8..0b755049 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -47,8 +47,8 @@ class UserService { * @var IAppData */ private $appData; - public const BLACKLISTED_DOMAIN_FOLDER_NAME = 'blacklisted_domains'; - public const BLACKLISTED_DOMAIN_FILE_NAME = 'blacklisted_domains.json'; + public const BLACKLISTED_DOMAINS_FOLDER_NAME = 'blacklisted_domains'; + public const BLACKLISTED_DOMAINS_FILE_NAME = 'blacklisted_domains.json'; public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger, Defaults $defaults, IFactory $l10nFactory, LDAPConnectionService $LDAPConnectionService, IAppData $appData) { $this->userManager = $userManager; @@ -604,7 +604,7 @@ class UserService { * */ private function getBlacklistedDomainsFolder() { - $foldername = self::BLACKLISTED_DOMAIN_FOLDER_NAME; + $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; try { return $this->appData->getFolder($foldername); } catch (NotFoundException $e) { @@ -634,7 +634,7 @@ class UserService { * */ private function getBlacklistedDomainsFilePath() { - $filename = self::BLACKLISTED_DOMAIN_FILE_NAME; + $filename = self::BLACKLISTED_DOMAINS_FILE_NAME; $currentFolder = $this->getBlacklistedDomainsFolder(); if ($currentFolder->fileExists($filename)) { return $currentFolder->getFile($filename); -- GitLab From 524e4791faa8a208fcb0fb8c94db33b842d4ac04 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 19 Jun 2024 10:25:36 +0530 Subject: [PATCH 05/41] added command --- appinfo/info.xml | 1 + lib/Command/UpdateBlacklistedDomains.php | 30 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 lib/Command/UpdateBlacklistedDomains.php diff --git a/appinfo/info.xml b/appinfo/info.xml index e6f7fd12..b3a4c439 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -25,6 +25,7 @@ OCA\EcloudAccounts\Settings\BetaSection + OCA\EcloudAccounts\Command\UpdateBlacklistedDomains OCA\EcloudAccounts\Command\Migrate2FASecrets OCA\EcloudAccounts\Command\MigrateWebmailAddressbooks OCA\EcloudAccounts\Command\MapActiveAttributetoLDAP diff --git a/lib/Command/UpdateBlacklistedDomains.php b/lib/Command/UpdateBlacklistedDomains.php new file mode 100644 index 00000000..8b51a28a --- /dev/null +++ b/lib/Command/UpdateBlacklistedDomains.php @@ -0,0 +1,30 @@ +userService = $userService; + } + + protected function configure() { + $this->setName(Application::APP_ID.':update-blacklisted-domains')->setDescription('Update blacklisted domains'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + $this->userService->updateBlacklistedDomains(); + $output->writeln('Updated blacklisted domains for creation.'); + return 1; + } +} -- GitLab From 3772491b0ffa462909da7474cfd24295fae1c7e5 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 19 Jun 2024 10:28:18 +0530 Subject: [PATCH 06/41] changed folder name --- 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 0b755049..ed99205c 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -47,7 +47,7 @@ class UserService { * @var IAppData */ private $appData; - public const BLACKLISTED_DOMAINS_FOLDER_NAME = 'blacklisted_domains'; + public const BLACKLISTED_DOMAINS_FOLDER_NAME = 'ecloud-accounts'; public const BLACKLISTED_DOMAINS_FILE_NAME = 'blacklisted_domains.json'; public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger, Defaults $defaults, IFactory $l10nFactory, LDAPConnectionService $LDAPConnectionService, IAppData $appData) { -- GitLab From 9d40a8084a13e85b6e725c066b097bd23479c2c6 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 19 Jun 2024 13:05:06 +0530 Subject: [PATCH 07/41] change in conditions --- lib/Service/UserService.php | 47 +++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index ed99205c..7752cd89 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -295,6 +295,9 @@ class UserService { */ public function isBlacklistedEmail(string $email): bool { // Get the blacklisted domains from configuration + if (!$this->ensureDocumentsFolder()) { + return false; + } $blacklistedDomainsInJson = $this->getBlacklistedDomainData(); if (empty($blacklistedDomainsInJson)) { return false; @@ -599,18 +602,6 @@ class UserService { $json_data = file_get_contents($blacklisted_domain_url); $this->setBlacklistedDomainsData($json_data); } - /** - * Get or create the folder for storing blacklisted domain data. - * - */ - private function getBlacklistedDomainsFolder() { - $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; - try { - return $this->appData->getFolder($foldername); - } catch (NotFoundException $e) { - return $this->appData->newFolder($foldername); - } - } /** * Store blacklisted domain data in a file within AppData. @@ -622,24 +613,40 @@ class UserService { $file->putContent($data); return $file; } - /** - * Get blacklisted domain data. - * - */ - private function getBlacklistedDomainData() { - return $this->getBlacklistedDomainsFilePath(); - } /** * Fetch the contents of a file from a given URL. * */ private function getBlacklistedDomainsFilePath() { + $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; + try { + $currentFolder = $this->appData->getFolder($foldername); + } catch (NotFoundException $e) { + $currentFolder = $this->appData->newFolder($foldername); + } $filename = self::BLACKLISTED_DOMAINS_FILE_NAME; - $currentFolder = $this->getBlacklistedDomainsFolder(); if ($currentFolder->fileExists($filename)) { return $currentFolder->getFile($filename); } else { return $currentFolder->newFile($filename); } } + public function getBlacklistedDomainData() { + $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; + $document = self::BLACKLISTED_DOMAINS_FILE_NAME; + return $this->appData->getFolder($foldername)->getFile((string) $document); + } + private function ensureDocumentsFolder(): bool { + $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; + try { + $this->appData->getFolder($foldername); + } catch (NotFoundException $e) { + $this->logger->logException($e); + return false; + } catch (\RuntimeException $e) { + $this->logger->logException($e); + return false; + } + return true; + } } -- GitLab From b9d0394a51c6fc1e9b780d17c8d22c6f8a38f1af Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 19 Jun 2024 13:11:52 +0530 Subject: [PATCH 08/41] change in conditions --- lib/Service/UserService.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 7752cd89..1fa9ba70 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -47,8 +47,9 @@ class UserService { * @var IAppData */ private $appData; - public const BLACKLISTED_DOMAINS_FOLDER_NAME = 'ecloud-accounts'; - public const BLACKLISTED_DOMAINS_FILE_NAME = 'blacklisted_domains.json'; + private const BLACKLISTED_DOMAINS_FOLDER_NAME = 'ecloud-accounts'; + private const BLACKLISTED_DOMAINS_FILE_NAME = 'blacklisted_domains.json'; + private const BLACKLISTED_DOMAINS_URL = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger, Defaults $defaults, IFactory $l10nFactory, LDAPConnectionService $LDAPConnectionService, IAppData $appData) { $this->userManager = $userManager; @@ -598,7 +599,7 @@ class UserService { return $this->config->getSystemValueInt('default_quota_in_megabytes', 1024); } public function updateBlacklistedDomains(): void { - $blacklisted_domain_url = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; + $blacklisted_domain_url = self::BLACKLISTED_DOMAINS_URL; $json_data = file_get_contents($blacklisted_domain_url); $this->setBlacklistedDomainsData($json_data); } @@ -626,10 +627,9 @@ class UserService { } $filename = self::BLACKLISTED_DOMAINS_FILE_NAME; if ($currentFolder->fileExists($filename)) { - return $currentFolder->getFile($filename); - } else { - return $currentFolder->newFile($filename); + $currentFolder->getFile($filename)->delete(); } + return $currentFolder->newFile($filename); } public function getBlacklistedDomainData() { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; @@ -641,7 +641,7 @@ class UserService { try { $this->appData->getFolder($foldername); } catch (NotFoundException $e) { - $this->logger->logException($e); + $this->logger->logException('Blacklisted domains file not found!'); return false; } catch (\RuntimeException $e) { $this->logger->logException($e); -- GitLab From ed6cc0af7eaf9fca601d3308b369c17331da896e Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 19 Jun 2024 13:14:19 +0530 Subject: [PATCH 09/41] change in conditions --- lib/Service/UserService.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 1fa9ba70..f1c24ced 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -598,12 +598,15 @@ class UserService { private function getDefaultQuota() { return $this->config->getSystemValueInt('default_quota_in_megabytes', 1024); } + /** + * update the blacklisted domains file. + * + */ public function updateBlacklistedDomains(): void { $blacklisted_domain_url = self::BLACKLISTED_DOMAINS_URL; $json_data = file_get_contents($blacklisted_domain_url); $this->setBlacklistedDomainsData($json_data); } - /** * Store blacklisted domain data in a file within AppData. * @@ -615,7 +618,7 @@ class UserService { return $file; } /** - * Fetch the contents of a file from a given URL. + * Retrieve the blacklisted domain file path * */ private function getBlacklistedDomainsFilePath() { @@ -631,11 +634,19 @@ class UserService { } return $currentFolder->newFile($filename); } + /** + * Retrieve the blacklisted domain data. + * + */ public function getBlacklistedDomainData() { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; $document = self::BLACKLISTED_DOMAINS_FILE_NAME; return $this->appData->getFolder($foldername)->getFile((string) $document); } + /** + * Ensure the specified folder exists within AppData. + * + */ private function ensureDocumentsFolder(): bool { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; try { -- GitLab From 9e85456f6db003f1ff8ac6841c4b5de2dbf9e6e1 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 19 Jun 2024 13:20:16 +0530 Subject: [PATCH 10/41] test --- lib/Service/UserService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index f1c24ced..7b0e916f 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -605,6 +605,7 @@ class UserService { public function updateBlacklistedDomains(): void { $blacklisted_domain_url = self::BLACKLISTED_DOMAINS_URL; $json_data = file_get_contents($blacklisted_domain_url); + $json_data = '[{\'test\':\'test1\'}]'; $this->setBlacklistedDomainsData($json_data); } /** -- GitLab From f296112470d52fe3c42c70fc0b32d143f01e6bcb Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 19 Jun 2024 13:29:52 +0530 Subject: [PATCH 11/41] test #1 --- 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 7b0e916f..b80e9aa5 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -631,7 +631,7 @@ class UserService { } $filename = self::BLACKLISTED_DOMAINS_FILE_NAME; if ($currentFolder->fileExists($filename)) { - $currentFolder->getFile($filename)->delete(); + return $currentFolder->getFile($filename); } return $currentFolder->newFile($filename); } -- GitLab From e9af14a35e814b429c11a70a8c6400bab3fdc8b0 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 19 Jun 2024 13:32:38 +0530 Subject: [PATCH 12/41] test #1 --- 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 b80e9aa5..bead03b0 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -605,7 +605,7 @@ class UserService { public function updateBlacklistedDomains(): void { $blacklisted_domain_url = self::BLACKLISTED_DOMAINS_URL; $json_data = file_get_contents($blacklisted_domain_url); - $json_data = '[{\'test\':\'test1\'}]'; + $json_data = '[{\'test\':\'test2\'}]'; $this->setBlacklistedDomainsData($json_data); } /** -- GitLab From aba73da622b415a92929a5c69aaaebb228ffbec9 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 19 Jun 2024 13:35:51 +0530 Subject: [PATCH 13/41] added original file --- lib/Service/UserService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index bead03b0..8a7143fc 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -605,7 +605,6 @@ class UserService { public function updateBlacklistedDomains(): void { $blacklisted_domain_url = self::BLACKLISTED_DOMAINS_URL; $json_data = file_get_contents($blacklisted_domain_url); - $json_data = '[{\'test\':\'test2\'}]'; $this->setBlacklistedDomainsData($json_data); } /** -- GitLab From d42ef470709bcff7b4974cc44e1b9d3120cfe216 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Wed, 19 Jun 2024 13:46:14 +0530 Subject: [PATCH 14/41] getcontent --- lib/Service/UserService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 8a7143fc..a8abcbd7 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -304,7 +304,7 @@ class UserService { return false; } $blacklistedDomains = json_decode($blacklistedDomainsInJson, true); - + if (empty($blacklistedDomains)) { return false; } @@ -641,7 +641,7 @@ class UserService { public function getBlacklistedDomainData() { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; $document = self::BLACKLISTED_DOMAINS_FILE_NAME; - return $this->appData->getFolder($foldername)->getFile((string) $document); + return $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); } /** * Ensure the specified folder exists within AppData. -- GitLab From 239e26860d1a824cf0c5ae50852def6ef100c53c Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 07:48:38 +0530 Subject: [PATCH 15/41] added changes --- lib/Service/UserService.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index a8abcbd7..7d1a7775 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -641,7 +641,13 @@ class UserService { public function getBlacklistedDomainData() { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; $document = self::BLACKLISTED_DOMAINS_FILE_NAME; - return $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); + try { + return $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); + } catch (NotFoundException $e) { + $this->logger->logException('Blacklisted domains file '.$document.' not found!'); + return []; + } + } /** * Ensure the specified folder exists within AppData. @@ -652,7 +658,7 @@ class UserService { try { $this->appData->getFolder($foldername); } catch (NotFoundException $e) { - $this->logger->logException('Blacklisted domains file not found!'); + $this->logger->logException('Blacklisted domains folder '.$foldername.' not found!'); return false; } catch (\RuntimeException $e) { $this->logger->logException($e); -- GitLab From c624838c78385611b2ad80926f28a5ecb3eadfc5 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 07:52:42 +0530 Subject: [PATCH 16/41] added changes --- lib/Service/UserService.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 7d1a7775..37ff9f6e 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -299,12 +299,7 @@ class UserService { if (!$this->ensureDocumentsFolder()) { return false; } - $blacklistedDomainsInJson = $this->getBlacklistedDomainData(); - if (empty($blacklistedDomainsInJson)) { - return false; - } - $blacklistedDomains = json_decode($blacklistedDomainsInJson, true); - + $blacklistedDomains = $this->getBlacklistedDomainData(); if (empty($blacklistedDomains)) { return false; } @@ -642,7 +637,11 @@ class UserService { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; $document = self::BLACKLISTED_DOMAINS_FILE_NAME; try { - return $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); + $blacklistedDomainsInJson = $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); + if (empty($blacklistedDomainsInJson)) { + return []; + } + return json_decode($blacklistedDomainsInJson, true); } catch (NotFoundException $e) { $this->logger->logException('Blacklisted domains file '.$document.' not found!'); return []; -- GitLab From 5f2fd90ad2d7a38ba169f34ec32dffdedb984e29 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 09:32:44 +0530 Subject: [PATCH 17/41] changes --- lib/Command/UpdateBlacklistedDomains.php | 8 ++++++-- lib/Service/UserService.php | 17 ++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/Command/UpdateBlacklistedDomains.php b/lib/Command/UpdateBlacklistedDomains.php index 8b51a28a..5ccb9bdf 100644 --- a/lib/Command/UpdateBlacklistedDomains.php +++ b/lib/Command/UpdateBlacklistedDomains.php @@ -23,8 +23,12 @@ class UpdateBlacklistedDomains extends Command { } protected function execute(InputInterface $input, OutputInterface $output): int { - $this->userService->updateBlacklistedDomains(); - $output->writeln('Updated blacklisted domains for creation.'); + try { + $this->userService->updateBlacklistedDomains(); + $output->writeln('Updated blacklisted domains for creation.'); + } catch (\Throwable $th) { + $output->writeln('Error while updating blacklisted domains. Error: '.$th->getMessage()); + } return 1; } } diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 37ff9f6e..39d4acee 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -14,6 +14,7 @@ use OCA\EcloudAccounts\Exception\LDAPUserCreationException; use OCP\Defaults; use OCP\Files\IAppData; use OCP\Files\NotFoundException; +use OCP\Files\SimpleFS\ISimpleFile; use OCP\IConfig; use OCP\ILogger; use OCP\IUser; @@ -43,11 +44,8 @@ class UserService { private $apiConfig; /** @var LDAPConnectionService */ private $LDAPConnectionService; - /** - * @var IAppData - */ - private $appData; - private const BLACKLISTED_DOMAINS_FOLDER_NAME = 'ecloud-accounts'; + private IAppData $appData; + private const BLACKLISTED_DOMAINS_FOLDER_NAME = Application::APP_ID; private const BLACKLISTED_DOMAINS_FILE_NAME = 'blacklisted_domains.json'; private const BLACKLISTED_DOMAINS_URL = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; @@ -607,16 +605,16 @@ class UserService { * * @param string $data The data to be stored in the file. */ - private function setBlacklistedDomainsData(string $data) { + private function setBlacklistedDomainsData(string $data): void { $file = $this->getBlacklistedDomainsFilePath(); $file->putContent($data); - return $file; } /** * Retrieve the blacklisted domain file path * + * @return ISimpleFile */ - private function getBlacklistedDomainsFilePath() { + private function getBlacklistedDomainsFilePath(): ISimpleFile { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; try { $currentFolder = $this->appData->getFolder($foldername); @@ -632,8 +630,9 @@ class UserService { /** * Retrieve the blacklisted domain data. * + * @return array The array of blacklisted domains. */ - public function getBlacklistedDomainData() { + public function getBlacklistedDomainData(): array { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; $document = self::BLACKLISTED_DOMAINS_FILE_NAME; try { -- GitLab From 57b5291690448df423fa7a74d5ab7fe858194b1a Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 09:45:34 +0530 Subject: [PATCH 18/41] removed return type --- lib/Service/UserService.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 39d4acee..e8531ea4 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -612,9 +612,8 @@ class UserService { /** * Retrieve the blacklisted domain file path * - * @return ISimpleFile */ - private function getBlacklistedDomainsFilePath(): ISimpleFile { + private function getBlacklistedDomainsFilePath() { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; try { $currentFolder = $this->appData->getFolder($foldername); -- GitLab From 47fd97f6d775a003025db43c85a4dbdce0b4dfa5 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 09:46:23 +0530 Subject: [PATCH 19/41] removed return type --- lib/Service/UserService.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index e8531ea4..8626c09c 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -14,7 +14,6 @@ use OCA\EcloudAccounts\Exception\LDAPUserCreationException; use OCP\Defaults; use OCP\Files\IAppData; use OCP\Files\NotFoundException; -use OCP\Files\SimpleFS\ISimpleFile; use OCP\IConfig; use OCP\ILogger; use OCP\IUser; -- GitLab From b1ea83fccf3b38e12c930f1d20024637936bbad5 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 10:16:08 +0530 Subject: [PATCH 20/41] fetch --- lib/Service/UserService.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 8626c09c..cae850aa 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -591,14 +591,25 @@ class UserService { return $this->config->getSystemValueInt('default_quota_in_megabytes', 1024); } /** - * update the blacklisted domains file. + * Update the blacklisted domains data by fetching it from a URL and saving it locally. * + * @return void */ public function updateBlacklistedDomains(): void { $blacklisted_domain_url = self::BLACKLISTED_DOMAINS_URL; - $json_data = file_get_contents($blacklisted_domain_url); - $this->setBlacklistedDomainsData($json_data); + try { + $json_data = file_get_contents($blacklisted_domain_url); + if ($json_data === false) { + $this->logger->error("Failed to fetch data from URL: $blacklisted_domain_url"); + throw new \RuntimeException("Failed to fetch data from URL: $blacklisted_domain_url"); + } + $this->setBlacklistedDomainsData($json_data); + } catch (Exception $e) { + // Log any exceptions that occur during the process + $this->logger->logException($e, ['message' => 'Failed to update blacklisted domains.']); + } } + /** * Store blacklisted domain data in a file within AppData. * -- GitLab From 2f9b347990e9db76a48a15bc6761753fbd8b1324 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 10:34:47 +0530 Subject: [PATCH 21/41] logger changes --- lib/Service/UserService.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index cae850aa..a0fdbcec 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -651,7 +651,7 @@ class UserService { } return json_decode($blacklistedDomainsInJson, true); } catch (NotFoundException $e) { - $this->logger->logException('Blacklisted domains file '.$document.' not found!'); + $this->logger->error('Blacklisted domains file '.$document.' not found!'); return []; } @@ -663,12 +663,14 @@ class UserService { private function ensureDocumentsFolder(): bool { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; try { + $this->logger->error('Blacklisted domains folder found!'); $this->appData->getFolder($foldername); } catch (NotFoundException $e) { - $this->logger->logException('Blacklisted domains folder '.$foldername.' not found!'); + $this->logger->error('Blacklisted domains folder '.$foldername.' not found!'); return false; } catch (\RuntimeException $e) { - $this->logger->logException($e); + $this->logger->error('Blacklisted domains folder not found!'); + $this->logger->error($e); return false; } return true; -- GitLab From 08ffb155c8b481a72297b342dcf4ec456fe2e6dc Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 10:51:20 +0530 Subject: [PATCH 22/41] changed folder path --- lib/Service/UserService.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index a0fdbcec..d068272b 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -44,7 +44,7 @@ class UserService { /** @var LDAPConnectionService */ private $LDAPConnectionService; private IAppData $appData; - private const BLACKLISTED_DOMAINS_FOLDER_NAME = Application::APP_ID; + private const BLACKLISTED_DOMAINS_FOLDER_NAME = '/'; private const BLACKLISTED_DOMAINS_FILE_NAME = 'blacklisted_domains.json'; private const BLACKLISTED_DOMAINS_URL = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; @@ -663,7 +663,6 @@ class UserService { private function ensureDocumentsFolder(): bool { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; try { - $this->logger->error('Blacklisted domains folder found!'); $this->appData->getFolder($foldername); } catch (NotFoundException $e) { $this->logger->error('Blacklisted domains folder '.$foldername.' not found!'); @@ -673,6 +672,7 @@ class UserService { $this->logger->error($e); return false; } + $this->logger->error('Blacklisted domains folder found!'); return true; } } -- GitLab From a148eb1c62093f8f9a4e01f003996a8481ec7fdd Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 11:01:33 +0530 Subject: [PATCH 23/41] changed folder path # --- 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 d068272b..fcbde839 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -44,7 +44,7 @@ class UserService { /** @var LDAPConnectionService */ private $LDAPConnectionService; private IAppData $appData; - private const BLACKLISTED_DOMAINS_FOLDER_NAME = '/'; + private const BLACKLISTED_DOMAINS_FOLDER_NAME = Application::APP_ID; private const BLACKLISTED_DOMAINS_FILE_NAME = 'blacklisted_domains.json'; private const BLACKLISTED_DOMAINS_URL = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; -- GitLab From e4bff5745ee795cf6a8439fb52dcbe5be9450207 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 11:07:40 +0530 Subject: [PATCH 24/41] changed folder path # --- lib/Command/UpdateBlacklistedDomains.php | 2 +- lib/Service/UserService.php | 13 ++----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/lib/Command/UpdateBlacklistedDomains.php b/lib/Command/UpdateBlacklistedDomains.php index 5ccb9bdf..27434981 100644 --- a/lib/Command/UpdateBlacklistedDomains.php +++ b/lib/Command/UpdateBlacklistedDomains.php @@ -27,7 +27,7 @@ class UpdateBlacklistedDomains extends Command { $this->userService->updateBlacklistedDomains(); $output->writeln('Updated blacklisted domains for creation.'); } catch (\Throwable $th) { - $output->writeln('Error while updating blacklisted domains. Error: '.$th->getMessage()); + $output->writeln('Error while updating blacklisted domains.'); } return 1; } diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index fcbde839..2eafcda7 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -597,17 +597,8 @@ class UserService { */ public function updateBlacklistedDomains(): void { $blacklisted_domain_url = self::BLACKLISTED_DOMAINS_URL; - try { - $json_data = file_get_contents($blacklisted_domain_url); - if ($json_data === false) { - $this->logger->error("Failed to fetch data from URL: $blacklisted_domain_url"); - throw new \RuntimeException("Failed to fetch data from URL: $blacklisted_domain_url"); - } - $this->setBlacklistedDomainsData($json_data); - } catch (Exception $e) { - // Log any exceptions that occur during the process - $this->logger->logException($e, ['message' => 'Failed to update blacklisted domains.']); - } + $json_data = file_get_contents($blacklisted_domain_url); + $this->setBlacklistedDomainsData($json_data); } /** -- GitLab From 5cd0849e413760bd0050cd8cfbc5f78accf21572 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 11:16:23 +0530 Subject: [PATCH 25/41] changed folder path # --- lib/Service/UserService.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 2eafcda7..027329f6 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -619,6 +619,7 @@ class UserService { try { $currentFolder = $this->appData->getFolder($foldername); } catch (NotFoundException $e) { + $this->logger->error('Folder '.$foldername.' not found!'); $currentFolder = $this->appData->newFolder($foldername); } $filename = self::BLACKLISTED_DOMAINS_FILE_NAME; -- GitLab From 61efaeca50e7c7c9b1742cdc6eb1e9b2c0c170ff Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 11:20:55 +0530 Subject: [PATCH 26/41] reverted --- lib/Service/UserService.php | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 027329f6..6d8c745c 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -591,24 +591,23 @@ class UserService { return $this->config->getSystemValueInt('default_quota_in_megabytes', 1024); } /** - * Update the blacklisted domains data by fetching it from a URL and saving it locally. + * update the blacklisted domains file. * - * @return void */ public function updateBlacklistedDomains(): void { $blacklisted_domain_url = self::BLACKLISTED_DOMAINS_URL; $json_data = file_get_contents($blacklisted_domain_url); $this->setBlacklistedDomainsData($json_data); } - /** * Store blacklisted domain data in a file within AppData. * * @param string $data The data to be stored in the file. */ - private function setBlacklistedDomainsData(string $data): void { + private function setBlacklistedDomainsData(string $data) { $file = $this->getBlacklistedDomainsFilePath(); $file->putContent($data); + return $file; } /** * Retrieve the blacklisted domain file path @@ -619,7 +618,6 @@ class UserService { try { $currentFolder = $this->appData->getFolder($foldername); } catch (NotFoundException $e) { - $this->logger->error('Folder '.$foldername.' not found!'); $currentFolder = $this->appData->newFolder($foldername); } $filename = self::BLACKLISTED_DOMAINS_FILE_NAME; @@ -631,22 +629,11 @@ class UserService { /** * Retrieve the blacklisted domain data. * - * @return array The array of blacklisted domains. */ - public function getBlacklistedDomainData(): array { + public function getBlacklistedDomainData() { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; $document = self::BLACKLISTED_DOMAINS_FILE_NAME; - try { - $blacklistedDomainsInJson = $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); - if (empty($blacklistedDomainsInJson)) { - return []; - } - return json_decode($blacklistedDomainsInJson, true); - } catch (NotFoundException $e) { - $this->logger->error('Blacklisted domains file '.$document.' not found!'); - return []; - } - + return $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); } /** * Ensure the specified folder exists within AppData. @@ -657,14 +644,12 @@ class UserService { try { $this->appData->getFolder($foldername); } catch (NotFoundException $e) { - $this->logger->error('Blacklisted domains folder '.$foldername.' not found!'); + $this->logger->logException('Blacklisted domains file not found!'); return false; } catch (\RuntimeException $e) { - $this->logger->error('Blacklisted domains folder not found!'); - $this->logger->error($e); + $this->logger->logException($e); return false; } - $this->logger->error('Blacklisted domains folder found!'); return true; } } -- GitLab From 8b058dbc58648df3390ce681a89df797e4e09771 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 11:28:08 +0530 Subject: [PATCH 27/41] renamed folder name --- 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 6d8c745c..f751cb9a 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -44,7 +44,7 @@ class UserService { /** @var LDAPConnectionService */ private $LDAPConnectionService; private IAppData $appData; - private const BLACKLISTED_DOMAINS_FOLDER_NAME = Application::APP_ID; + private const BLACKLISTED_DOMAINS_FOLDER_NAME = 'data'; private const BLACKLISTED_DOMAINS_FILE_NAME = 'blacklisted_domains.json'; private const BLACKLISTED_DOMAINS_URL = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; -- GitLab From 2fd4e4984e398eb78fe32be521809334f20e9274 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 12:05:48 +0530 Subject: [PATCH 28/41] reverted code --- lib/Service/UserService.php | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index f751cb9a..65afb894 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -44,7 +44,7 @@ class UserService { /** @var LDAPConnectionService */ private $LDAPConnectionService; private IAppData $appData; - private const BLACKLISTED_DOMAINS_FOLDER_NAME = 'data'; + private const BLACKLISTED_DOMAINS_FOLDER_NAME = Application::APP_ID; private const BLACKLISTED_DOMAINS_FILE_NAME = 'blacklisted_domains.json'; private const BLACKLISTED_DOMAINS_URL = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; @@ -591,23 +591,24 @@ class UserService { return $this->config->getSystemValueInt('default_quota_in_megabytes', 1024); } /** - * update the blacklisted domains file. + * Update the blacklisted domains data by fetching it from a URL and saving it locally. * + * @return void */ public function updateBlacklistedDomains(): void { $blacklisted_domain_url = self::BLACKLISTED_DOMAINS_URL; $json_data = file_get_contents($blacklisted_domain_url); $this->setBlacklistedDomainsData($json_data); } + /** * Store blacklisted domain data in a file within AppData. * * @param string $data The data to be stored in the file. */ - private function setBlacklistedDomainsData(string $data) { + private function setBlacklistedDomainsData(string $data): void { $file = $this->getBlacklistedDomainsFilePath(); $file->putContent($data); - return $file; } /** * Retrieve the blacklisted domain file path @@ -618,6 +619,7 @@ class UserService { try { $currentFolder = $this->appData->getFolder($foldername); } catch (NotFoundException $e) { + $this->logger->error('Folder '.$foldername.' not found!'); $currentFolder = $this->appData->newFolder($foldername); } $filename = self::BLACKLISTED_DOMAINS_FILE_NAME; @@ -629,11 +631,22 @@ class UserService { /** * Retrieve the blacklisted domain data. * + * @return array The array of blacklisted domains. */ - public function getBlacklistedDomainData() { + public function getBlacklistedDomainData(): array { $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; $document = self::BLACKLISTED_DOMAINS_FILE_NAME; - return $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); + try { + $blacklistedDomainsInJson = $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); + if (empty($blacklistedDomainsInJson)) { + return []; + } + return json_decode($blacklistedDomainsInJson, true); + } catch (NotFoundException $e) { + $this->logger->error('Blacklisted domains file '.$document.' not found!'); + return []; + } + } /** * Ensure the specified folder exists within AppData. @@ -644,10 +657,10 @@ class UserService { try { $this->appData->getFolder($foldername); } catch (NotFoundException $e) { - $this->logger->logException('Blacklisted domains file not found!'); + $this->logger->error('Blacklisted domains folder '.$foldername.' not found!'); return false; } catch (\RuntimeException $e) { - $this->logger->logException($e); + $this->logger->error($e); return false; } return true; -- GitLab From 2ba85e000cfd36c79063dea1b12c77d9b56186a2 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 13:42:56 +0530 Subject: [PATCH 29/41] trying root --- 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 65afb894..926d9e28 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -44,7 +44,7 @@ class UserService { /** @var LDAPConnectionService */ private $LDAPConnectionService; private IAppData $appData; - private const BLACKLISTED_DOMAINS_FOLDER_NAME = Application::APP_ID; + private const BLACKLISTED_DOMAINS_FOLDER_NAME = '/'; private const BLACKLISTED_DOMAINS_FILE_NAME = 'blacklisted_domains.json'; private const BLACKLISTED_DOMAINS_URL = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; -- GitLab From 05e6443f49caf90aaac8cbd6a7a196ebe25f939e Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 13:50:17 +0530 Subject: [PATCH 30/41] separate call for BlacklistService --- lib/Service/BlackListService.php | 117 +++++++++++++++++++++++++++++++ lib/Service/UserService.php | 114 ++---------------------------- 2 files changed, 121 insertions(+), 110 deletions(-) create mode 100644 lib/Service/BlackListService.php diff --git a/lib/Service/BlackListService.php b/lib/Service/BlackListService.php new file mode 100644 index 00000000..9afa293a --- /dev/null +++ b/lib/Service/BlackListService.php @@ -0,0 +1,117 @@ +appData = $appData; + $this->logger = $logger; + } + + /** + * Check if an email domain is blacklisted against a JSON list of disposable email domains. + * + * @param string $email The email address to check. + * @return bool True if the email domain is blacklisted, false otherwise. + */ + public function isBlacklistedEmail(string $email): bool { + if (!$this->ensureDocumentsFolder()) { + return false; + } + $blacklistedDomains = $this->getBlacklistedDomainData(); + if (empty($blacklistedDomains)) { + return false; + } + $emailParts = explode('@', $email); + $emailDomain = strtolower(end($emailParts)); + return in_array($emailDomain, $blacklistedDomains); + } + /** + * Update the blacklisted domains data by fetching it from a URL and saving it locally. + * + * @return void + */ + public function updateBlacklistedDomains(): void { + $blacklisted_domain_url = self::BLACKLISTED_DOMAINS_URL; + $json_data = file_get_contents($blacklisted_domain_url); + $this->setBlacklistedDomainsData($json_data); + } + /** + * Store blacklisted domain data in a file within AppData. + * + * @param string $data The data to be stored in the file. + */ + private function setBlacklistedDomainsData(string $data): void { + $file = $this->getBlacklistedDomainsFilePath(); + $file->putContent($data); + } + /** + * Retrieve the blacklisted domain file path + * + */ + private function getBlacklistedDomainsFilePath() { + $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; + try { + $currentFolder = $this->appData->getFolder($foldername); + } catch (NotFoundException $e) { + $this->logger->error('Folder '.$foldername.' not found!'); + $currentFolder = $this->appData->newFolder($foldername); + } + $filename = self::BLACKLISTED_DOMAINS_FILE_NAME; + if ($currentFolder->fileExists($filename)) { + return $currentFolder->getFile($filename); + } + return $currentFolder->newFile($filename); + } + /** + * Retrieve the blacklisted domain data. + * + * @return array The array of blacklisted domains. + */ + public function getBlacklistedDomainData(): array { + $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; + $document = self::BLACKLISTED_DOMAINS_FILE_NAME; + try { + $blacklistedDomainsInJson = $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); + if (empty($blacklistedDomainsInJson)) { + return []; + } + return json_decode($blacklistedDomainsInJson, true); + } catch (NotFoundException $e) { + $this->logger->error('Blacklisted domains file '.$document.' not found!'); + return []; + } + + } + /** + * Ensure the specified folder exists within AppData. + * + */ + private function ensureDocumentsFolder(): bool { + $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; + try { + $this->appData->getFolder($foldername); + } catch (NotFoundException $e) { + $this->logger->error('Blacklisted domains folder '.$foldername.' not found!'); + return false; + } catch (\RuntimeException $e) { + $this->logger->error($e); + return false; + } + return true; + } +} diff --git a/lib/Service/UserService.php b/lib/Service/UserService.php index 926d9e28..8364edeb 100644 --- a/lib/Service/UserService.php +++ b/lib/Service/UserService.php @@ -12,8 +12,6 @@ use OCA\EcloudAccounts\Exception\AddUsernameToCommonStoreException; use OCA\EcloudAccounts\Exception\BlacklistedEmailException; use OCA\EcloudAccounts\Exception\LDAPUserCreationException; use OCP\Defaults; -use OCP\Files\IAppData; -use OCP\Files\NotFoundException; use OCP\IConfig; use OCP\ILogger; use OCP\IUser; @@ -43,12 +41,8 @@ class UserService { private $apiConfig; /** @var LDAPConnectionService */ private $LDAPConnectionService; - private IAppData $appData; - private const BLACKLISTED_DOMAINS_FOLDER_NAME = '/'; - private const BLACKLISTED_DOMAINS_FILE_NAME = 'blacklisted_domains.json'; - private const BLACKLISTED_DOMAINS_URL = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; - - public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger, Defaults $defaults, IFactory $l10nFactory, LDAPConnectionService $LDAPConnectionService, IAppData $appData) { + private BlackListService $blackListService; + public function __construct($appName, IUserManager $userManager, IConfig $config, CurlService $curlService, ILogger $logger, Defaults $defaults, IFactory $l10nFactory, LDAPConnectionService $LDAPConnectionService, BlackListService $blackListService) { $this->userManager = $userManager; $this->config = $config; $this->appConfig = $this->config->getSystemValue($appName); @@ -57,7 +51,7 @@ class UserService { $this->defaults = $defaults; $this->l10nFactory = $l10nFactory; $this->LDAPConnectionService = $LDAPConnectionService; - $this->appData = $appData; + $this->blackListService = $blackListService; $commonServiceURL = $this->config->getSystemValue('common_services_url', ''); if (!empty($commonServiceURL)) { @@ -281,35 +275,10 @@ class UserService { if ($this->isRecoveryEmailDomainDisallowed($recoveryEmail)) { throw new Exception('You cannot set an email address with a Murena domain as recovery email address.'); } - if ($this->isBlacklistedEmail($recoveryEmail)) { + if ($this->blackListService->isBlacklistedEmail($recoveryEmail)) { throw new BlacklistedEmailException('The domain of this email address is blacklisted. Please provide another recovery address.'); } } - /** - * Check if an email domain is blacklisted against a JSON list of disposable email domains. - * - * @param string $email The email address to check. - * @return bool True if the email domain is blacklisted, false otherwise. - */ - public function isBlacklistedEmail(string $email): bool { - // Get the blacklisted domains from configuration - if (!$this->ensureDocumentsFolder()) { - return false; - } - $blacklistedDomains = $this->getBlacklistedDomainData(); - if (empty($blacklistedDomains)) { - return false; - } - - // Split the email address into parts using explode - $emailParts = explode('@', $email); - - // Extract the domain part - $emailDomain = strtolower(end($emailParts)); - - // Check if the email domain is in the blacklisted domains array - return in_array($emailDomain, $blacklistedDomains); - } /** * Add a new user to the LDAP directory. * @@ -590,79 +559,4 @@ class UserService { private function getDefaultQuota() { return $this->config->getSystemValueInt('default_quota_in_megabytes', 1024); } - /** - * Update the blacklisted domains data by fetching it from a URL and saving it locally. - * - * @return void - */ - public function updateBlacklistedDomains(): void { - $blacklisted_domain_url = self::BLACKLISTED_DOMAINS_URL; - $json_data = file_get_contents($blacklisted_domain_url); - $this->setBlacklistedDomainsData($json_data); - } - - /** - * Store blacklisted domain data in a file within AppData. - * - * @param string $data The data to be stored in the file. - */ - private function setBlacklistedDomainsData(string $data): void { - $file = $this->getBlacklistedDomainsFilePath(); - $file->putContent($data); - } - /** - * Retrieve the blacklisted domain file path - * - */ - private function getBlacklistedDomainsFilePath() { - $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; - try { - $currentFolder = $this->appData->getFolder($foldername); - } catch (NotFoundException $e) { - $this->logger->error('Folder '.$foldername.' not found!'); - $currentFolder = $this->appData->newFolder($foldername); - } - $filename = self::BLACKLISTED_DOMAINS_FILE_NAME; - if ($currentFolder->fileExists($filename)) { - return $currentFolder->getFile($filename); - } - return $currentFolder->newFile($filename); - } - /** - * Retrieve the blacklisted domain data. - * - * @return array The array of blacklisted domains. - */ - public function getBlacklistedDomainData(): array { - $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; - $document = self::BLACKLISTED_DOMAINS_FILE_NAME; - try { - $blacklistedDomainsInJson = $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); - if (empty($blacklistedDomainsInJson)) { - return []; - } - return json_decode($blacklistedDomainsInJson, true); - } catch (NotFoundException $e) { - $this->logger->error('Blacklisted domains file '.$document.' not found!'); - return []; - } - - } - /** - * Ensure the specified folder exists within AppData. - * - */ - private function ensureDocumentsFolder(): bool { - $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; - try { - $this->appData->getFolder($foldername); - } catch (NotFoundException $e) { - $this->logger->error('Blacklisted domains folder '.$foldername.' not found!'); - return false; - } catch (\RuntimeException $e) { - $this->logger->error($e); - return false; - } - return true; - } } -- GitLab From 4124657f5f03dba6d4f02c4fada39dd94e14dc1b Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 13:52:03 +0530 Subject: [PATCH 31/41] change in call --- lib/Command/UpdateBlacklistedDomains.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Command/UpdateBlacklistedDomains.php b/lib/Command/UpdateBlacklistedDomains.php index 27434981..3c489b89 100644 --- a/lib/Command/UpdateBlacklistedDomains.php +++ b/lib/Command/UpdateBlacklistedDomains.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Command; use OCA\EcloudAccounts\AppInfo\Application; +use OCA\EcloudAccounts\Service\BlackListService; use OCA\EcloudAccounts\Service\UserService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; @@ -12,10 +13,12 @@ use Symfony\Component\Console\Output\OutputInterface; class UpdateBlacklistedDomains extends Command { private UserService $userService; + private BlackListService $blackListService; - public function __construct(UserService $userService) { + public function __construct(UserService $userService, BlackListService $blackListService) { parent::__construct(); $this->userService = $userService; + $this->blackListService = $blackListService; } protected function configure() { @@ -24,7 +27,7 @@ class UpdateBlacklistedDomains extends Command { protected function execute(InputInterface $input, OutputInterface $output): int { try { - $this->userService->updateBlacklistedDomains(); + $this->blackListService->updateBlacklistedDomains(); $output->writeln('Updated blacklisted domains for creation.'); } catch (\Throwable $th) { $output->writeln('Error while updating blacklisted domains.'); -- GitLab From 343793f55e5f8a21d68f7c2f2e12fe0539c98964 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 13:53:23 +0530 Subject: [PATCH 32/41] unncessary call --- lib/Command/UpdateBlacklistedDomains.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/Command/UpdateBlacklistedDomains.php b/lib/Command/UpdateBlacklistedDomains.php index 3c489b89..6ca8bdb5 100644 --- a/lib/Command/UpdateBlacklistedDomains.php +++ b/lib/Command/UpdateBlacklistedDomains.php @@ -6,18 +6,15 @@ namespace OCA\EcloudAccounts\Command; use OCA\EcloudAccounts\AppInfo\Application; use OCA\EcloudAccounts\Service\BlackListService; -use OCA\EcloudAccounts\Service\UserService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class UpdateBlacklistedDomains extends Command { - private UserService $userService; private BlackListService $blackListService; - public function __construct(UserService $userService, BlackListService $blackListService) { + public function __construct(BlackListService $blackListService) { parent::__construct(); - $this->userService = $userService; $this->blackListService = $blackListService; } -- GitLab From 12c04ce84cf51e575b5872715bb33d25e47d3f95 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 14:25:30 +0530 Subject: [PATCH 33/41] throwable ccode --- lib/Command/UpdateBlacklistedDomains.php | 7 ++++++- lib/Service/BlackListService.php | 5 +---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Command/UpdateBlacklistedDomains.php b/lib/Command/UpdateBlacklistedDomains.php index 6ca8bdb5..22f3d255 100644 --- a/lib/Command/UpdateBlacklistedDomains.php +++ b/lib/Command/UpdateBlacklistedDomains.php @@ -9,13 +9,17 @@ use OCA\EcloudAccounts\Service\BlackListService; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use OCP\ILogger; class UpdateBlacklistedDomains extends Command { private BlackListService $blackListService; + private ILogger $logger; - public function __construct(BlackListService $blackListService) { + + public function __construct(BlackListService $blackListService, ILogger $logger) { parent::__construct(); $this->blackListService = $blackListService; + $this->logger = $logger; } protected function configure() { @@ -27,6 +31,7 @@ class UpdateBlacklistedDomains extends Command { $this->blackListService->updateBlacklistedDomains(); $output->writeln('Updated blacklisted domains for creation.'); } catch (\Throwable $th) { + $this->logger->error('Error while updating blacklisted domains. ' . $th->getMessage()); $output->writeln('Error while updating blacklisted domains.'); } return 1; diff --git a/lib/Service/BlackListService.php b/lib/Service/BlackListService.php index 9afa293a..ce8138c7 100644 --- a/lib/Service/BlackListService.php +++ b/lib/Service/BlackListService.php @@ -4,8 +4,6 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Service; -require __DIR__ . '/../../vendor/autoload.php'; - use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\ILogger; @@ -68,7 +66,6 @@ class BlackListService { try { $currentFolder = $this->appData->getFolder($foldername); } catch (NotFoundException $e) { - $this->logger->error('Folder '.$foldername.' not found!'); $currentFolder = $this->appData->newFolder($foldername); } $filename = self::BLACKLISTED_DOMAINS_FILE_NAME; @@ -92,7 +89,7 @@ class BlackListService { } return json_decode($blacklistedDomainsInJson, true); } catch (NotFoundException $e) { - $this->logger->error('Blacklisted domains file '.$document.' not found!'); + $this->logger->warning('Blacklisted domains file '.$document.' not found!'); return []; } -- GitLab From 1b0e46470ae6eeb845a2b6d31540ec873ec31223 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 14:36:58 +0530 Subject: [PATCH 34/41] changes --- lib/Command/UpdateBlacklistedDomains.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Command/UpdateBlacklistedDomains.php b/lib/Command/UpdateBlacklistedDomains.php index 22f3d255..2b403900 100644 --- a/lib/Command/UpdateBlacklistedDomains.php +++ b/lib/Command/UpdateBlacklistedDomains.php @@ -6,10 +6,10 @@ namespace OCA\EcloudAccounts\Command; use OCA\EcloudAccounts\AppInfo\Application; use OCA\EcloudAccounts\Service\BlackListService; +use OCP\ILogger; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use OCP\ILogger; class UpdateBlacklistedDomains extends Command { private BlackListService $blackListService; -- GitLab From 72c447b2f22058c8594ccfaa9c27d6420fb7a698 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 15:04:27 +0530 Subject: [PATCH 35/41] added try catch --- lib/Service/BlackListService.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Service/BlackListService.php b/lib/Service/BlackListService.php index ce8138c7..b2ff8485 100644 --- a/lib/Service/BlackListService.php +++ b/lib/Service/BlackListService.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Service; +use Exception; use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\ILogger; @@ -84,14 +85,17 @@ class BlackListService { $document = self::BLACKLISTED_DOMAINS_FILE_NAME; try { $blacklistedDomainsInJson = $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); - if (empty($blacklistedDomainsInJson)) { - return []; - } - return json_decode($blacklistedDomainsInJson, true); } catch (NotFoundException $e) { $this->logger->warning('Blacklisted domains file '.$document.' not found!'); return []; + } catch (Exception $e) { + $this->logger->warning('Blacklisted domains file '.$document.' not found!'); + return []; + } + if (empty($blacklistedDomainsInJson)) { + return []; } + return json_decode($blacklistedDomainsInJson, true); } /** -- GitLab From 2f71b62047ab789ad3b62bb409d9aba058a719e2 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 15:06:25 +0530 Subject: [PATCH 36/41] made changes --- lib/Service/BlackListService.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/Service/BlackListService.php b/lib/Service/BlackListService.php index b2ff8485..c894b8b3 100644 --- a/lib/Service/BlackListService.php +++ b/lib/Service/BlackListService.php @@ -81,10 +81,14 @@ class BlackListService { * @return array The array of blacklisted domains. */ public function getBlacklistedDomainData(): array { - $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; $document = self::BLACKLISTED_DOMAINS_FILE_NAME; + $file = $this->getBlacklistedDomainsFilePath(); try { - $blacklistedDomainsInJson = $this->appData->getFolder($foldername)->getFile((string) $document)->getContent(); + $blacklistedDomainsInJson = $file->getContent(); + if (empty($blacklistedDomainsInJson)) { + return []; + } + return json_decode($blacklistedDomainsInJson, true); } catch (NotFoundException $e) { $this->logger->warning('Blacklisted domains file '.$document.' not found!'); return []; @@ -92,11 +96,6 @@ class BlackListService { $this->logger->warning('Blacklisted domains file '.$document.' not found!'); return []; } - if (empty($blacklistedDomainsInJson)) { - return []; - } - return json_decode($blacklistedDomainsInJson, true); - } /** * Ensure the specified folder exists within AppData. -- GitLab From a0161b43687079879ce1f77804098678dcbca560 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 15:15:45 +0530 Subject: [PATCH 37/41] removed root folder --- lib/Service/BlackListService.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/Service/BlackListService.php b/lib/Service/BlackListService.php index c894b8b3..82439f98 100644 --- a/lib/Service/BlackListService.php +++ b/lib/Service/BlackListService.php @@ -12,7 +12,6 @@ use OCP\ILogger; class BlackListService { private IAppData $appData; private ILogger $logger; - private const BLACKLISTED_DOMAINS_FOLDER_NAME = '/'; private const BLACKLISTED_DOMAINS_FILE_NAME = 'blacklisted_domains.json'; private const BLACKLISTED_DOMAINS_URL = 'https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains.json'; @@ -63,11 +62,10 @@ class BlackListService { * */ private function getBlacklistedDomainsFilePath() { - $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; try { - $currentFolder = $this->appData->getFolder($foldername); + $currentFolder = $this->appData->getFolder('/'); } catch (NotFoundException $e) { - $currentFolder = $this->appData->newFolder($foldername); + $currentFolder = $this->appData->newFolder('/'); } $filename = self::BLACKLISTED_DOMAINS_FILE_NAME; if ($currentFolder->fileExists($filename)) { @@ -102,11 +100,10 @@ class BlackListService { * */ private function ensureDocumentsFolder(): bool { - $foldername = self::BLACKLISTED_DOMAINS_FOLDER_NAME; try { - $this->appData->getFolder($foldername); + $this->appData->getFolder('/'); } catch (NotFoundException $e) { - $this->logger->error('Blacklisted domains folder '.$foldername.' not found!'); + $this->logger->error('Blacklisted domains folder not found!'); return false; } catch (\RuntimeException $e) { $this->logger->error($e); -- GitLab From 399e5210871cf03dd62d2ce6b36a6e87af5e68ce Mon Sep 17 00:00:00 2001 From: Akhil Date: Thu, 20 Jun 2024 15:19:20 +0000 Subject: [PATCH 38/41] Apply 1 suggestion(s) to 1 file(s) Co-authored-by: Akhil --- lib/Service/BlackListService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Service/BlackListService.php b/lib/Service/BlackListService.php index 82439f98..2eecc0fe 100644 --- a/lib/Service/BlackListService.php +++ b/lib/Service/BlackListService.php @@ -103,7 +103,7 @@ class BlackListService { try { $this->appData->getFolder('/'); } catch (NotFoundException $e) { - $this->logger->error('Blacklisted domains folder not found!'); + $this->logger->error(Application::APP_ID . ' AppData folder not found!'); return false; } catch (\RuntimeException $e) { $this->logger->error($e); -- GitLab From 6b6f00bc4b3349a734af98d76ebd55b1560610a7 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 16:42:49 +0530 Subject: [PATCH 39/41] feedback work --- lib/Service/BlackListService.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Service/BlackListService.php b/lib/Service/BlackListService.php index 2eecc0fe..a179a615 100644 --- a/lib/Service/BlackListService.php +++ b/lib/Service/BlackListService.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace OCA\EcloudAccounts\Service; -use Exception; use OCP\Files\IAppData; use OCP\Files\NotFoundException; use OCP\ILogger; @@ -54,14 +53,14 @@ class BlackListService { * @param string $data The data to be stored in the file. */ private function setBlacklistedDomainsData(string $data): void { - $file = $this->getBlacklistedDomainsFilePath(); + $file = $this->getBlacklistedDomainsFile(); $file->putContent($data); } /** * Retrieve the blacklisted domain file path * */ - private function getBlacklistedDomainsFilePath() { + private function getBlacklistedDomainsFile() { try { $currentFolder = $this->appData->getFolder('/'); } catch (NotFoundException $e) { @@ -80,21 +79,22 @@ class BlackListService { */ public function getBlacklistedDomainData(): array { $document = self::BLACKLISTED_DOMAINS_FILE_NAME; - $file = $this->getBlacklistedDomainsFilePath(); + $file = $this->getBlacklistedDomainsFile(); try { $blacklistedDomainsInJson = $file->getContent(); if (empty($blacklistedDomainsInJson)) { return []; } - return json_decode($blacklistedDomainsInJson, true); + return json_decode($blacklistedDomainsInJson, true, 512, JSON_THROW_ON_ERROR); } catch (NotFoundException $e) { - $this->logger->warning('Blacklisted domains file '.$document.' not found!'); + $this->logger->warning('Blacklisted domains file ' . $document . ' not found!'); return []; - } catch (Exception $e) { - $this->logger->warning('Blacklisted domains file '.$document.' not found!'); + } catch (\Throwable $e) { + $this->logger->warning('Error decoding blacklisted domains file ' . $document . ': ' . $e->getMessage()); return []; } } + /** * Ensure the specified folder exists within AppData. * @@ -106,7 +106,7 @@ class BlackListService { $this->logger->error(Application::APP_ID . ' AppData folder not found!'); return false; } catch (\RuntimeException $e) { - $this->logger->error($e); + $this->logger->error(Application::APP_ID . ' AppData folder not found! Runtime Error: '.$e->getMessage()); return false; } return true; -- GitLab From 5f82a1ec76a9bc37ec1c354cc63d8df3a28bfd64 Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Thu, 20 Jun 2024 16:46:16 +0530 Subject: [PATCH 40/41] added return type --- lib/Service/BlackListService.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Service/BlackListService.php b/lib/Service/BlackListService.php index a179a615..ba9d0a21 100644 --- a/lib/Service/BlackListService.php +++ b/lib/Service/BlackListService.php @@ -6,6 +6,7 @@ namespace OCA\EcloudAccounts\Service; use OCP\Files\IAppData; use OCP\Files\NotFoundException; +use OCP\Files\SimpleFS\ISimpleFile; use OCP\ILogger; class BlackListService { @@ -51,6 +52,7 @@ class BlackListService { * Store blacklisted domain data in a file within AppData. * * @param string $data The data to be stored in the file. + * @return void */ private function setBlacklistedDomainsData(string $data): void { $file = $this->getBlacklistedDomainsFile(); @@ -59,8 +61,9 @@ class BlackListService { /** * Retrieve the blacklisted domain file path * + * @return ISimpleFile */ - private function getBlacklistedDomainsFile() { + private function getBlacklistedDomainsFile(): ISimpleFile { try { $currentFolder = $this->appData->getFolder('/'); } catch (NotFoundException $e) { @@ -98,6 +101,7 @@ class BlackListService { /** * Ensure the specified folder exists within AppData. * + * @return bool */ private function ensureDocumentsFolder(): bool { try { -- GitLab From 043c9ccd9cd2f28e6772764466c5581e1367596a Mon Sep 17 00:00:00 2001 From: Ronak Patel Date: Fri, 21 Jun 2024 07:42:51 +0530 Subject: [PATCH 41/41] added message --- lib/Command/UpdateBlacklistedDomains.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Command/UpdateBlacklistedDomains.php b/lib/Command/UpdateBlacklistedDomains.php index 2b403900..74bc1642 100644 --- a/lib/Command/UpdateBlacklistedDomains.php +++ b/lib/Command/UpdateBlacklistedDomains.php @@ -32,7 +32,7 @@ class UpdateBlacklistedDomains extends Command { $output->writeln('Updated blacklisted domains for creation.'); } catch (\Throwable $th) { $this->logger->error('Error while updating blacklisted domains. ' . $th->getMessage()); - $output->writeln('Error while updating blacklisted domains.'); + $output->writeln('Error while updating blacklisted domains. '. $th->getMessage()); } return 1; } -- GitLab