Compare commits
5 commits
2227620cc7
...
b1438e5ca1
Author | SHA1 | Date | |
---|---|---|---|
b1438e5ca1 | |||
a735b8aa2b | |||
3f48a3cf60 | |||
aa9c1624a1 | |||
509058ec46 |
7 changed files with 38 additions and 7 deletions
3
CHANGELOG
Normal file
3
CHANGELOG
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
0.2.0
|
||||||
|
|
||||||
|
* On the initial package install, link existing Customers to Mailboxes.
|
|
@ -19,7 +19,7 @@ You have been warned.
|
||||||
### Install the package with composer
|
### Install the package with composer
|
||||||
|
|
||||||
```
|
```
|
||||||
composer require "millions-missing-france/freescout-restricted-customers" "0.1.2"
|
composer require "millions-missing-france/freescout-restricted-customers" "0.2.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Edit the application routes
|
### Edit the application routes
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "millions-missing-france/freescout-restricted-customers",
|
"name": "millions-missing-france/freescout-restricted-customers",
|
||||||
"description": "Freescout restricted customers - Restrict access to Freescout customers to specific mailboxes",
|
"description": "Freescout restricted customers - Restrict access to Freescout customers to specific mailboxes",
|
||||||
"version": "0.1.2",
|
"version": "0.2.0",
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"license": ["AGPL-3.0-only"],
|
"license": ["AGPL-3.0-only"],
|
||||||
"authors": [
|
"authors": [
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
use MillionsMissingFrance\FreescoutRestrictedCustomers\Customer;
|
use MillionsMissingFrance\FreescoutRestrictedCustomers\Customer;
|
||||||
|
|
||||||
class AddMailboxIdColumnToCustomersTable extends Migration {
|
class AddMailboxIdColumnToCustomersTable extends Migration {
|
||||||
|
@ -30,6 +31,14 @@ class AddMailboxIdColumnToCustomersTable extends Migration {
|
||||||
// On mailbox deletion, delete all customer entries that are linked to it.
|
// On mailbox deletion, delete all customer entries that are linked to it.
|
||||||
->onDelete('cascade');
|
->onDelete('cascade');
|
||||||
});
|
});
|
||||||
|
// Link Customers to Mailboxes, through their Conversation information.
|
||||||
|
$output = new ConsoleOutput();
|
||||||
|
$output->writeln('<info>Linking existing Customers to Mailboxes, it might take a couple minutes…</info>');
|
||||||
|
$customers = Customer::all();
|
||||||
|
$customers->each(function ($customer) {
|
||||||
|
$customer->linkToMailboxThroughConversations();
|
||||||
|
});
|
||||||
|
$output->writeln('<info>Linking existing Customers to Mailboxes done.</info>');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -82,4 +82,26 @@ class Customer extends BaseCustomer {
|
||||||
->whereIn('mailbox_id', $mailboxes)
|
->whereIn('mailbox_id', $mailboxes)
|
||||||
->first($columns);
|
->first($columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the Mailboxes this Customer is linked to through Conversations.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function mailboxesThroughConversations() {
|
||||||
|
return $this
|
||||||
|
->conversations
|
||||||
|
->pluck('mailbox');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If this Customer is linked to a single Mailbox through Conversations, link it to it.
|
||||||
|
*/
|
||||||
|
public function linkToMailboxThroughConversations() {
|
||||||
|
$mailboxes = $this->mailboxesThroughConversations();
|
||||||
|
if ( $mailboxes->count() == 1 ) {
|
||||||
|
$this->mailbox_id = $mailboxes->first()->id;
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,11 +159,7 @@ class ConversationsController extends BaseConversationsController {
|
||||||
->whereIn('customers.mailbox_id', $mailbox_ids);
|
->whereIn('customers.mailbox_id', $mailbox_ids);
|
||||||
|
|
||||||
if (!empty($filters['mailbox']) && in_array($filters['mailbox'], $mailbox_ids)) {
|
if (!empty($filters['mailbox']) && in_array($filters['mailbox'], $mailbox_ids)) {
|
||||||
$query_customers->join('conversations', function ($join) use ($filters) {
|
$query_customers->where('customers.mailbox_id', '=', $filters['mailbox']);
|
||||||
$join->on('conversations.customer_id', '=', 'customers.id');
|
|
||||||
//$join->on('conversations.mailbox_id', '=', $filters['mailbox']);
|
|
||||||
});
|
|
||||||
$query_customers->where('conversations.mailbox_id', '=', $filters['mailbox']);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$query_customers = \Eventy::filter('search.customers.apply_filters', $query_customers, $filters, $q);
|
$query_customers = \Eventy::filter('search.customers.apply_filters', $query_customers, $filters, $q);
|
||||||
|
|
|
@ -250,6 +250,7 @@ class CustomersController extends BaseCustomersController {
|
||||||
$customers_query->where(function($customers_query) use($request, $q) {
|
$customers_query->where(function($customers_query) use($request, $q) {
|
||||||
if ($request->search_by == 'all' || $request->search_by == 'email') {
|
if ($request->search_by == 'all' || $request->search_by == 'email') {
|
||||||
$customers_query->where('emails.email', 'like', '%'.$q.'%');
|
$customers_query->where('emails.email', 'like', '%'.$q.'%');
|
||||||
|
}
|
||||||
if ($request->exclude_email) {
|
if ($request->exclude_email) {
|
||||||
$customers_query->where('emails.email', '<>', $request->exclude_email);
|
$customers_query->where('emails.email', '<>', $request->exclude_email);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue