From ea16e302775c40fca4423242f1339aaaade44fa7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 7 Jun 2025 19:07:54 +1000 Subject: [PATCH] Fixes for user checks when restoring a company --- app/Jobs/Company/CompanyImport.php | 4 +- composer.json | 3 +- composer.lock | 76 ++++++++++++++++++++++++++---- 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 44c60ace77..388d62fea8 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -1427,10 +1427,12 @@ class CompanyImport implements ShouldQueue //foreach ($this->backup_file->users as $user) foreach ((object)$this->getObject("users") as $user) { - if (User::withTrashed()->where('email', $user->email)->where('account_id', '!=', $this->account->id)->exists()) { + if($user = MultiDB::hasUser(['email' => $user->email]) && $user->account_id != $this->account->id) { //ensures that we do no inject existing users into the new account. throw new ImportCompanyFailed("{$user->email} is already in the system attached to a different account"); } + MultiDB::setDb($this->company->db); + $user_array = (array)$user; unset($user_array['laravel_through_key']); unset($user_array['hashed_id']); diff --git a/composer.json b/composer.json index 17a06e6b32..776e063dfa 100644 --- a/composer.json +++ b/composer.json @@ -116,7 +116,8 @@ "twig/twig": "^3.14", "twilio/sdk": "^6.40", "wikimedia/composer-merge-plugin": "^2.1", - "wildbit/postmark-php": "^4.0" + "wildbit/postmark-php": "^4.0", + "invoiceninja/admin-api": "dev-main" }, "require-dev": { "barryvdh/laravel-debugbar": "^3.6", diff --git a/composer.lock b/composer.lock index b8e0b33dda..e693b4f9e1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4361272676d998d08fb1926198065b39", + "content-hash": "f6635e28eff8ba2e1ba889d1ef9dd2d6", "packages": [ { "name": "adrienrn/php-mimetyper", @@ -4667,6 +4667,65 @@ ], "time": "2022-05-21T17:30:32+00:00" }, + { + "name": "invoiceninja/admin-api", + "version": "dev-main", + "dist": { + "type": "path", + "url": "../admin-api", + "reference": "1ba06bff5aa7fd37ad607431fa71d4a1652f97d8" + }, + "require": { + "afosto/yaac": "^1.5", + "asm/php-ansible": "dev-main", + "ext-curl": "*", + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-simplexml": "*", + "illuminate/database": "^11", + "illuminate/support": "^11", + "imdhemy/laravel-purchases": "^1.7", + "php": "^8.2|^8.3|^8.4" + }, + "require-dev": { + "larastan/larastan": "^3.0", + "orchestra/testbench": "^9.0", + "phpstan/phpstan": "^2.0", + "phpunit/phpunit": "^11.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "InvoiceNinja\\AdminApi\\Providers\\AdminApiServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "InvoiceNinja\\AdminApi\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "InvoiceNinja\\AdminApi\\Tests\\": "tests/" + } + }, + "license": [ + "Elastic" + ], + "authors": [ + { + "name": "David Bomba", + "email": "turbo124@gmail.com" + } + ], + "description": "API endpoints for the admin interface", + "transport-options": { + "relative": true + } + }, { "name": "invoiceninja/einvoice", "version": "dev-main", @@ -19137,16 +19196,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.5.21", + "version": "11.5.22", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "d565e2cdc21a7db9dc6c399c1fc2083b8010f289" + "reference": "4cd72faaa8f811e4cc63040cba167757660a5538" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d565e2cdc21a7db9dc6c399c1fc2083b8010f289", - "reference": "d565e2cdc21a7db9dc6c399c1fc2083b8010f289", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4cd72faaa8f811e4cc63040cba167757660a5538", + "reference": "4cd72faaa8f811e4cc63040cba167757660a5538", "shasum": "" }, "require": { @@ -19218,7 +19277,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.21" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.22" }, "funding": [ { @@ -19242,7 +19301,7 @@ "type": "tidelift" } ], - "time": "2025-05-21T12:35:00+00:00" + "time": "2025-06-06T02:48:05+00:00" }, { "name": "react/cache", @@ -21398,7 +21457,8 @@ "beganovich/snappdf": 20, "horstoeko/orderx": 20, "invoiceninja/einvoice": 20, - "socialiteproviders/apple": 20 + "socialiteproviders/apple": 20, + "invoiceninja/admin-api": 20 }, "prefer-stable": true, "prefer-lowest": false,