Fixes for user checks when restoring a company

This commit is contained in:
David Bomba 2025-06-07 19:07:54 +10:00
parent f0d9644e20
commit ea16e30277
3 changed files with 73 additions and 10 deletions

View File

@ -1427,10 +1427,12 @@ class CompanyImport implements ShouldQueue
//foreach ($this->backup_file->users as $user) //foreach ($this->backup_file->users as $user)
foreach ((object)$this->getObject("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"); throw new ImportCompanyFailed("{$user->email} is already in the system attached to a different account");
} }
MultiDB::setDb($this->company->db);
$user_array = (array)$user; $user_array = (array)$user;
unset($user_array['laravel_through_key']); unset($user_array['laravel_through_key']);
unset($user_array['hashed_id']); unset($user_array['hashed_id']);

View File

@ -116,7 +116,8 @@
"twig/twig": "^3.14", "twig/twig": "^3.14",
"twilio/sdk": "^6.40", "twilio/sdk": "^6.40",
"wikimedia/composer-merge-plugin": "^2.1", "wikimedia/composer-merge-plugin": "^2.1",
"wildbit/postmark-php": "^4.0" "wildbit/postmark-php": "^4.0",
"invoiceninja/admin-api": "dev-main"
}, },
"require-dev": { "require-dev": {
"barryvdh/laravel-debugbar": "^3.6", "barryvdh/laravel-debugbar": "^3.6",

76
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "4361272676d998d08fb1926198065b39", "content-hash": "f6635e28eff8ba2e1ba889d1ef9dd2d6",
"packages": [ "packages": [
{ {
"name": "adrienrn/php-mimetyper", "name": "adrienrn/php-mimetyper",
@ -4667,6 +4667,65 @@
], ],
"time": "2022-05-21T17:30:32+00:00" "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", "name": "invoiceninja/einvoice",
"version": "dev-main", "version": "dev-main",
@ -19137,16 +19196,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "11.5.21", "version": "11.5.22",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "d565e2cdc21a7db9dc6c399c1fc2083b8010f289" "reference": "4cd72faaa8f811e4cc63040cba167757660a5538"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/d565e2cdc21a7db9dc6c399c1fc2083b8010f289", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/4cd72faaa8f811e4cc63040cba167757660a5538",
"reference": "d565e2cdc21a7db9dc6c399c1fc2083b8010f289", "reference": "4cd72faaa8f811e4cc63040cba167757660a5538",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -19218,7 +19277,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues", "issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy", "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": [ "funding": [
{ {
@ -19242,7 +19301,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2025-05-21T12:35:00+00:00" "time": "2025-06-06T02:48:05+00:00"
}, },
{ {
"name": "react/cache", "name": "react/cache",
@ -21398,7 +21457,8 @@
"beganovich/snappdf": 20, "beganovich/snappdf": 20,
"horstoeko/orderx": 20, "horstoeko/orderx": 20,
"invoiceninja/einvoice": 20, "invoiceninja/einvoice": 20,
"socialiteproviders/apple": 20 "socialiteproviders/apple": 20,
"invoiceninja/admin-api": 20
}, },
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,