mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 22:07:33 -05: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();
 | 
					        $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))
 | 
					        if(array_key_exists('email', $input))
 | 
				
			||||||
            $input['email'] = trim($input['email']);
 | 
					            $input['email'] = trim($input['email']);
 | 
				
			||||||
 | 
				
			|||||||
@ -33,13 +33,18 @@ class CanAddUserRule implements Rule
 | 
				
			|||||||
    public function passes($attribute, $value)
 | 
					    public function passes($attribute, $value)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
          $count = CompanyUser::query()
 | 
					        /* If the user is active then we can add them to the company */
 | 
				
			||||||
                              ->where('company_user.account_id', auth()->user()->account_id)
 | 
					        if(User::where('email', request()->input('email'))->where('account_id', auth()->user()->account_id)->where('is_deleted',0)->exists())
 | 
				
			||||||
                              ->join('users', 'users.id', '=', 'company_user.user_id')
 | 
					            return true;
 | 
				
			||||||
                              ->whereNull('users.deleted_at')
 | 
					
 | 
				
			||||||
                              ->whereNull('company_user.deleted_at')
 | 
					        /* Check that we have sufficient quota to allow this to happen */
 | 
				
			||||||
                              ->distinct()
 | 
					        $count = CompanyUser::query()
 | 
				
			||||||
                              ->count('company_user.user_id');
 | 
					                          ->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;
 | 
					        return $count < auth()->user()->company()->account->num_users;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -171,7 +171,7 @@ class Company extends BaseModel
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function users()
 | 
					    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()
 | 
					    public function expense_categories()
 | 
				
			||||||
 | 
				
			|||||||
@ -189,6 +189,14 @@ class UserRepository extends BaseRepository
 | 
				
			|||||||
            return;
 | 
					            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->is_deleted = false;
 | 
				
			||||||
        $user->save();
 | 
					        $user->save();
 | 
				
			||||||
        $user->restore();
 | 
					        $user->restore();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user