From b7378b9b100a74c480f507046c76afad49d8a340 Mon Sep 17 00:00:00 2001 From: paulwer Date: Thu, 4 Apr 2024 07:27:07 +0200 Subject: [PATCH] renaming inbound_mailbox to expense_mailbox --- .../Requests/Company/StoreCompanyRequest.php | 24 ++++++++--------- .../Requests/Company/UpdateCompanyRequest.php | 26 +++++++++---------- .../Company/ValidExpenseMailbox.php | 14 +++++----- app/Jobs/Brevo/ProcessBrevoInboundWebhook.php | 2 +- .../Mailgun/ProcessMailgunInboundWebhook.php | 2 +- app/Libraries/MultiDB.php | 16 ++++++------ app/Models/Company.php | 10 +++---- .../InboundMail/InboundMailEngine.php | 4 +-- app/Transformers/CompanyTransformer.php | 4 +-- config/ninja.php | 4 +-- ...2023_12_10_110951_inbound_mail_parsing.php | 4 +-- lang/en/texts.php | 4 +-- 12 files changed, 57 insertions(+), 57 deletions(-) diff --git a/app/Http/Requests/Company/StoreCompanyRequest.php b/app/Http/Requests/Company/StoreCompanyRequest.php index 3b4725118a4d..ff09dbfacc07 100644 --- a/app/Http/Requests/Company/StoreCompanyRequest.php +++ b/app/Http/Requests/Company/StoreCompanyRequest.php @@ -47,7 +47,7 @@ class StoreCompanyRequest extends Request $rules['company_logo'] = 'mimes:jpeg,jpg,png,gif|max:10000'; // max 10000kb $rules['settings'] = new ValidSettingsRule(); - if (isset ($input['portal_mode']) && ($input['portal_mode'] == 'domain' || $input['portal_mode'] == 'iframe')) { + if (isset($input['portal_mode']) && ($input['portal_mode'] == 'domain' || $input['portal_mode'] == 'iframe')) { $rules['portal_domain'] = 'sometimes|url'; } else { if (Ninja::isHosted()) { @@ -57,7 +57,7 @@ class StoreCompanyRequest extends Request } } - $rules['inbound_mailbox'] = new ValidExpenseMailbox($this->company->key, $this->company->account->isPaid() && $this->company->account->plan == 'enterprise'); + $rules['expense_mailbox'] = new ValidExpenseMailbox($this->company->key, $this->company->account->isPaid() && $this->company->account->plan == 'enterprise'); $rules['smtp_host'] = 'sometimes|string|nullable'; $rules['smtp_port'] = 'sometimes|integer|nullable'; @@ -75,39 +75,39 @@ class StoreCompanyRequest extends Request { $input = $this->all(); - if (!isset ($input['name'])) { + if (!isset($input['name'])) { $input['name'] = 'Untitled Company'; } - if (isset ($input['google_analytics_url'])) { + if (isset($input['google_analytics_url'])) { $input['google_analytics_key'] = $input['google_analytics_url']; } - if (isset ($input['portal_domain'])) { + if (isset($input['portal_domain'])) { $input['portal_domain'] = rtrim(strtolower($input['portal_domain']), "/"); } - if (isset ($input['inbound_mailbox']) && Ninja::isHosted() && !($this->company->account->isPaid() && $this->company->account->plan == 'enterprise')) { - unset($input['inbound_mailbox']); + if (isset($input['expense_mailbox']) && Ninja::isHosted() && !($this->company->account->isPaid() && $this->company->account->plan == 'enterprise')) { + unset($input['expense_mailbox']); } - if (Ninja::isHosted() && !isset ($input['subdomain'])) { + if (Ninja::isHosted() && !isset($input['subdomain'])) { $input['subdomain'] = MultiDB::randomSubdomainGenerator(); } - if (isset ($input['smtp_username']) && strlen(str_replace("*", "", $input['smtp_username'])) < 2) { + if (isset($input['smtp_username']) && strlen(str_replace("*", "", $input['smtp_username'])) < 2) { unset($input['smtp_username']); } - if (isset ($input['smtp_password']) && strlen(str_replace("*", "", $input['smtp_password'])) < 2) { + if (isset($input['smtp_password']) && strlen(str_replace("*", "", $input['smtp_password'])) < 2) { unset($input['smtp_password']); } - if (isset ($input['smtp_port'])) { + if (isset($input['smtp_port'])) { $input['smtp_port'] = (int) $input['smtp_port']; } - if (isset ($input['smtp_verify_peer']) && is_string($input['smtp_verify_peer'])) + if (isset($input['smtp_verify_peer']) && is_string($input['smtp_verify_peer'])) $input['smtp_verify_peer'] == 'true' ? true : false; $this->replace($input); diff --git a/app/Http/Requests/Company/UpdateCompanyRequest.php b/app/Http/Requests/Company/UpdateCompanyRequest.php index c8578d262ae1..e4b24961e85b 100644 --- a/app/Http/Requests/Company/UpdateCompanyRequest.php +++ b/app/Http/Requests/Company/UpdateCompanyRequest.php @@ -66,7 +66,7 @@ class UpdateCompanyRequest extends Request // $rules['smtp_verify_peer'] = 'sometimes|string'; - if (isset ($input['portal_mode']) && ($input['portal_mode'] == 'domain' || $input['portal_mode'] == 'iframe')) { + if (isset($input['portal_mode']) && ($input['portal_mode'] == 'domain' || $input['portal_mode'] == 'iframe')) { $rules['portal_domain'] = 'bail|nullable|sometimes|url'; } @@ -74,7 +74,7 @@ class UpdateCompanyRequest extends Request $rules['subdomain'] = ['nullable', 'regex:/^[a-zA-Z0-9.-]+[a-zA-Z0-9]$/', new ValidSubdomain()]; } - $rules['inbound_mailbox'] = new ValidExpenseMailbox($this->company->key, $this->company->account->isPaid() && $this->company->account->plan == 'enterprise'); // @turbo124 check if this is right + $rules['expense_mailbox'] = new ValidExpenseMailbox($this->company->key, $this->company->account->isPaid() && $this->company->account->plan == 'enterprise'); // @turbo124 check if this is right return $rules; } @@ -83,40 +83,40 @@ class UpdateCompanyRequest extends Request { $input = $this->all(); - if (isset ($input['portal_domain']) && strlen($input['portal_domain']) > 1) { + if (isset($input['portal_domain']) && strlen($input['portal_domain']) > 1) { $input['portal_domain'] = $this->addScheme($input['portal_domain']); $input['portal_domain'] = rtrim(strtolower($input['portal_domain']), "/"); } - if (isset ($input['inbound_mailbox']) && Ninja::isHosted() && !($this->company->account->isPaid() && $this->company->account->plan == 'enterprise')) { - unset($input['inbound_mailbox']); + if (isset($input['expense_mailbox']) && Ninja::isHosted() && !($this->company->account->isPaid() && $this->company->account->plan == 'enterprise')) { + unset($input['expense_mailbox']); } - if (isset ($input['settings'])) { + if (isset($input['settings'])) { $input['settings'] = (array) $this->filterSaveableSettings($input['settings']); } - if (isset ($input['subdomain']) && $this->company->subdomain == $input['subdomain']) { + if (isset($input['subdomain']) && $this->company->subdomain == $input['subdomain']) { unset($input['subdomain']); } - if (isset ($input['e_invoice_certificate_passphrase']) && empty ($input['e_invoice_certificate_passphrase'])) { + if (isset($input['e_invoice_certificate_passphrase']) && empty($input['e_invoice_certificate_passphrase'])) { unset($input['e_invoice_certificate_passphrase']); } - if (isset ($input['smtp_username']) && strlen(str_replace("*", "", $input['smtp_username'])) < 2) { + if (isset($input['smtp_username']) && strlen(str_replace("*", "", $input['smtp_username'])) < 2) { unset($input['smtp_username']); } - if (isset ($input['smtp_password']) && strlen(str_replace("*", "", $input['smtp_password'])) < 2) { + if (isset($input['smtp_password']) && strlen(str_replace("*", "", $input['smtp_password'])) < 2) { unset($input['smtp_password']); } - if (isset ($input['smtp_port'])) { + if (isset($input['smtp_port'])) { $input['smtp_port'] = (int) $input['smtp_port']; } - if (isset ($input['smtp_verify_peer']) && is_string($input['smtp_verify_peer'])) { + if (isset($input['smtp_verify_peer']) && is_string($input['smtp_verify_peer'])) { $input['smtp_verify_peer'] == 'true' ? true : false; } @@ -143,7 +143,7 @@ class UpdateCompanyRequest extends Request } } - if (isset ($settings['email_style_custom'])) { + if (isset($settings['email_style_custom'])) { $settings['email_style_custom'] = str_replace(['{!!', '!!}', '{{', '}}', '@if(', '@endif', '@isset', '@unless', '@auth', '@empty', '@guest', '@env', '@section', '@switch', '@foreach', '@while', '@include', '@each', '@once', '@push', '@use', '@forelse', '@verbatim', 'company_key = $company_key; - $this->endings = explode(",", config('ninja.inbound_mailbox.inbound_mailbox_endings')); + $this->endings = explode(",", config('ninja.inbound_mailbox.expense_mailbox_endings')); } public function passes($attribute, $value) { - if (empty ($value)) { + if (empty($value)) { return true; } // early return, if we dont have any additional validation - if (!config('ninja.inbound_mailbox.inbound_mailbox_endings')) { + if (!config('ninja.inbound_mailbox.expense_mailbox_endings')) { $this->validated_schema = true; - return MultiDB::checkInboundMailboxAvailable($value); + return MultiDB::checkExpenseMailboxAvailable($value); } // Validate Schema @@ -59,7 +59,7 @@ class ValidExpenseMailbox implements Rule return false; $this->validated_schema = true; - return MultiDB::checkInboundMailboxAvailable($value); + return MultiDB::checkExpenseMailboxAvailable($value); } /** @@ -68,8 +68,8 @@ class ValidExpenseMailbox implements Rule public function message() { if (!$this->validated_schema) - return ctrans('texts.inbound_mailbox_invalid'); + return ctrans('texts.expense_mailbox_invalid'); - return ctrans('texts.inbound_mailbox_taken'); + return ctrans('texts.expense_mailbox_taken'); } } diff --git a/app/Jobs/Brevo/ProcessBrevoInboundWebhook.php b/app/Jobs/Brevo/ProcessBrevoInboundWebhook.php index 6fafc74ee47d..d6fc40e6f4a0 100644 --- a/app/Jobs/Brevo/ProcessBrevoInboundWebhook.php +++ b/app/Jobs/Brevo/ProcessBrevoInboundWebhook.php @@ -129,7 +129,7 @@ class ProcessBrevoInboundWebhook implements ShouldQueue } // match company - $company = MultiDB::findAndSetDbByInboundMailbox($recipient); + $company = MultiDB::findAndSetDbByExpenseMailbox($recipient); if (!$company) { Log::info('[ProcessBrevoInboundWebhook] unknown Expense Mailbox occured while handling an inbound email from brevo: ' . $recipient); (new InboundMailEngine())->saveMeta($this->input["From"]["Address"], $recipient); // important to save this, to protect from spam diff --git a/app/Jobs/Mailgun/ProcessMailgunInboundWebhook.php b/app/Jobs/Mailgun/ProcessMailgunInboundWebhook.php index c1846df7fcf1..1e786f80eeac 100644 --- a/app/Jobs/Mailgun/ProcessMailgunInboundWebhook.php +++ b/app/Jobs/Mailgun/ProcessMailgunInboundWebhook.php @@ -176,7 +176,7 @@ class ProcessMailgunInboundWebhook implements ShouldQueue } // match company - $company = MultiDB::findAndSetDbByInboundMailbox($to); + $company = MultiDB::findAndSetDbByExpenseMailbox($to); if (!$company) { Log::info('[ProcessMailgunInboundWebhook] unknown Expense Mailbox occured while handling an inbound email from mailgun: ' . $to); (new InboundMailEngine())->saveMeta($from, $to); // important to save this, to protect from spam diff --git a/app/Libraries/MultiDB.php b/app/Libraries/MultiDB.php index 58362ab77dcd..c0a6b213d241 100644 --- a/app/Libraries/MultiDB.php +++ b/app/Libraries/MultiDB.php @@ -73,7 +73,7 @@ class MultiDB 'socket', ]; - private static $protected_inbound_mailboxes = []; + private static $protected_expense_mailboxes = []; /** * @return array @@ -109,21 +109,21 @@ class MultiDB return true; } - public static function checkInboundMailboxAvailable($inbound_mailbox): bool + public static function checkExpenseMailboxAvailable($expense_mailbox): bool { if (!config('ninja.db.multi_db_enabled')) { - return Company::where("inbound_mailbox", $inbound_mailbox)->withTrashed()->exists(); + return Company::where("expense_mailbox", $expense_mailbox)->withTrashed()->exists(); } - if (in_array($inbound_mailbox, self::$protected_inbound_mailboxes)) { + if (in_array($expense_mailbox, self::$protected_expense_mailboxes)) { return false; } $current_db = config('database.default'); foreach (self::$dbs as $db) { - if (Company::on($db)->where("inbound_mailbox", $inbound_mailbox)->withTrashed()->exists()) { + if (Company::on($db)->where("expense_mailbox", $expense_mailbox)->withTrashed()->exists()) { self::setDb($current_db); return false; @@ -515,16 +515,16 @@ class MultiDB return false; } - public static function findAndSetDbByInboundMailbox($inbound_mailbox) + public static function findAndSetDbByExpenseMailbox($expense_mailbox) { if (!config('ninja.db.multi_db_enabled')) { - return Company::where("inbound_mailbox", $inbound_mailbox)->first(); + return Company::where("expense_mailbox", $expense_mailbox)->first(); } $current_db = config('database.default'); foreach (self::$dbs as $db) { - if ($company = Company::on($db)->where("inbound_mailbox", $inbound_mailbox)->first()) { + if ($company = Company::on($db)->where("expense_mailbox", $expense_mailbox)->first()) { self::setDb($db); return $company; diff --git a/app/Models/Company.php b/app/Models/Company.php index ab40b29960d0..5400d284b507 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -111,8 +111,8 @@ use Laracasts\Presenter\PresentableTrait; * @property int $convert_expense_currency * @property int $notify_vendor_when_paid * @property int $invoice_task_hours - * @property string|null $inbound_mailbox - * @property boolean $inbound_mailbox_active + * @property string|null $expense_mailbox + * @property boolean $expense_mailbox_active * @property bool $inbound_mailbox_allow_company_users * @property bool $inbound_mailbox_allow_vendors * @property bool $inbound_mailbox_allow_clients @@ -369,8 +369,8 @@ class Company extends BaseModel 'calculate_taxes', 'tax_data', 'e_invoice_certificate_passphrase', - 'inbound_mailbox_active', - 'inbound_mailbox', // TODO: @turbo124 custom validation: self-hosted => free change, hosted => not changeable, only changeable with env-mask + 'expense_mailbox_active', + 'expense_mailbox', // TODO: @turbo124 custom validation: self-hosted => free change, hosted => not changeable, only changeable with env-mask 'inbound_mailbox_allow_company_users', 'inbound_mailbox_allow_vendors', 'inbound_mailbox_allow_clients', @@ -732,7 +732,7 @@ class Company extends BaseModel public function getLocale() { - return isset ($this->settings->language_id) && $this->language() ? $this->language()->locale : config('ninja.i18n.locale'); + return isset($this->settings->language_id) && $this->language() ? $this->language()->locale : config('ninja.i18n.locale'); } public function getLogo(): ?string diff --git a/app/Services/InboundMail/InboundMailEngine.php b/app/Services/InboundMail/InboundMailEngine.php index 3c1db5a0f0a0..cdf1fe177fb7 100644 --- a/app/Services/InboundMail/InboundMailEngine.php +++ b/app/Services/InboundMail/InboundMailEngine.php @@ -54,7 +54,7 @@ class InboundMailEngine $isUnknownRecipent = true; // Expense Mailbox => will create an expense - $company = MultiDB::findAndSetDbByInboundMailbox($email->to); + $company = MultiDB::findAndSetDbByExpenseMailbox($email->to); if ($company) { $isUnknownRecipent = false; $this->createExpense($company, $email); @@ -148,7 +148,7 @@ class InboundMailEngine protected function createExpense(Company $company, InboundMail $email) { // Skipping executions: will not result in not saving Metadata to prevent usage of these conditions, to spam - if (!($company?->inbound_mailbox_active ?: false)) { + if (!($company?->expense_mailbox_active ?: false)) { $this->logBlocked($company, 'mailbox not active for this company. from: ' . $email->from); return; } diff --git a/app/Transformers/CompanyTransformer.php b/app/Transformers/CompanyTransformer.php index f3ebd108fc6e..f6cc4ae526a5 100644 --- a/app/Transformers/CompanyTransformer.php +++ b/app/Transformers/CompanyTransformer.php @@ -204,8 +204,8 @@ class CompanyTransformer extends EntityTransformer 'invoice_task_project_header' => (bool) $company->invoice_task_project_header, 'invoice_task_item_description' => (bool) $company->invoice_task_item_description, 'origin_tax_data' => $company->origin_tax_data ?: new \stdClass, - 'inbound_mailbox' => (bool) $company->inbound_mailbox, - 'inbound_mailbox_active' => (bool) $company->inbound_mailbox_active, + 'expense_mailbox' => (bool) $company->expense_mailbox, + 'expense_mailbox_active' => (bool) $company->expense_mailbox_active, 'inbound_mailbox_allow_company_users' => (bool) $company->inbound_mailbox_allow_company_users, 'inbound_mailbox_allow_vendors' => (bool) $company->inbound_mailbox_allow_vendors, 'inbound_mailbox_allow_clients' => (bool) $company->inbound_mailbox_allow_clients, diff --git a/config/ninja.php b/config/ninja.php index bdac51f8c0f1..3a05f424e7f3 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -237,8 +237,8 @@ return [ 'webhook_id' => env('PAYPAL_WEBHOOK_ID', null), ], 'inbound_mailbox' => [ - 'inbound_mailbox_template' => env('INBOUND_MAILBOX_TEMPLATE', null), - 'inbound_mailbox_endings' => env('INBOUND_MAILBOX_ENDINGS', '@expense.invoicing.co'), + 'expense_mailbox_template' => env('EXPENSE_MAILBOX_TEMPLATE', null), + 'expense_mailbox_endings' => env('EXPENSE_MAILBOX_ENDINGS', '@expense.invoicing.co'), ], 'cloudflare' => [ 'turnstile' => [ diff --git a/database/migrations/2023_12_10_110951_inbound_mail_parsing.php b/database/migrations/2023_12_10_110951_inbound_mail_parsing.php index f750d07065b4..94d647510f34 100644 --- a/database/migrations/2023_12_10_110951_inbound_mail_parsing.php +++ b/database/migrations/2023_12_10_110951_inbound_mail_parsing.php @@ -12,8 +12,8 @@ return new class extends Migration { public function up(): void { Schema::table('companies', function (Blueprint $table) { - $table->boolean("inbound_mailbox_active")->default(true); - $table->string("inbound_mailbox")->nullable(); + $table->boolean("expense_mailbox_active")->default(true); + $table->string("expense_mailbox")->nullable(); $table->boolean("inbound_mailbox_allow_company_users")->default(false); $table->boolean("inbound_mailbox_allow_vendors")->default(false); $table->boolean("inbound_mailbox_allow_clients")->default(false); diff --git a/lang/en/texts.php b/lang/en/texts.php index 627eb807284d..3f6fb79b43a5 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -2494,8 +2494,8 @@ $lang = array( 'local_storage_required' => 'Error: local storage is not available.', 'your_password_reset_link' => 'Your Password Reset Link', 'subdomain_taken' => 'The subdomain is already in use', - 'inbound_mailbox_taken' => 'The inbound mailbox is already in use', - 'inbound_mailbox_invalid' => 'The inbound mailbox does not match the required schema', + 'expense_mailbox_taken' => 'The inbound mailbox is already in use', + 'expense_mailbox_invalid' => 'The inbound mailbox does not match the required schema', 'client_login' => 'Client Login', 'converted_amount' => 'Converted Amount', 'default' => 'Default',