changes related to allow_clients

This commit is contained in:
paulwer 2024-03-25 07:08:41 +01:00
parent 157037f56f
commit 1db0350273
2 changed files with 7 additions and 12 deletions

View File

@ -118,7 +118,7 @@ class ProcessBrevoInboundWebhook implements ShouldQueue
public function handle() public function handle()
{ {
// brevo defines recipients as array to enable webhook processing as batches, we check all of them // brevo defines recipients as array, we check all of them, to be sure
foreach ($this->input["Recipients"] as $recipient) { foreach ($this->input["Recipients"] as $recipient) {
// match company // match company

View File

@ -229,15 +229,13 @@ class InboundMailEngine
if ($this->company->inbound_mailbox_allow_company_users && $this->company->users()->where("email", $this->email->from)->exists()) if ($this->company->inbound_mailbox_allow_company_users && $this->company->users()->where("email", $this->email->from)->exists())
return true; return true;
// from vendors (if active) // from vendors
if ($this->company->inbound_mailbox_allow_vendors && $this->company->vendors()->where("invoicing_email", $this->email->from)->orWhere("invoicing_domain", $domain)->exists()) if ($this->company->inbound_mailbox_allow_vendors && $this->company->vendors()->where("invoicing_email", $this->email->from)->orWhere("invoicing_domain", $domain)->exists())
return true; return true;
if ($this->company->inbound_mailbox_allow_vendors && $this->company->vendors()->contacts()->where("email", $this->email->from)->exists()) if ($this->company->inbound_mailbox_allow_vendors && $this->company->vendors()->contacts()->where("email", $this->email->from)->exists())
return true; return true;
// from clients (if active) // from clients
if ($this->company->inbound_mailbox_allow_clients && $this->company->clients()->where("invoicing_email", $this->email->from)->orWhere("invoicing_domain", $domain)->exists())
return true;
if ($this->company->inbound_mailbox_allow_clients && $this->company->clients()->contacts()->where("email", $this->email->from)->exists()) if ($this->company->inbound_mailbox_allow_clients && $this->company->clients()->contacts()->where("email", $this->email->from)->exists())
return true; return true;
@ -246,14 +244,11 @@ class InboundMailEngine
} }
private function getClient() private function getClient()
{ {
$parts = explode('@', $this->email->from); // $parts = explode('@', $this->email->from);
$domain = array_pop($parts); // $domain = array_pop($parts);
$client = Client::where("company_id", $this->company->id)->where("email", $domain)->first(); $clientContact = ClientContact::where("company_id", $this->company->id)->where("email", $this->email->from)->first();
if ($client == null) { $client = $clientContact->client();
$clientContact = ClientContact::where("company_id", $this->company->id)->where("email", $this->email->from)->first();
$client = $clientContact->client();
}
return $client; return $client;
} }