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; + }); } /**