Compare commits

...

5 commits

Author SHA1 Message Date
b1438e5ca1
0.2.0 release
* On the initial package install, link existing Customers to Mailboxes
2024-07-08 13:01:54 +02:00
a735b8aa2b
Display console messages during the migration 2024-07-08 12:59:47 +02:00
3f48a3cf60
Fix syntax error in CustomersController@ajaxSearch 2024-07-08 12:51:54 +02:00
aa9c1624a1
On initial install, link existing Customers to Mailboxes
The link is set only for Customers that are linked to exactly one Mailbox,
through the Conversations they are linked to.
2024-07-08 12:44:40 +02:00
509058ec46
Expand the ability to restrict a Customers list to a specific Mailbox
The results now include Customers created through the admin interface,
not only the ones created from a Conversation.
2024-07-08 11:48:31 +02:00
7 changed files with 38 additions and 7 deletions

3
CHANGELOG Normal file
View file

@ -0,0 +1,3 @@
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
```
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

View file

@ -1,7 +1,7 @@
{
"name": "millions-missing-france/freescout-restricted-customers",
"description": "Freescout restricted customers - Restrict access to Freescout customers to specific mailboxes",
"version": "0.1.2",
"version": "0.2.0",
"type": "library",
"license": ["AGPL-3.0-only"],
"authors": [

View file

@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Symfony\Component\Console\Output\ConsoleOutput;
use MillionsMissingFrance\FreescoutRestrictedCustomers\Customer;
class AddMailboxIdColumnToCustomersTable extends Migration {
@ -30,6 +31,14 @@ class AddMailboxIdColumnToCustomersTable extends Migration {
// On mailbox deletion, delete all customer entries that are linked to it.
->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,4 +82,26 @@ class Customer extends BaseCustomer {
->whereIn('mailbox_id', $mailboxes)
->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,11 +159,7 @@ class ConversationsController extends BaseConversationsController {
->whereIn('customers.mailbox_id', $mailbox_ids);
if (!empty($filters['mailbox']) && in_array($filters['mailbox'], $mailbox_ids)) {
$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->where('customers.mailbox_id', '=', $filters['mailbox']);
}
$query_customers = \Eventy::filter('search.customers.apply_filters', $query_customers, $filters, $q);

View file

@ -250,6 +250,7 @@ class CustomersController extends BaseCustomersController {
$customers_query->where(function($customers_query) use($request, $q) {
if ($request->search_by == 'all' || $request->search_by == 'email') {
$customers_query->where('emails.email', 'like', '%'.$q.'%');
}
if ($request->exclude_email) {
$customers_query->where('emails.email', '<>', $request->exclude_email);
}