From 1f92ea01080ea80a89f8a6bd2d100f423c230051 Mon Sep 17 00:00:00 2001 From: paulwer Date: Wed, 28 Aug 2024 07:33:03 +0200 Subject: [PATCH] fixes for validating expense_mailbox in company request --- app/Http/Requests/Company/UpdateCompanyRequest.php | 2 +- app/Http/ValidationRules/Company/ValidExpenseMailbox.php | 3 ++- app/Libraries/MultiDB.php | 2 +- app/Transformers/CompanyTransformer.php | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Http/Requests/Company/UpdateCompanyRequest.php b/app/Http/Requests/Company/UpdateCompanyRequest.php index fa8927a8c8..52d6d80aa9 100644 --- a/app/Http/Requests/Company/UpdateCompanyRequest.php +++ b/app/Http/Requests/Company/UpdateCompanyRequest.php @@ -76,7 +76,7 @@ class UpdateCompanyRequest extends Request $rules['subdomain'] = ['nullable', 'regex:/^[a-zA-Z0-9.-]+[a-zA-Z0-9]$/', new ValidSubdomain()]; } - $rules['expense_mailbox'] = new ValidExpenseMailbox(); + $rules['expense_mailbox'] = ['email', 'nullable', new ValidExpenseMailbox()]; return $rules; } diff --git a/app/Http/ValidationRules/Company/ValidExpenseMailbox.php b/app/Http/ValidationRules/Company/ValidExpenseMailbox.php index d9ab3727cb..aa333fddc0 100644 --- a/app/Http/ValidationRules/Company/ValidExpenseMailbox.php +++ b/app/Http/ValidationRules/Company/ValidExpenseMailbox.php @@ -14,6 +14,7 @@ namespace App\Http\ValidationRules\Company; use App\Libraries\MultiDB; use App\Utils\Ninja; use Illuminate\Contracts\Validation\Rule; +use Symfony\Component\Validator\Constraints\EmailValidator; /** * Class ValidCompanyQuantity. @@ -47,7 +48,7 @@ class ValidExpenseMailbox implements Rule // Validate Schema $validated = false; foreach ($this->endings as $ending) { - if (str_ends_with($ending, $value)) { + if (str_ends_with($value, $ending)) { $validated = true; break; } diff --git a/app/Libraries/MultiDB.php b/app/Libraries/MultiDB.php index 3e190a3c61..cc3545b927 100644 --- a/app/Libraries/MultiDB.php +++ b/app/Libraries/MultiDB.php @@ -113,7 +113,7 @@ class MultiDB { if (!config('ninja.db.multi_db_enabled')) { - return Company::where("expense_mailbox", $expense_mailbox)->exists(); + return !Company::where("expense_mailbox", $expense_mailbox)->exists(); } if (in_array($expense_mailbox, self::$protected_expense_mailboxes)) { diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index 4d3dacc65a..7c28215870 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -210,8 +210,8 @@ class CompanyTransformer extends EntityTransformer 'inbound_mailbox_allow_vendors' => (bool) $company->inbound_mailbox_allow_vendors, 'inbound_mailbox_allow_clients' => (bool) $company->inbound_mailbox_allow_clients, 'inbound_mailbox_allow_unknown' => (bool) $company->inbound_mailbox_allow_unknown, - 'inbound_mailbox_blacklist' => $company->inbound_mailbox_blacklist, - 'inbound_mailbox_whitelist' => $company->inbound_mailbox_whitelist, + 'inbound_mailbox_blacklist' => (string) $company->inbound_mailbox_blacklist, + 'inbound_mailbox_whitelist' => (string) $company->inbound_mailbox_whitelist, 'smtp_host' => (string) $company->smtp_host ?? '', 'smtp_port' => (int) $company->smtp_port ?? 25, 'smtp_encryption' => (string) $company->smtp_encryption ?? 'tls',