diff --git a/app/Jobs/Auth/DeleteUser.php b/app/Jobs/Auth/DeleteUser.php index c71b20302..e2dc1a722 100644 --- a/app/Jobs/Auth/DeleteUser.php +++ b/app/Jobs/Auth/DeleteUser.php @@ -16,6 +16,8 @@ class DeleteUser extends Job implements ShouldDelete event(new UserDeleting($this->model)); \DB::transaction(function () { + $this->deleteRelationships($this->model, ['invitation']); + $this->model->delete(); $this->model->flushCache(); diff --git a/app/Listeners/Auth/DeleteUserInvitation.php b/app/Listeners/Auth/DeleteUserInvitation.php deleted file mode 100644 index b4eb8597a..000000000 --- a/app/Listeners/Auth/DeleteUserInvitation.php +++ /dev/null @@ -1,28 +0,0 @@ -user->id)->get(); - - foreach ($invitations as $invitation) { - $this->dispatch(new DeleteInvitation($invitation)); - } - } -} diff --git a/app/Listeners/Update/V30/Version304.php b/app/Listeners/Update/V30/Version304.php index fd836f850..de4f6e069 100644 --- a/app/Listeners/Update/V30/Version304.php +++ b/app/Listeners/Update/V30/Version304.php @@ -58,6 +58,7 @@ class Version304 extends Listener $files = [ 'app/Events/Auth/InvitationCreated.php', 'app/Listeners/Auth/SendUserInvitation.php', + 'app/Listeners/Auth/DeleteUserInvitation.php', ]; foreach ($files as $file) { diff --git a/app/Models/Auth/User.php b/app/Models/Auth/User.php index e51b4fa1b..bed0d6aa0 100644 --- a/app/Models/Auth/User.php +++ b/app/Models/Auth/User.php @@ -89,6 +89,11 @@ class User extends Authenticatable implements HasLocalePreference return $this->belongsToMany('App\Models\Common\Dashboard', 'App\Models\Auth\UserDashboard'); } + public function invitation() + { + return $this->hasOne('App\Models\Auth\UserInvitation', 'user_id', 'id'); + } + /** * Always capitalize the name when we retrieve it */ diff --git a/app/Providers/Event.php b/app/Providers/Event.php index ae239981c..05ad6759e 100644 --- a/app/Providers/Event.php +++ b/app/Providers/Event.php @@ -32,12 +32,6 @@ class Event extends Provider 'App\Events\Auth\LandingPageShowing' => [ 'App\Listeners\Auth\AddLandingPages', ], - 'App\Events\Auth\InvitationCreated' => [ - 'App\Listeners\Auth\SendUserInvitation', - ], - 'App\Events\Auth\UserDeleted' => [ - 'App\Listeners\Auth\DeleteUserInvitation', - ], 'App\Events\Document\DocumentCreated' => [ 'App\Listeners\Document\CreateDocumentCreatedHistory', 'App\Listeners\Document\IncreaseNextDocumentNumber',