Compare commits

..

No commits in common. "b1438e5ca1dfb8dc3236911b974ead3467f90738" and "2227620cc7954571998d316ad7f2ef946c617266" have entirely different histories.

7 changed files with 7 additions and 38 deletions

View file

@ -1,3 +0,0 @@
0.2.0
* On the initial package install, link existing Customers to Mailboxes.

View file

@ -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.2.0" composer require "millions-missing-france/freescout-restricted-customers" "0.1.2"
``` ```
### Edit the application routes ### Edit the application routes

View file

@ -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.2.0", "version": "0.1.2",
"type": "library", "type": "library",
"license": ["AGPL-3.0-only"], "license": ["AGPL-3.0-only"],
"authors": [ "authors": [

View file

@ -7,7 +7,6 @@
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 {
@ -31,14 +30,6 @@ 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>');
} }
/** /**

View file

@ -82,26 +82,4 @@ 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();
}
}
} }

View file

@ -159,7 +159,11 @@ 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->where('customers.mailbox_id', '=', $filters['mailbox']); $query_customers->join('conversations', function ($join) use ($filters) {
$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);

View file

@ -250,7 +250,6 @@ 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);
} }