mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
rework env-struct & validation of expense_mailbox
This commit is contained in:
parent
80a9d51ffb
commit
21a8f4da76
@ -51,8 +51,8 @@ class CompanyFactory
|
||||
$company->first_month_of_year = 1;
|
||||
|
||||
// default mailbox
|
||||
$company->expense_mailbox = config('ninja.inbound_expense.webhook.mailbox_template') != '' ?
|
||||
str_replace('{{company_key}}', $company->company_key, config('ninja.inbound_expense.webhook.mailbox_template')) : null;
|
||||
$company->expense_mailbox = config('ninja.ingest_mail.expense_mailbox_template') != '' ?
|
||||
str_replace('{{company_key}}', $company->company_key, config('ninja.ingest_mail.expense_mailbox_template')) : null;
|
||||
|
||||
return $company;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ use Illuminate\Contracts\Validation\Rule;
|
||||
class ValidExpenseMailbox implements Rule
|
||||
{
|
||||
|
||||
private $is_enterprise_error = false;
|
||||
private $validated_schema = false;
|
||||
private $company_key = false;
|
||||
private $isEnterprise = false;
|
||||
@ -32,9 +33,7 @@ class ValidExpenseMailbox implements Rule
|
||||
{
|
||||
$this->company_key = $company_key;
|
||||
$this->isEnterprise = $isEnterprise;
|
||||
$this->endings = explode(",", config('ninja.inbound_expense.webhook.mailbox_endings'));
|
||||
$this->hasCompanyKey = config('ninja.inbound_expense.webhook.mailbox_hascompanykey');
|
||||
$this->enterprise_endings = explode(",", config('ninja.inbound_expense.webhook.mailbox_enterprise_endings'));
|
||||
$this->endings = explode(",", config('ninja.ingest_mail.expense_mailbox_endings'));
|
||||
}
|
||||
|
||||
public function passes($attribute, $value)
|
||||
@ -43,16 +42,20 @@ class ValidExpenseMailbox implements Rule
|
||||
return true;
|
||||
}
|
||||
|
||||
// denie on hosted and not enterprise
|
||||
if (Ninja::isHosted() && !$this->isEnterprise) {
|
||||
$this->is_enterprise_error = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// early return, if we dont have any additional validation
|
||||
if (!config('ninja.inbound_expense.webhook.mailbox_schema') && !(Ninja::isHosted() && config('ninja.inbound_expense.webhook.mailbox_schema_enterprise'))) {
|
||||
if (!config('ninja.ingest_mail.expense_mailbox_endings')) {
|
||||
$this->validated_schema = true;
|
||||
return MultiDB::checkExpenseMailboxAvailable($value);
|
||||
}
|
||||
|
||||
// Validate Schema
|
||||
$validated_hasCompanyKey = !$this->hasCompanyKey || str_contains($value, $this->company_key);
|
||||
$validated = false;
|
||||
if ($validated_hasCompanyKey)
|
||||
foreach ($this->endings as $ending) {
|
||||
if (str_ends_with($ending, $value)) {
|
||||
$validated = true;
|
||||
@ -60,16 +63,7 @@ class ValidExpenseMailbox implements Rule
|
||||
}
|
||||
}
|
||||
|
||||
$validated_enterprise = false;
|
||||
if (Ninja::isHosted() && $this->isEnterprise)
|
||||
foreach ($this->endings as $ending) {
|
||||
if (str_ends_with($ending, $value)) {
|
||||
$validated_enterprise = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$validated && !$validated_enterprise)
|
||||
if (!$validated)
|
||||
return false;
|
||||
|
||||
$this->validated_schema = true;
|
||||
@ -81,6 +75,12 @@ class ValidExpenseMailbox implements Rule
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return $this->validated_schema ? ctrans('texts.expense_mailbox_taken') : ctrans('texts.expense_mailbox_invalid');
|
||||
if ($this->validated_schema)
|
||||
return ctrans('texts.expense_mailbox_not_available');
|
||||
|
||||
if ($this->validated_schema)
|
||||
return ctrans('texts.expense_mailbox_taken');
|
||||
|
||||
return ctrans('texts.expense_mailbox_invalid');
|
||||
}
|
||||
}
|
||||
|
@ -74,14 +74,14 @@ class ExpenseMailboxJob implements ShouldQueue
|
||||
|
||||
private function getImapCredentials()
|
||||
{
|
||||
$servers = array_map('trim', explode(",", config('ninja.inbound_expense.imap.servers')));
|
||||
$ports = array_map('trim', explode(",", config('ninja.inbound_expense.imap.ports')));
|
||||
$users = array_map('trim', explode(",", config('ninja.inbound_expense.imap.users')));
|
||||
$passwords = array_map('trim', explode(",", config('ninja.inbound_expense.imap.passwords')));
|
||||
$companies = array_map('trim', explode(",", config('ninja.inbound_expense.imap.companies')));
|
||||
$servers = array_map('trim', explode(",", config('ninja.ingest_mail.imap.servers')));
|
||||
$ports = array_map('trim', explode(",", config('ninja.ingest_mail.imap.ports')));
|
||||
$users = array_map('trim', explode(",", config('ninja.ingest_mail.imap.users')));
|
||||
$passwords = array_map('trim', explode(",", config('ninja.ingest_mail.imap.passwords')));
|
||||
$companies = array_map('trim', explode(",", config('ninja.ingest_mail.imap.companies')));
|
||||
|
||||
if (sizeOf($servers) != sizeOf($ports) || sizeOf($servers) != sizeOf($users) || sizeOf($servers) != sizeOf($passwords) || sizeOf($servers) != sizeOf($companies))
|
||||
throw new \Exception('invalid configuration inbound_expense.imap (wrong element-count)');
|
||||
throw new \Exception('invalid configuration ingest_mail.imap (wrong element-count)');
|
||||
|
||||
foreach ($companies as $index => $companyId) {
|
||||
|
||||
|
@ -228,19 +228,15 @@ return [
|
||||
'secret' => env('PAYPAL_SECRET', null),
|
||||
'client_id' => env('PAYPAL_CLIENT_ID', null),
|
||||
],
|
||||
'inbound_expense' => [
|
||||
'ingest_mail' => [
|
||||
'imap' => [
|
||||
'servers' => env('INBOUND_EXPENSE_IMAP_SERVERS', ''),
|
||||
'ports' => env('INBOUND_EXPENSE_IMAP_PORTS', ''),
|
||||
'users' => env('INBOUND_EXPENSE_IMAP_USERS', ''),
|
||||
'passwords' => env('INBOUND_EXPENSE_IMAP_PASSWORDS', ''),
|
||||
'companies' => env('INBOUND_EXPENSE_IMAP_COMPANIES', '1'),
|
||||
],
|
||||
'webhook' => [
|
||||
'mailbox_template' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOX_TEMPLATE', null),
|
||||
'mailbox_endings_endings' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOX_ENDINGS', ''),
|
||||
'mailbox_hascompanykey' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOX_HASCOMPANYKEY', false),
|
||||
'mailbox_endings_enterprise' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOX_ENTERPRISE_ENDINGS', '@expense.invoicing.co'),
|
||||
'servers' => env('ingest_mail_IMAP_SERVERS', ''),
|
||||
'ports' => env('ingest_mail_IMAP_PORTS', ''),
|
||||
'users' => env('ingest_mail_IMAP_USERS', ''),
|
||||
'passwords' => env('ingest_mail_IMAP_PASSWORDS', ''),
|
||||
'companies' => env('ingest_mail_IMAP_COMPANIES', '1'),
|
||||
],
|
||||
'expense_mailbox_template' => env('ingest_mail_EXPENSE_MAILBOX_TEMPLATE', null),
|
||||
'expense_mailbox_endings' => env('ingest_mail_EXPENSE_MAILBOX_ENDINGS', '@expense.invoicing.co'),
|
||||
],
|
||||
];
|
||||
|
@ -2534,6 +2534,7 @@ $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',
|
||||
'expense_mailbox_not_available' => 'You are not allowed to set an expense_inbox. Please upgrade plan to enterpise.',
|
||||
'expense_mailbox_taken' => 'The mailbox is already in use',
|
||||
'expense_mailbox_invalid' => 'The mailbox does not match the required schema',
|
||||
'client_login' => 'Client Login',
|
||||
|
Loading…
x
Reference in New Issue
Block a user