From 2a7bdc8d5902e40770b042393751a1720d3d932e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 7 Nov 2021 22:12:54 +1100 Subject: [PATCH] Fixes for User Add rules in hosted --- app/Http/Controllers/PreviewController.php | 2 -- .../ValidationRules/Ninja/CanAddUserRule.php | 23 +++++-------------- .../Ninja/CanRestoreUserRule.php | 16 ++++++------- 3 files changed, 13 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 19489a4b7d..153f76a656 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -217,8 +217,6 @@ class PreviewController extends BaseController if(!$request->has('entity_id')) $entity_obj->service()->fillDefaults()->save(); - // $entity_obj->load('client.contacts','client.company'); - App::forgetInstance('translator'); $t = app('translator'); App::setLocale($entity_obj->client->locale()); diff --git a/app/Http/ValidationRules/Ninja/CanAddUserRule.php b/app/Http/ValidationRules/Ninja/CanAddUserRule.php index 1c85687bf3..4e88125507 100644 --- a/app/Http/ValidationRules/Ninja/CanAddUserRule.php +++ b/app/Http/ValidationRules/Ninja/CanAddUserRule.php @@ -33,25 +33,14 @@ class CanAddUserRule implements Rule public function passes($attribute, $value) { - // $count = CompanyUser::query() - // ->with('user') - // ->where('account_id', auth()->user()->account_id) - // ->distinct() - // ->select('user_id') - // ->count(); - - - $count = User::query() - ->with(['company_user' => function ($query){ - return $query->whereNull('company_user.deleted_at'); - }]) - ->where('account_id', auth()->user()->account_id) - ->distinct() - ->select('users.id') - ->count(); + $count = CompanyUser::query() + ->where('account_id', auth()->user()->account_id) + ->whereNull('deleted_at') + ->distinct() + ->count('user_id'); return $count < auth()->user()->company()->account->num_users; - //return auth()->user()->company()->account->users->count() < auth()->user()->company()->account->num_users; + } /** diff --git a/app/Http/ValidationRules/Ninja/CanRestoreUserRule.php b/app/Http/ValidationRules/Ninja/CanRestoreUserRule.php index 45bf5ec7f3..db7291dc19 100644 --- a/app/Http/ValidationRules/Ninja/CanRestoreUserRule.php +++ b/app/Http/ValidationRules/Ninja/CanRestoreUserRule.php @@ -33,17 +33,15 @@ class CanRestoreUserRule implements Rule public function passes($attribute, $value) { - $count = User::query() - ->with(['company_user' => function ($query){ - return $query->whereNull('company_user.deleted_at'); - }]) - ->where('account_id', 1) - ->distinct() - ->select('users.id') - ->count(); + $count = CompanyUser::query() + ->where('account_id', auth()->user()->account_id) + ->whereNull('deleted_at') + ->distinct() + ->count('user_id'); + return $count < auth()->user()->company()->account->num_users; - //return auth()->user()->company()->account->users->count() < auth()->user()->company()->account->num_users; + } /**