mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-08-07 10:01:47 -04:00
switch to endings for better oportunity to display in frontend
This commit is contained in:
parent
36279be694
commit
168fef71c7
@ -24,11 +24,17 @@ class ValidExpenseMailbox implements Rule
|
|||||||
private $validated_schema = false;
|
private $validated_schema = false;
|
||||||
private $company_key = false;
|
private $company_key = false;
|
||||||
private $isEnterprise = false;
|
private $isEnterprise = false;
|
||||||
|
private array $endings;
|
||||||
|
private bool $hasCompanyKey;
|
||||||
|
private array $enterprise_endings;
|
||||||
|
|
||||||
public function __construct(string $company_key, bool $isEnterprise = false)
|
public function __construct(string $company_key, bool $isEnterprise = false)
|
||||||
{
|
{
|
||||||
$this->company_key = $company_key;
|
$this->company_key = $company_key;
|
||||||
$this->isEnterprise = $isEnterprise;
|
$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'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function passes($attribute, $value)
|
public function passes($attribute, $value)
|
||||||
@ -44,8 +50,24 @@ class ValidExpenseMailbox implements Rule
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate Schema
|
// Validate Schema
|
||||||
$validated = !config('ninja.inbound_expense.webhook.mailbox_schema') || (preg_match(config('ninja.inbound_expense.webhook.mailbox_schema'), $value) && (!config('ninja.inbound_expense.webhook.mailbox_schema_hascompanykey') || str_contains($value, $this->company_key))) ? true : false;
|
$validated_hasCompanyKey = !$this->hasCompanyKey || str_contains($value, $this->company_key);
|
||||||
$validated_enterprise = !config('ninja.inbound_expense.webhook.mailbox_schema_enterprise') || (Ninja::isHosted() && $this->isEnterprise && preg_match(config('ninja.inbound_expense.webhook.mailbox_schema_enterprise'), $value));
|
$validated = false;
|
||||||
|
if ($validated_hasCompanyKey)
|
||||||
|
foreach ($this->endings as $ending) {
|
||||||
|
if (str_ends_with($ending, $value)) {
|
||||||
|
$validated = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$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 && !$validated_enterprise)
|
||||||
return false;
|
return false;
|
||||||
|
@ -238,9 +238,9 @@ return [
|
|||||||
],
|
],
|
||||||
'webhook' => [
|
'webhook' => [
|
||||||
'mailbox_template' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOXTEMPLATE', null),
|
'mailbox_template' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOXTEMPLATE', null),
|
||||||
'mailbox_schema' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOX_SCHEMA', null),
|
'mailbox_endings_endings' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOX_ENDINGS', ''),
|
||||||
'mailbox_schema_hascompanykey' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOX_SCHEMA_HASCOMPANYKEY', false),
|
'mailbox_hascompanykey' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOX_HASCOMPANYKEY', false),
|
||||||
'mailbox_schema_enterprise' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOX_SCHEMA_ENTERPRISE', '.*@expense\.invoicing\.co$'),
|
'mailbox_endings_enterprise' => env('INBOUND_EXPENSE_WEBHOOK_MAILBOX_ENTERPRISE_ENDINGS', '@expense.invoicing.co'),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user