From 45028e03a92451222c7f5fd93708717af5bae02f Mon Sep 17 00:00:00 2001 From: Antoine Le Gonidec Date: Sat, 20 Jul 2024 18:48:58 +0200 Subject: [PATCH] Add compatibility with MMFCustomersGroups --- Providers/MMFRestrictedCustomersServiceProvider.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Providers/MMFRestrictedCustomersServiceProvider.php b/Providers/MMFRestrictedCustomersServiceProvider.php index a5a7b77..be69681 100644 --- a/Providers/MMFRestrictedCustomersServiceProvider.php +++ b/Providers/MMFRestrictedCustomersServiceProvider.php @@ -68,6 +68,19 @@ class MMFRestrictedCustomersServiceProvider extends ServiceProvider { $priority = 20, $arguments = 3 ); + + // Filter the list of Customers returned by MMFCustomersGroups when creating/editing a Customers Group. + Eventy::addFilter('mmfcustomergroups.groups.create.customers-query', function($customers_query) { + $user = auth()->user(); + // Do not restrict the query if the current user is an admin. + if ( $user->role != User::ROLE_ADMIN ) { + // Get IDs of mailboxes the current user is allowed to access. + $mailboxes = $user->mailboxesIdsCanView(); + // Restrict the query to the Customers the current user is allowed to access. + $customers_query->whereIn('customers.mailbox_id', $mailboxes); + } + return $customers_query; + }); } /**