mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
fixes for adding users into the production system
This commit is contained in:
parent
539fc1dcfd
commit
f66c3076f1
@ -58,7 +58,7 @@ class StoreUserRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
//unique user rule - check company_user table for user_id / company_id / account_id if none exist we can add the user. ELSE return false
|
||||
//unique user rule - check company_user table for user_id / company_id / account_id if none exist we can add the user. ELSE return false
|
||||
|
||||
if(array_key_exists('email', $input))
|
||||
$input['email'] = trim($input['email']);
|
||||
|
@ -33,13 +33,18 @@ class CanAddUserRule implements Rule
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
|
||||
$count = CompanyUser::query()
|
||||
->where('company_user.account_id', auth()->user()->account_id)
|
||||
->join('users', 'users.id', '=', 'company_user.user_id')
|
||||
->whereNull('users.deleted_at')
|
||||
->whereNull('company_user.deleted_at')
|
||||
->distinct()
|
||||
->count('company_user.user_id');
|
||||
/* If the user is active then we can add them to the company */
|
||||
if(User::where('email', request()->input('email'))->where('account_id', auth()->user()->account_id)->where('is_deleted',0)->exists())
|
||||
return true;
|
||||
|
||||
/* Check that we have sufficient quota to allow this to happen */
|
||||
$count = CompanyUser::query()
|
||||
->where('company_user.account_id', auth()->user()->account_id)
|
||||
->join('users', 'users.id', '=', 'company_user.user_id')
|
||||
->whereNull('users.deleted_at')
|
||||
->whereNull('company_user.deleted_at')
|
||||
->distinct()
|
||||
->count('company_user.user_id');
|
||||
|
||||
return $count < auth()->user()->company()->account->num_users;
|
||||
|
||||
|
@ -171,7 +171,7 @@ class Company extends BaseModel
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->hasManyThrough(User::class, CompanyUser::class, 'company_id', 'id', 'id', 'user_id');
|
||||
return $this->hasManyThrough(User::class, CompanyUser::class, 'company_id', 'id', 'id', 'user_id')->withTrashed();
|
||||
}
|
||||
|
||||
public function expense_categories()
|
||||
|
@ -189,6 +189,14 @@ class UserRepository extends BaseRepository
|
||||
return;
|
||||
}
|
||||
|
||||
if (Ninja::isHosted()) {
|
||||
|
||||
$count = User::where('account_id', auth()->user()->account_id)->count();
|
||||
if($count >= auth()->user()->account->num_users)
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
$user->is_deleted = false;
|
||||
$user->save();
|
||||
$user->restore();
|
||||
|
Loading…
x
Reference in New Issue
Block a user