mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 22:07:29 -08:00
Userimport fixes/improvements (#5884)
* Send notification when user is created. * Flesh out default user mappings * Add user importing test.
This commit is contained in:
parent
19396b2107
commit
92671823d8
|
@ -60,7 +60,12 @@ abstract class Importer
|
||||||
'warranty_months' => 'warranty',
|
'warranty_months' => 'warranty',
|
||||||
'full_name' => 'full name',
|
'full_name' => 'full name',
|
||||||
'email' => 'email',
|
'email' => 'email',
|
||||||
'username' => 'username'
|
'username' => 'username',
|
||||||
|
'jobtitle' => 'job title',
|
||||||
|
'employee_num' => 'employee number',
|
||||||
|
'phone_number' => 'phone number',
|
||||||
|
'first_name' => 'first name',
|
||||||
|
'last_name' => 'last name',
|
||||||
];
|
];
|
||||||
/**
|
/**
|
||||||
* Map of item fields->csv names
|
* Map of item fields->csv names
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Importer;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Notifications\WelcomeNotification;
|
||||||
|
|
||||||
class UserImporter extends ItemImporter
|
class UserImporter extends ItemImporter
|
||||||
{
|
{
|
||||||
|
@ -26,6 +27,7 @@ class UserImporter extends ItemImporter
|
||||||
*
|
*
|
||||||
* @author Daniel Melzter
|
* @author Daniel Melzter
|
||||||
* @since 4.0
|
* @since 4.0
|
||||||
|
* @param array $row
|
||||||
*/
|
*/
|
||||||
public function createUserIfNotExists(array $row)
|
public function createUserIfNotExists(array $row)
|
||||||
{
|
{
|
||||||
|
@ -55,14 +57,24 @@ class UserImporter extends ItemImporter
|
||||||
$this->log("No matching user, creating one");
|
$this->log("No matching user, creating one");
|
||||||
$user = new User();
|
$user = new User();
|
||||||
$user->fill($this->sanitizeItemForStoring($user));
|
$user->fill($this->sanitizeItemForStoring($user));
|
||||||
|
|
||||||
if ($user->save()) {
|
if ($user->save()) {
|
||||||
// $user->logCreate('Imported using CSV Importer');
|
// $user->logCreate('Imported using CSV Importer');
|
||||||
$this->log("User " . $this->item["name"] . ' was created');
|
$this->log("User " . $this->item["name"] . ' was created');
|
||||||
|
if($user->email) {
|
||||||
|
$data = [
|
||||||
|
'email' => $user->email,
|
||||||
|
'username' => $user->username,
|
||||||
|
'first_name' => $user->first_name,
|
||||||
|
'last_name' => $user->last_name,
|
||||||
|
'password' => $this->tempPassword,
|
||||||
|
];
|
||||||
|
$user->notify(new WelcomeNotification($data));
|
||||||
|
}
|
||||||
$user = null;
|
$user = null;
|
||||||
$this->item = null;
|
$this->item = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logError($user, 'User');
|
$this->logError($user, 'User');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ use App\Importer\AccessoryImporter;
|
||||||
use App\Importer\AssetImporter;
|
use App\Importer\AssetImporter;
|
||||||
use App\Importer\ConsumableImporter;
|
use App\Importer\ConsumableImporter;
|
||||||
use App\Importer\LicenseImporter;
|
use App\Importer\LicenseImporter;
|
||||||
|
use App\Importer\UserImporter;
|
||||||
use App\Models\Accessory;
|
use App\Models\Accessory;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\AssetModel;
|
use App\Models\AssetModel;
|
||||||
|
@ -14,6 +15,7 @@ use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||||
use Illuminate\Support\Facades\Hash;
|
use Illuminate\Support\Facades\Hash;
|
||||||
|
use Illuminate\Support\Facades\Notification;
|
||||||
|
|
||||||
class ImporterTest extends BaseTest
|
class ImporterTest extends BaseTest
|
||||||
{
|
{
|
||||||
|
@ -681,6 +683,36 @@ EOT;
|
||||||
$this->tester->seeNumRecords(80, 'license_seats');
|
$this->tester->seeNumRecords(80, 'license_seats');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function testDefaultUserImport()
|
||||||
|
{
|
||||||
|
Notification::fake();
|
||||||
|
$this->signIn();
|
||||||
|
$csv = <<<'EOT'
|
||||||
|
First Name,Last Name,email,Username,Location,Phone Number,Job Title,Employee Number,Company
|
||||||
|
Blanche,O'Collopy,bocollopy0@livejournal.com,bocollopy0,Hinapalanan,63-(199)661-2186,Clinical Specialist,7080919053,Morar-Ward
|
||||||
|
Jessie,Primo,,jprimo1,Korenovsk,7-(885)578-0266,Paralegal,6284292031,Jast-Stiedemann
|
||||||
|
|
||||||
|
EOT;
|
||||||
|
$this->import(new UserImporter($csv));
|
||||||
|
|
||||||
|
$this->tester->seeRecord('users', [
|
||||||
|
'first_name' => 'Blanche',
|
||||||
|
'last_name' => "O'Collopy",
|
||||||
|
'email' => 'bocollopy0@livejournal.com',
|
||||||
|
'username' => 'bocollopy0',
|
||||||
|
'phone' => '63-(199)661-2186',
|
||||||
|
'jobtitle' => 'Clinical Specialist',
|
||||||
|
'employee_num' => '7080919053'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->tester->seeRecord('companies', [
|
||||||
|
'name' => 'Morar-Ward'
|
||||||
|
]);
|
||||||
|
|
||||||
|
Notification::assertSentTo(User::find(2), \App\Notifications\WelcomeNotification::class);
|
||||||
|
Notification::assertNotSentTo(User::find(3), \App\Notifications\WelcomeNotification::class);
|
||||||
|
}
|
||||||
private function import($importer, $mappings = null)
|
private function import($importer, $mappings = null)
|
||||||
{
|
{
|
||||||
if ($mappings) {
|
if ($mappings) {
|
||||||
|
|
Loading…
Reference in a new issue