From e471aa8639a15402d5c608baac0f05b7ce4d259d Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 29 Jun 2022 11:15:15 -0700 Subject: [PATCH 1/4] adds button to email user list of assets from profile --- app/Http/Controllers/Users/UsersController.php | 14 ++++++++++++++ resources/lang/en/admin/users/general.php | 2 ++ resources/views/users/print.blade.php | 1 + resources/views/users/view.blade.php | 9 +++++++++ routes/web/users.php | 8 ++++++++ 5 files changed, 34 insertions(+) diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index c67cbcb286..d7372627b6 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -23,6 +23,7 @@ use Redirect; use Str; use Symfony\Component\HttpFoundation\StreamedResponse; use View; +use App\Notifications\CurrentInventory; /** * This controller handles all actions related to Users for @@ -614,6 +615,19 @@ class UsersController extends Controller ->with('show_user', $show_user) ->with('settings', Setting::getSettings()); } + public function emailAssetList($id) + { + $this->authorize('view', User::class); + + if( User::where('id', $id)->first()->exists()) + { + $user= User::where('id', $id)->first(); + $user->notify((new CurrentInventory($user))); + return redirect()->back()->with('success', 'admin/users/general.user_notified'); + } + + return redirect()->back()->with('error', 'admin/accessories/message.user_does_not_exist'); + } /** * Send individual password reset email diff --git a/resources/lang/en/admin/users/general.php b/resources/lang/en/admin/users/general.php index 66c9699064..c77ff8f8c7 100644 --- a/resources/lang/en/admin/users/general.php +++ b/resources/lang/en/admin/users/general.php @@ -17,6 +17,8 @@ return [ 'last_login' => 'Last Login', 'ldap_config_text' => 'LDAP configuration settings can be found Admin > Settings. The (optional) selected location will be set for all imported users.', 'print_assigned' => 'Print All Assigned', + 'email_assigned' => 'Email List of All Assigned', + 'user_notified' => 'User has been emailed a list of their currently assigned items.', 'software_user' => 'Software Checked out to :name', 'send_email_help' => 'You must provide an email address for this user to send them credentials. Emailing credentials can only be done on user creation. Passwords are stored in a one-way hash and cannot be retrieved once saved.', 'view_user' => 'View User :name', diff --git a/resources/views/users/print.blade.php b/resources/views/users/print.blade.php index 1da8353f28..76b4767682 100644 --- a/resources/views/users/print.blade.php +++ b/resources/views/users/print.blade.php @@ -67,6 +67,7 @@ {{ trans('admin/hardware/table.asset_tag') }} {{ trans('general.name') }} {{ trans('general.category') }} + {{ trans('admin/hardware/form.serial') }} {{ trans('admin/hardware/form.model') }} {{ trans('admin/hardware/form.serial') }} {{ trans('admin/hardware/table.checkout_date') }} diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php index a6161f5197..296453bf83 100755 --- a/resources/views/users/view.blade.php +++ b/resources/views/users/view.blade.php @@ -188,6 +188,15 @@ @endcan + @can('view', $user) +
+
+ {{ csrf_field() }} + +
+
+ @endcan + @can('update', $user) @if (($user->activated == '1') && ($user->email != '') && ($user->ldap_import == '0'))
diff --git a/routes/web/users.php b/routes/web/users.php index bc6cd32c67..b34fae0c17 100644 --- a/routes/web/users.php +++ b/routes/web/users.php @@ -144,6 +144,14 @@ Route::group(['prefix' => 'users', 'middleware' => ['auth']], function () { ] )->name('users.print'); + Route::post( + '{userId}/email', + [ + Users\UsersController::class, + 'emailAssetList' + ] + )->name('users.email'); + Route::post( 'bulkedit', [ From fc636ea88877e293d5866c2456d521e43f0c0160 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 29 Jun 2022 12:01:56 -0700 Subject: [PATCH 2/4] removed redundant header --- resources/views/users/print.blade.php | 1 - 1 file changed, 1 deletion(-) diff --git a/resources/views/users/print.blade.php b/resources/views/users/print.blade.php index 76b4767682..1da8353f28 100644 --- a/resources/views/users/print.blade.php +++ b/resources/views/users/print.blade.php @@ -67,7 +67,6 @@ {{ trans('admin/hardware/table.asset_tag') }} {{ trans('general.name') }} {{ trans('general.category') }} - {{ trans('admin/hardware/form.serial') }} {{ trans('admin/hardware/form.model') }} {{ trans('admin/hardware/form.serial') }} {{ trans('admin/hardware/table.checkout_date') }} From cd9d2d0cecbd81bd3e2ad1f2ff27c1d6514d036d Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 29 Jun 2022 13:01:29 -0700 Subject: [PATCH 3/4] adds docblock --- app/Http/Controllers/Users/UsersController.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index d7372627b6..1fcfad9cf3 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -615,6 +615,15 @@ class UsersController extends Controller ->with('show_user', $show_user) ->with('settings', Setting::getSettings()); } + + /** + * Emails user a list of assigned assets + * + * @author [G. Martinez] [] + * @since [v6.0.5] + * @param \App\Http\Controllers\Users\UsersController $id + * @return \Illuminate\Http\RedirectResponse + */ public function emailAssetList($id) { $this->authorize('view', User::class); From 2451bb9a2bacfa50d05aaa9be6969dfbb8ee9a02 Mon Sep 17 00:00:00 2001 From: Brady Wetherington Date: Wed, 29 Jun 2022 14:48:59 -0700 Subject: [PATCH 4/4] Make SCIM be more tolerant of missing fields --- app/Models/SnipeSCIMConfig.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app/Models/SnipeSCIMConfig.php b/app/Models/SnipeSCIMConfig.php index 4c990fd045..4c13dc4ed7 100644 --- a/app/Models/SnipeSCIMConfig.php +++ b/app/Models/SnipeSCIMConfig.php @@ -42,7 +42,7 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig ); $config['validations'][$core.'emails'] = 'nullable|array'; // emails are not required in Snipe-IT... - $config['validations'][$core.'emails.*.value'] = 'required|email'; // ...but if you give us one, it better be an email address + $config['validations'][$core.'emails.*.value'] = 'email'; // ...(had to remove the recommended 'required' here) $mappings['emails'] = [[ "value" => AttributeMapping::eloquent("email"), @@ -58,7 +58,7 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig //phone $config['validations'][$core.'phoneNumbers'] = 'nullable|array'; - $config['validations'][$core.'phoneNumbers.*.value'] = 'required'; + $config['validations'][$core.'phoneNumbers.*.value'] = 'string'; // another one where want to say 'we don't _need_ a phone number, but if you have one it better have a value. $mappings['phoneNumbers'] = [[ "value" => AttributeMapping::eloquent("phone"), @@ -69,10 +69,10 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig //address $config['validations'][$core.'addresses'] = 'nullable|array'; - $config['validations'][$core.'addresses.*.streetAddress'] = 'required'; + $config['validations'][$core.'addresses.*.streetAddress'] = 'string'; $config['validations'][$core.'addresses.*.locality'] = 'string'; - $config['validations'][$core.'addresses.*.region'] = 'string'; - $config['validations'][$core.'addresses.*.postalCode'] = 'string'; + $config['validations'][$core.'addresses.*.region'] = 'nullable|string'; + $config['validations'][$core.'addresses.*.postalCode'] = 'nullable|string'; $config['validations'][$core.'addresses.*.country'] = 'string'; $mappings['addresses'] = [[ @@ -118,7 +118,6 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig 'employeeNumber' => AttributeMapping::eloquent('employee_num'), 'department' =>(new AttributeMapping())->setAdd( // FIXME parent? function ($value, &$object) { - \Log::error("Department-Add: $value"); //FIXME $department = Department::where("name", $value)->first(); if ($department) { $object->department_id = $department->id; @@ -126,7 +125,6 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig } )->setReplace( function ($value, &$object) { - \Log::error("Department-Replace: $value"); //FIXME $department = Department::where("name", $value)->first(); if ($department) { $object->department_id = $department->id; @@ -134,7 +132,6 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig } )->setRead( function (&$object) { - \Log::error("Weird department reader firing..."); //FIXME return $object->department ? $object->department->name : null; } ), @@ -145,7 +142,6 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig // NOTE: you could probably do a 'plain' Eloquent mapping here, but we don't for future-proofing 'value' => (new AttributeMapping())->setAdd( function ($value, &$object) { - \Log::error("Manager-Add: $value"); //FIXME $manager = User::find($value); if ($manager) { $object->manager_id = $manager->id; @@ -153,7 +149,6 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig } )->setReplace( function ($value, &$object) { - \Log::error("Manager-Replace: $value"); //FIXME $manager = User::find($value); if ($manager) { $object->manager_id = $manager->id; @@ -161,7 +156,6 @@ class SnipeSCIMConfig extends \ArieTimmerman\Laravel\SCIMServer\SCIMConfig } )->setRead( function (&$object) { - \Log::error("Weird manager reader firing..."); //FIXME return $object->manager_id; } ),