mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-27 06:29:47 -08:00
a1eafc108d
Signed-off-by: snipe <snipe@snipe.net>
52 lines
1.8 KiB
PHP
Executable file
52 lines
1.8 KiB
PHP
Executable file
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use \Illuminate\Contracts\View\View;
|
|
|
|
|
|
/**
|
|
* This controller handles all actions related to the Admin Dashboard
|
|
* for the Snipe-IT Asset Management application.
|
|
*
|
|
* @author A. Gianotto <snipe@snipe.net>
|
|
* @version v1.0
|
|
*/
|
|
class DashboardController extends Controller
|
|
{
|
|
/**
|
|
* Check authorization and display admin dashboard, otherwise display
|
|
* the user's checked-out assets.
|
|
*
|
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
|
* @since [v1.0]
|
|
*/
|
|
public function index() : View | RedirectResponse
|
|
{
|
|
// Show the page
|
|
if (auth()->user()->hasAccess('admin')) {
|
|
$asset_stats = null;
|
|
|
|
$counts['asset'] = \App\Models\Asset::count();
|
|
$counts['accessory'] = \App\Models\Accessory::count();
|
|
$counts['license'] = \App\Models\License::assetcount();
|
|
$counts['consumable'] = \App\Models\Consumable::count();
|
|
$counts['component'] = \App\Models\Component::count();
|
|
$counts['user'] = \App\Models\Company::scopeCompanyables(auth()->user())->count();
|
|
$counts['grand_total'] = $counts['asset'] + $counts['accessory'] + $counts['license'] + $counts['consumable'];
|
|
|
|
if ((! file_exists(storage_path().'/oauth-private.key')) || (! file_exists(storage_path().'/oauth-public.key'))) {
|
|
Artisan::call('migrate', ['--force' => true]);
|
|
\Artisan::call('passport:install');
|
|
}
|
|
|
|
return view('dashboard')->with('asset_stats', $asset_stats)->with('counts', $counts);
|
|
} else {
|
|
// Redirect to the profile page
|
|
return redirect()->intended('account/view-assets');
|
|
}
|
|
}
|
|
}
|