From 67a7449ffcf261468c857b86a71efca746d5ef9c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 30 Sep 2024 10:33:51 +1000 Subject: [PATCH] Ensure activities have account_id set --- app/Listeners/User/ArchivedUserActivity.php | 1 + app/Listeners/User/CreatedUserActivity.php | 1 + app/Listeners/User/DeletedUserActivity.php | 1 + app/Listeners/User/RestoredUserActivity.php | 1 + app/Listeners/User/UpdatedUserActivity.php | 2 ++ app/Models/Company.php | 2 +- 6 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Listeners/User/ArchivedUserActivity.php b/app/Listeners/User/ArchivedUserActivity.php index 02f1e8bf6cfe..8c3d43db55fd 100644 --- a/app/Listeners/User/ArchivedUserActivity.php +++ b/app/Listeners/User/ArchivedUserActivity.php @@ -49,6 +49,7 @@ class ArchivedUserActivity implements ShouldQueue $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::ARCHIVE_USER; + $fields->account_id = $event->company->account_id; $this->activityRepo->save($fields, $event->user, $event->event_vars); } diff --git a/app/Listeners/User/CreatedUserActivity.php b/app/Listeners/User/CreatedUserActivity.php index d4325eb6aa2c..bb76aab118ad 100644 --- a/app/Listeners/User/CreatedUserActivity.php +++ b/app/Listeners/User/CreatedUserActivity.php @@ -48,6 +48,7 @@ class CreatedUserActivity implements ShouldQueue $fields->user_id = $user_id; $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::CREATE_USER; + $fields->account_id = $event->company->account_id; $this->activityRepo->save($fields, $event->user, $event->event_vars); } diff --git a/app/Listeners/User/DeletedUserActivity.php b/app/Listeners/User/DeletedUserActivity.php index 6d98bc123d1a..9b1c7d416ae0 100644 --- a/app/Listeners/User/DeletedUserActivity.php +++ b/app/Listeners/User/DeletedUserActivity.php @@ -55,6 +55,7 @@ class DeletedUserActivity implements ShouldQueue $fields->user_id = $user_id; $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::DELETE_USER; + $fields->account_id = $event->company->account_id; $this->activityRepo->save($fields, $event->user, $event->event_vars); } diff --git a/app/Listeners/User/RestoredUserActivity.php b/app/Listeners/User/RestoredUserActivity.php index 47859b2c079a..f1636c4afed6 100644 --- a/app/Listeners/User/RestoredUserActivity.php +++ b/app/Listeners/User/RestoredUserActivity.php @@ -48,6 +48,7 @@ class RestoredUserActivity implements ShouldQueue $fields->company_id = $event->company->id; $fields->activity_type_id = Activity::RESTORE_USER; + $fields->account_id = $event->company->account_id; $this->activityRepo->save($fields, $event->user, $event->event_vars); } diff --git a/app/Listeners/User/UpdatedUserActivity.php b/app/Listeners/User/UpdatedUserActivity.php index dc48eae4280c..1959ab2a2058 100644 --- a/app/Listeners/User/UpdatedUserActivity.php +++ b/app/Listeners/User/UpdatedUserActivity.php @@ -47,6 +47,8 @@ class UpdatedUserActivity implements ShouldQueue $fields->user_id = $user_id; $fields->company_id = $event->company->id; + $fields->account_id = $event->company->account_id; + $fields->activity_type_id = Activity::UPDATE_USER; $this->activityRepo->save($fields, $event->user, $event->event_vars); diff --git a/app/Models/Company.php b/app/Models/Company.php index a8d2bb7a1299..38f1292017f4 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -576,7 +576,7 @@ class Company extends BaseModel public function activities(): HasMany { - return $this->hasMany(Activity::class)->orderBy('id', 'DESC')->take(50); + return $this->hasMany(Activity::class)->where('account_id', $this->account_id)->orderBy('id', 'DESC')->take(50); } /**