mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 05:58:50 -05:00 
			
		
		
		
	Fixes for test
This commit is contained in:
		
							parent
							
								
									0079e52b85
								
							
						
					
					
						commit
						ba672f6fdd
					
				@ -45,9 +45,6 @@ class UpdateUserRequest extends Request
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        $input = $this->all();
 | 
					        $input = $this->all();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // if (isset($input['company_user']) && ! auth()->user()->isAdmin()) {
 | 
					 | 
				
			||||||
        //     unset($input['company_user']);
 | 
					 | 
				
			||||||
        // }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $this->replace($input);
 | 
					        $this->replace($input);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -60,12 +60,6 @@ class UniqueUserRule implements Rule
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    private function checkIfEmailExists($email) : bool
 | 
					    private function checkIfEmailExists($email) : bool
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $current_db = config('database.default');
 | 
					        return MultiDB::checkUserEmailExists($email);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        $result =  MultiDB::checkUserEmailExists($email);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        MultiDB::setDb($current_db);
 | 
					 | 
				
			||||||
        
 | 
					 | 
				
			||||||
        return $result;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -20,6 +20,7 @@ use Illuminate\Contracts\Validation\Rule;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class AttachableUser implements Rule
 | 
					class AttachableUser implements Rule
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    public $message;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function __construct()
 | 
					    public function __construct()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -39,7 +40,7 @@ class AttachableUser implements Rule
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function message()
 | 
					    public function message()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return "Cannot add the same user to the same company";
 | 
					        return $this->message;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -63,9 +64,16 @@ class AttachableUser implements Rule
 | 
				
			|||||||
                                    ->where('company_id', auth()->user()->company()->id)
 | 
					                                    ->where('company_id', auth()->user()->company()->id)
 | 
				
			||||||
                                    ->exists();
 | 
					                                    ->exists();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if($user_already_attached)
 | 
					        //If the user is already attached or isn't link to this account - return false
 | 
				
			||||||
 | 
					        if($user_already_attached) {
 | 
				
			||||||
 | 
					            $this->message = ctrans('texts.user_duplicate_error');
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
 | 
					        } 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if($user->account_id != auth()->user()->account_id){
 | 
				
			||||||
 | 
					            $this->message = ctrans('texts.user_cross_linked_error');
 | 
				
			||||||
 | 
					            return false;            
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -26,14 +26,7 @@ class ValidUserForCompany implements Rule
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function passes($attribute, $value)
 | 
					    public function passes($attribute, $value)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $current_db = config('database.default');
 | 
					        return MultiDB::checkUserAndCompanyCoExist($value, auth()->user()->company()->company_key, auth()->user()->company()->id);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        $result = MultiDB::checkUserAndCompanyCoExist($value, auth()->user()->company()->company_key, auth()->user()->company()->id);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        MultiDB::setDb($current_db);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        return $result;
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -423,7 +423,8 @@ class Import implements ShouldQueue
 | 
				
			|||||||
        $rules = [
 | 
					        $rules = [
 | 
				
			||||||
            '*.first_name' => ['string'],
 | 
					            '*.first_name' => ['string'],
 | 
				
			||||||
            '*.last_name' => ['string'],
 | 
					            '*.last_name' => ['string'],
 | 
				
			||||||
            '*.email' => ['distinct'],
 | 
					            //'*.email' => ['distinct'],
 | 
				
			||||||
 | 
					            '*.email' => ['distinct', 'email', new ValidUserForCompany(), new AttachableUser()],
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // if (config('ninja.db.multi_db_enabled')) {
 | 
					        // if (config('ninja.db.multi_db_enabled')) {
 | 
				
			||||||
 | 
				
			|||||||
@ -106,8 +106,8 @@ class MultiDB
 | 
				
			|||||||
        $current_db = config('database.default');  
 | 
					        $current_db = config('database.default');  
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach (self::$dbs as $db) {
 | 
					        foreach (self::$dbs as $db) {
 | 
				
			||||||
            if (User::on($db)->where(['email' => $email])->get()->count() >= 1) { // if user already exists, validation will fail
 | 
					            if (User::on($db)->where(['email' => $email])->exists()) { 
 | 
				
			||||||
                if (Company::on($db)->where(['company_key' => $company_key])->get()->count() >= 1) {
 | 
					                if (Company::on($db)->where(['company_key' => $company_key])->exists()) {
 | 
				
			||||||
                    self::setDb($current_db);
 | 
					                    self::setDb($current_db);
 | 
				
			||||||
                    return true;
 | 
					                    return true;
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
 | 
				
			|||||||
@ -38,7 +38,7 @@ class UpdateReminder extends AbstractService
 | 
				
			|||||||
            $this->invoice->next_send_date = null;
 | 
					            $this->invoice->next_send_date = null;
 | 
				
			||||||
            $this->invoice->save();
 | 
					            $this->invoice->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return; //exit early
 | 
					            return $this->invoice; //exit early
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $date_collection = collect();
 | 
					        $date_collection = collect();
 | 
				
			||||||
 | 
				
			|||||||
@ -4252,6 +4252,8 @@ $LANG = array(
 | 
				
			|||||||
    'contact_details' => 'Contact Details',
 | 
					    'contact_details' => 'Contact Details',
 | 
				
			||||||
    'download_backup_subject' => 'Your company backup is ready for download',
 | 
					    'download_backup_subject' => 'Your company backup is ready for download',
 | 
				
			||||||
    'account_passwordless_login' => 'Account passwordless login',
 | 
					    'account_passwordless_login' => 'Account passwordless login',
 | 
				
			||||||
 | 
					    'user_duplicate_error' => 'Cannot add the same user to the same company',
 | 
				
			||||||
 | 
					    'user_cross_linked_error' => 'User exists but cannot be crossed linked to multiple accounts',
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
return $LANG;
 | 
					return $LANG;
 | 
				
			||||||
 | 
				
			|||||||
@ -25,7 +25,6 @@ class CheckRemindersTest extends TestCase
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    use MockAccountData;
 | 
					    use MockAccountData;
 | 
				
			||||||
    use DatabaseTransactions;
 | 
					    use DatabaseTransactions;
 | 
				
			||||||
    use MakesReminders;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function setUp() :void
 | 
					    public function setUp() :void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
				
			|||||||
@ -192,10 +192,10 @@ trait MockAccountData
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if (! $user) {
 | 
					        if (! $user) {
 | 
				
			||||||
            $user = User::factory()->create([
 | 
					            $user = User::factory()->create([
 | 
				
			||||||
                                'account_id' => $this->account->id,
 | 
					                'account_id' => $this->account->id,
 | 
				
			||||||
                                'confirmation_code' => $this->createDbHash(config('database.default')),
 | 
					                'confirmation_code' => $this->createDbHash(config('database.default')),
 | 
				
			||||||
                                'email' => 'user@example.com',
 | 
					                'email' => 'user@example.com',
 | 
				
			||||||
                            ]);
 | 
					            ]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $user->password = Hash::make('ALongAndBriliantPassword');
 | 
					        $user->password = Hash::make('ALongAndBriliantPassword');
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user