3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-02-04 19:35:39 +00:00

Attempt to use a gate here?

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe
2025-07-17 20:09:27 +01:00
parent a98d3fb4dc
commit 0fe49e04bf

View File

@ -7,6 +7,7 @@ use App\Models\Department;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\WelcomeNotification;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Password;
@ -81,6 +82,7 @@ class UserImporter extends ItemImporter
$this->item['username'] = $user_formatted_array['username'];
}
// Check if a numeric ID was passed. If it does, use that above all else.
if ((array_key_exists('id', $this->item) && ($this->item['id'] != "") && (is_numeric($this->item['id'])))) {
$user = User::find($this->item['id']);
@ -90,12 +92,22 @@ class UserImporter extends ItemImporter
if ($user) {
// If the user does not want to update existing values, only add new ones, bail out
if (! $this->updating) {
Log::debug('A matching User '.$this->item['name'].' already exists. ');
return;
}
$this->log('Updating User');
// Todo - check that this works
// if (!Gate::allows('editCurrentUser', $user)) {
// $user->except(['password', 'username', 'email', 'activated']);
// }
$user->update($this->sanitizeItemForUpdating($user));
// Why do we have to do this twice? Update should
$user->save();
// Update the location of any assets checked out to this user
@ -116,8 +128,12 @@ class UserImporter extends ItemImporter
$this->log('No matching user, creating one');
$user = new User();
$user->created_by = auth()->id();
$user->fill($this->sanitizeItemForStoring($user));
// TODO - check for gate here I guess
if ($user->save()) {
$this->log('User '.$this->item['name'].' was created');
@ -143,6 +159,7 @@ class UserImporter extends ItemImporter
$this->logError($user, 'User');
}
/**
* Fetch an existing department, or create new if it doesn't exist
*