Changeset View
Changeset View
Standalone View
Standalone View
src/app/Observers/UserObserver.php
Show First 20 Lines • Show All 228 Lines • ▼ Show 20 Lines | public function forceDeleting(User $user) | ||||
->delete(); | ->delete(); | ||||
Transaction::where('object_type', Wallet::class) | Transaction::where('object_type', Wallet::class) | ||||
->whereIn('object_id', $wallets) | ->whereIn('object_id', $wallets) | ||||
->delete(); | ->delete(); | ||||
} | } | ||||
/** | /** | ||||
* Handle the user "restored" event. | |||||
* | |||||
* @param \App\User $user The user | |||||
* | |||||
* @return void | |||||
*/ | |||||
public function restored(User $user) | |||||
{ | |||||
$wallets = $user->wallets()->pluck('id')->all(); | |||||
// Restore all domains (domain entitlements will be restored | |||||
// by DomainObserver) | |||||
$domains = Entitlement::whereIn('wallet_id', $wallets)->withTrashed() | |||||
->where('entitleable_type', Domain::class) | |||||
->pluck('entitleable_id') | |||||
->unique() | |||||
->all(); | |||||
if (!empty($domains)) { | |||||
Domain::withTrashed()->find($domains) | |||||
->each(function ($domain, $key) { | |||||
$domain->restore(); | |||||
}); | |||||
} | |||||
// Restore user entitlements | |||||
// FIXME: entitlements that shouldn't be recovered when a domain is to be restored | |||||
// Should we filter by SKU? | |||||
// Should we restore only these deleted last? | |||||
\App\Entitlement::withTrashed() | |||||
->where('entitleable_id', $user->id) | |||||
->where('entitleable_type', User::class) | |||||
->update(['updated_at' => now(), 'deleted_at' => null]); | |||||
vanmeeuwen: Here too, please avoid touching `updated_at`. | |||||
// Make sure it's not DELETED/LDAP_READY/IMAP_READY anymore | |||||
if ($user->isDeleted()) { | |||||
$user->status ^= User::STATUS_DELETED; | |||||
} | |||||
if ($user->isLdapReady()) { | |||||
$user->status ^= User::STATUS_LDAP_READY; | |||||
} | |||||
if ($user->isImapReady()) { | |||||
$user->status ^= User::STATUS_IMAP_READY; | |||||
} | |||||
/* FIXME: Should we also unsuspend the user? | |||||
if ($user->isSuspended()) { | |||||
$user->status ^= User::STATUS_SUSPENDED; | |||||
} | |||||
*/ | |||||
// FIXME: Should we modify created_at/updated_at? | |||||
$user->save(); | |||||
// Create user record in LDAP, then check if the account is created in IMAP | |||||
$chain = [ | |||||
new \App\Jobs\User\VerifyJob($user->id), | |||||
]; | |||||
\App\Jobs\User\CreateJob::withChain($chain)->dispatch($user->id); | |||||
} | |||||
/** | |||||
* Handle the "retrieving" event. | * Handle the "retrieving" event. | ||||
* | * | ||||
* @param User $user The user that is being retrieved. | * @param User $user The user that is being retrieved. | ||||
* | * | ||||
* @todo This is useful for audit. | * @todo This is useful for audit. | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
Show All 17 Lines |
Here too, please avoid touching updated_at.