diff --git a/Entities/Customer.php b/Entities/Customer.php index eb6e050..fe5e1ca 100644 --- a/Entities/Customer.php +++ b/Entities/Customer.php @@ -59,6 +59,7 @@ class Customer extends BaseCustomer { ::where('id', '=', $id) ->whereIn('mailbox_id', $mailboxes) ->first($columns); + return $customer; } /** diff --git a/Providers/MMFRestrictedCustomersServiceProvider.php b/Providers/MMFRestrictedCustomersServiceProvider.php index 5ce18dc..93bf992 100644 --- a/Providers/MMFRestrictedCustomersServiceProvider.php +++ b/Providers/MMFRestrictedCustomersServiceProvider.php @@ -15,6 +15,7 @@ use Illuminate\Support\ServiceProvider; use App\User; use Modules\MMFRestrictedCustomers\Console\Commands\FetchEmails; +use Modules\MMFRestrictedCustomers\Entities\Customer; class MMFRestrictedCustomersServiceProvider extends ServiceProvider { /** @@ -69,6 +70,12 @@ class MMFRestrictedCustomersServiceProvider extends ServiceProvider { if ( array_key_exists('mailbox_id', $data) ) { $customer->mailbox_id = $data['mailbox_id']; } else { + $customer = Customer::find($customer->id); + if ( $customer == null ) { + Log::error('Trying to use a Customer in another Mailbox than the one it is linked to is not allowed, and has been aborted.'); + // TODO: Error out more gracefully. + abort(500, 'Trying to use a Customer in another Mailbox than the one it is linked to is not allowed, and has been aborted.'); + } if ( $customer->mailbox_id == null ) { Log::error('The creation of a Customer with no link to a Mailbox is not allowed, and has been aborted.'); // TODO: Error out more gracefully.