Add compatibility with MMFCustomersGroups

This commit is contained in:
Antoine Le Gonidec 2024-07-20 18:48:58 +02:00
parent 69c518086e
commit 45028e03a9
Signed by: vv221
GPG key ID: 636B78F91CEB80D8

View file

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