From 891b5b288217755547ddfec5de06e130cd184b5a Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 4 Oct 2022 15:45:25 -0700 Subject: [PATCH] Added routes, language Signed-off-by: snipe --- app/Http/Controllers/ProfileController.php | 48 +++++++++++++++++++ .../Controllers/Users/UsersController.php | 2 +- resources/lang/en/general.php | 1 + resources/views/account/view-assets.blade.php | 40 +++++++++------- routes/web.php | 17 +++++++ 5 files changed, 89 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 38d4226dfa..8edcc70c6a 100755 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -3,7 +3,10 @@ namespace App\Http\Controllers; use App\Http\Requests\ImageUploadRequest; +use App\Models\Asset; use App\Models\Setting; +use App\Models\User; +use App\Notifications\CurrentInventory; use Illuminate\Support\Facades\Auth; use Gate; use Illuminate\Http\Request; @@ -216,4 +219,49 @@ class ProfileController extends Controller $request->session()->put('menu_state', 'closed'); } } + + + /** + * Print inventory + * + * @author A. Gianotto + * @since [v6.0.12] + * @return \Illuminate\Http\RedirectResponse + */ + public function printInventory() + { + $show_user = User::where('id', Auth::user()->id)->withTrashed()->first(); + $assets = Asset::where('assigned_to', Auth::user()->id)->where('assigned_type', User::class)->with('model', 'model.category')->get(); + $accessories = $show_user->accessories()->get(); + $consumables = $show_user->consumables()->get(); + + return view('users/print')->with('assets', $assets) + ->with('licenses', $show_user->licenses()->get()) + ->with('accessories', $accessories) + ->with('consumables', $consumables) + ->with('show_user', $show_user) + ->with('settings', Setting::getSettings()); + } + + /** + * Emails user a list of assigned assets + * + * @author A. Gianotto + * @since [v6.0.12] + * @return \Illuminate\Http\RedirectResponse + */ + public function emailAssetList() + { + + if (!$user = User::find(Auth::user()->id)) { + return redirect()->back() + ->with('error', trans('admin/users/message.user_not_found', ['id' => $id])); + } + if (empty($user->email)) { + return redirect()->back()->with('error', trans('admin/users/message.user_has_no_email')); + } + + $user->notify((new CurrentInventory($user))); + return redirect()->back()->with('success', trans('admin/users/general.user_notified')); + } } diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index 7cbbbdb10b..8582ace158 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -594,7 +594,7 @@ class UsersController extends Controller } /** - * LDAP form processing. + * Print inventory * * @author Aladin Alaily * @since [v1.8] diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index ba2cb77a6d..7943520808 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -376,6 +376,7 @@ return [ 'assets_by_status' => 'Assets by Status', 'assets_by_status_type' => 'Assets by Status Type', 'pie_chart_type' => 'Dashboard Pie Chart Type', + 'hello_name' => 'Hello, :name!', ]; \ No newline at end of file diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php index d3e7047e9d..b780e63c31 100755 --- a/resources/views/account/view-assets.blade.php +++ b/resources/views/account/view-assets.blade.php @@ -2,7 +2,7 @@ {{-- Page title --}} @section('title') -{{ trans('general.viewassetsfor', array('name' => $user->present()->fullName())) }} +{{ trans('general.hello_name', array('name' => $user->present()->fullName())) }} @parent @stop @@ -83,36 +83,42 @@
- @if (($user->isSuperUser()) || ($user->hasAccess('admin'))) - -
{{ ($user->isSuperUser()) ? 'superadmin' : 'admin'}}
- @endif - -
{{ $user->present()->fullName() }}
- - - @can('update', $user) + + + + @can('self.api') + @endcan - @can('view', $user) - @endcan - @can('view', $user) +
@if(!empty($user->email)) -
+ {{ csrf_field() }}
@@ -120,8 +126,6 @@ @endif
- @endcan -

diff --git a/routes/web.php b/routes/web.php index 249e02a367..4c52918f8e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -279,6 +279,23 @@ Route::group(['prefix' => 'account', 'middleware' => ['auth']], function () { ->name('account.accept.item'); Route::post('accept/{id}', [Account\AcceptanceController::class, 'store']); + + Route::get( + 'print', + [ + ProfileController::class, + 'printInventory' + ] + )->name('profile.print'); + + Route::post( + 'email', + [ + ProfileController::class, + 'emailAssetList' + ] + )->name('profile.email_assets'); + }); Route::group(['middleware' => ['auth']], function () {