Log an explicit error when trying to create a Customer without a Mailbox

This commit is contained in:
Antoine Le Gonidec 2024-07-22 18:05:54 +02:00
parent 4207b8093c
commit f861f240d1
Signed by: vv221
GPG key ID: 636B78F91CEB80D8

View file

@ -6,10 +6,14 @@
namespace Modules\MMFRestrictedCustomers\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Eloquent\Factory;
use Eventy;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;
use App\User;
use Modules\MMFRestrictedCustomers\Console\Commands\FetchEmails;
class MMFRestrictedCustomersServiceProvider extends ServiceProvider {
@ -57,13 +61,20 @@ class MMFRestrictedCustomersServiceProvider extends ServiceProvider {
Eventy::addAction(
'customer.set_data',
function($customer, $data, $replace_data) {
if ( isset($data['mailbox']) ) {
if ( array_key_exists('mailbox', $data) ) {
// TODO: Check that the current user is allowed to access this Mailbox.
$data['mailbox_id'] = $data['mailbox'];
unset($data['mailbox']);
}
// TODO: Throw an error if the Mailbox is not set.
if ( array_key_exists('mailbox_id', $data) ) {
$customer->mailbox_id = $data['mailbox_id'];
} else {
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.
abort(500, 'The creation of a Customer with no link to a Mailbox is not allowed, and has been aborted.');
}
}
},
$priority = 20,
$arguments = 3