mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 23:44:30 -04:00
Adjustments for expense imports
This commit is contained in:
parent
9ced189262
commit
10f6977023
@ -65,6 +65,8 @@ class MailgunController extends BaseController
|
|||||||
|
|
||||||
$input = $request->all();
|
$input = $request->all();
|
||||||
|
|
||||||
|
nlog($input);
|
||||||
|
|
||||||
if (\abs(\time() - $request['signature']['timestamp']) > 15) {
|
if (\abs(\time() - $request['signature']['timestamp']) > 15) {
|
||||||
return response()->json(['message' => 'Success'], 200);
|
return response()->json(['message' => 'Success'], 200);
|
||||||
}
|
}
|
||||||
@ -118,6 +120,8 @@ class MailgunController extends BaseController
|
|||||||
{
|
{
|
||||||
$input = $request->all();
|
$input = $request->all();
|
||||||
|
|
||||||
|
nlog($input);
|
||||||
|
|
||||||
if (!array_key_exists('sender', $input) || !array_key_exists('recipient', $input) || !array_key_exists('message-url', $input)) {
|
if (!array_key_exists('sender', $input) || !array_key_exists('recipient', $input) || !array_key_exists('message-url', $input)) {
|
||||||
nlog('Failed: Message could not be parsed, because required parameters are missing. Please ensure contacting this api-endpoint with a store & notify operation instead of a forward operation!');
|
nlog('Failed: Message could not be parsed, because required parameters are missing. Please ensure contacting this api-endpoint with a store & notify operation instead of a forward operation!');
|
||||||
return response()->json(['message' => 'Failed. Missing Parameters. Use store and notify!'], 400);
|
return response()->json(['message' => 'Failed. Missing Parameters. Use store and notify!'], 400);
|
||||||
|
@ -273,7 +273,9 @@ class PostMarkController extends BaseController
|
|||||||
|
|
||||||
$input = $request->all();
|
$input = $request->all();
|
||||||
|
|
||||||
if (!($request->has('token') && $request->get('token') == config('ninja.inbound_mailbox.inbound_webhook_token')))
|
nlog($input);
|
||||||
|
|
||||||
|
if (!$request->has('token') || $request->token != config('ninja.inbound_mailbox.inbound_webhook_token'))
|
||||||
return response()->json(['message' => 'Unauthorized'], 403);
|
return response()->json(['message' => 'Unauthorized'], 403);
|
||||||
|
|
||||||
if (!(array_key_exists("MessageStream", $input) && $input["MessageStream"] == "inbound") || !array_key_exists("To", $input) || !array_key_exists("From", $input) || !array_key_exists("MessageID", $input)) {
|
if (!(array_key_exists("MessageStream", $input) && $input["MessageStream"] == "inbound") || !array_key_exists("To", $input) || !array_key_exists("From", $input) || !array_key_exists("MessageID", $input)) {
|
||||||
@ -281,17 +283,16 @@ class PostMarkController extends BaseController
|
|||||||
return response()->json(['message' => 'Failed. Missing/Invalid Parameters.'], 400);
|
return response()->json(['message' => 'Failed. Missing/Invalid Parameters.'], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$company = MultiDB::findAndSetDbByExpenseMailbox($input["To"]);
|
$company = MultiDB::findAndSetDbByExpenseMailbox($input["ToFull"][0]["Email"]);
|
||||||
|
|
||||||
if (!$company) {
|
if (!$company) {
|
||||||
nlog('[PostmarkInboundWebhook] unknown Expense Mailbox occured while handling an inbound email from postmark: ' . $input["To"]);
|
nlog('[PostmarkInboundWebhook] unknown Expense Mailbox occured while handling an inbound email from postmark: ' . $input["To"]);
|
||||||
// $inboundEngine->saveMeta($input["From"], $input["To"], true); // important to save this, to protect from spam
|
|
||||||
return response()->json(['message' => 'Ok'], 200);
|
return response()->json(['message' => 'Ok'], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
$inboundEngine = new InboundMailEngine($company);
|
$inboundEngine = new InboundMailEngine($company);
|
||||||
|
|
||||||
if ($inboundEngine->isInvalidOrBlocked($input["From"], $input["To"])) {
|
if ($inboundEngine->isInvalidOrBlocked($input["From"], $input["ToFull"][0]["Email"])) {
|
||||||
return response()->json(['message' => 'Blocked.'], 403);
|
return response()->json(['message' => 'Blocked.'], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,14 +11,15 @@
|
|||||||
|
|
||||||
namespace App\Http\Requests\Company;
|
namespace App\Http\Requests\Company;
|
||||||
|
|
||||||
use App\DataMapper\CompanySettings;
|
|
||||||
use App\Http\Requests\Request;
|
|
||||||
use App\Http\ValidationRules\Company\ValidExpenseMailbox;
|
|
||||||
use App\Http\ValidationRules\ValidSettingsRule;
|
|
||||||
use App\Http\ValidationRules\EInvoice\ValidCompanyScheme;
|
|
||||||
use App\Http\ValidationRules\Company\ValidSubdomain;
|
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
|
use App\Http\Requests\Request;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use App\DataMapper\CompanySettings;
|
||||||
|
use App\Http\ValidationRules\ValidSettingsRule;
|
||||||
|
use App\Http\ValidationRules\Company\ValidSubdomain;
|
||||||
|
use App\Http\ValidationRules\Company\ValidExpenseMailbox;
|
||||||
|
use App\Http\ValidationRules\EInvoice\ValidCompanyScheme;
|
||||||
|
|
||||||
class UpdateCompanyRequest extends Request
|
class UpdateCompanyRequest extends Request
|
||||||
{
|
{
|
||||||
@ -76,7 +77,7 @@ class UpdateCompanyRequest extends Request
|
|||||||
$rules['subdomain'] = ['nullable', 'regex:/^[a-zA-Z0-9.-]+[a-zA-Z0-9]$/', new ValidSubdomain()];
|
$rules['subdomain'] = ['nullable', 'regex:/^[a-zA-Z0-9.-]+[a-zA-Z0-9]$/', new ValidSubdomain()];
|
||||||
}
|
}
|
||||||
|
|
||||||
$rules['expense_mailbox'] = ['email', 'nullable', new ValidExpenseMailbox()];
|
$rules['expense_mailbox'] = ['sometimes','email', 'nullable', new ValidExpenseMailbox(), Rule::unique('companies')->ignore($this->company->id)];
|
||||||
|
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
||||||
|
@ -32,30 +32,21 @@ class ValidExpenseMailbox implements Rule
|
|||||||
|
|
||||||
public function passes($attribute, $value)
|
public function passes($attribute, $value)
|
||||||
{
|
{
|
||||||
if (empty($value)) {
|
if (empty($value) || !config('ninja.inbound_mailbox.expense_mailbox_endings')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// early return, if we dont have any additional validation
|
|
||||||
if (!config('ninja.inbound_mailbox.expense_mailbox_endings')) {
|
|
||||||
$this->validated_schema = true;
|
|
||||||
return MultiDB::checkExpenseMailboxAvailable($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate Schema
|
// Validate Schema
|
||||||
$validated = false;
|
$validated = false;
|
||||||
foreach ($this->endings as $ending) {
|
foreach ($this->endings as $ending) {
|
||||||
if (str_ends_with($value, $ending)) {
|
if (str_ends_with($value, $ending)) {
|
||||||
$validated = true;
|
return true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$validated)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$this->validated_schema = true;
|
|
||||||
return MultiDB::checkExpenseMailboxAvailable($value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +30,7 @@ class InboundMail
|
|||||||
|
|
||||||
public string $text_body;
|
public string $text_body;
|
||||||
|
|
||||||
/** @var array[\Illuminate\Http\UploadedFile] $documents */
|
/** @var array[?\Illuminate\Http\UploadedFile] $documents */
|
||||||
public array $documents = [];
|
public array $documents = [];
|
||||||
|
|
||||||
public ?Carbon $date = null;
|
public ?Carbon $date = null;
|
||||||
|
@ -265,14 +265,14 @@ class InboundMailEngine
|
|||||||
|
|
||||||
// whitelists
|
// whitelists
|
||||||
$whitelist = explode(",", $this->company->inbound_mailbox_whitelist);
|
$whitelist = explode(",", $this->company->inbound_mailbox_whitelist);
|
||||||
if (in_array($email->from, $whitelist))
|
if (is_array($whitelist) && in_array($email->from, $whitelist))
|
||||||
return true;
|
return true;
|
||||||
if (in_array($domain, $whitelist))
|
if (is_array($whitelist) && in_array($domain, $whitelist))
|
||||||
return true;
|
return true;
|
||||||
$blacklist = explode(",", $this->company->inbound_mailbox_blacklist);
|
$blacklist = explode(",", $this->company->inbound_mailbox_blacklist);
|
||||||
if (in_array($email->from, $blacklist))
|
if (is_array($blacklist) && in_array($email->from, $blacklist))
|
||||||
return false;
|
return false;
|
||||||
if (in_array($domain, $blacklist))
|
if (is_array($blacklist) && in_array($domain, $blacklist))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// allow unknown
|
// allow unknown
|
||||||
|
Loading…
x
Reference in New Issue
Block a user