diff --git a/.env.testing b/.env.testing index 1c2b1b963474..7a44e2154d48 100644 --- a/.env.testing +++ b/.env.testing @@ -3,7 +3,7 @@ # -------------------------------------------- APP_ENV=testing APP_DEBUG=true -APP_KEY=ChangeMe +APP_KEY=base64:glJpcM7BYwWiBggp3SQ/+NlRkqsBQMaGEOjemXqJzOU= APP_URL=http://localhost:8000 APP_TIMEZONE='US/Pacific' APP_LOCALE=en diff --git a/.travis.yml b/.travis.yml index d783b2712ca1..e68578b2bc9f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,18 +14,18 @@ php: # execute any number of scripts before the test run, custom env's are available as variables before_script: - phantomjs --webdriver=4444 & - - sleep 10 + - sleep 4 - mysql -e "create database IF NOT EXISTS snipeit_unit;" -utravis - composer self-update - composer install -n --prefer-source - - cp .env.testing-ci .env - chmod -R 777 storage - - php artisan migrate --database=mysql --force + - php artisan migrate --env=testing-ci --database=mysql --force - ./vendor/bin/codecept build - - php artisan key:generate - - php artisan db:seed --database=mysql --force - - php artisan snipeit:create-admin --first_name=Alison --last_name=Foobar --email=me@example.com --username=snipe --password=password - - php artisan serve --port=8000 --host=localhost & + - php artisan key:generate --env=testing-ci + - php artisan db:seed --env=testing-ci --database=mysql --force + - php artisan --env=testing-ci snipeit:create-admin --first_name=Alison --last_name=Foobar --email=me@example.com --username=snipe --password=password + - php artisan --env=testing-ci snipeit:travisci-install + - php artisan serve --env=testing-ci --port=8000 --host=localhost & - sleep 5 - pip install --user codecov - sleep 5 @@ -34,16 +34,17 @@ before_script: # omitting "script:" will default to phpunit # use the $DB env variable to determine the phpunit.xml to use -# script: ./vendor/bin/codecept run --env testing-ci - broken :( -script: ./vendor/bin/codecept run unit --env testing-ci +# script: ./vendor/bin/codecept run --env testing-ci +script: ./vendor/bin/codecept run unit --env testing-ci && ./vendor/bin/codecept run functional --env=functional-travis #script: ./vendor/bin/codecept run after_success: - codecov after_failure: - - cat tests/_output/AccessoriesCept.fail.html + - cat tests/_output/*.fail.html - curl http://localhost:8000/login + - cat storage/logs/laravel.log # configure notifications (email, IRC, campfire etc) notifications: diff --git a/app/Console/Commands/SendExpirationAlerts.php b/app/Console/Commands/SendExpirationAlerts.php index d25a3cb7999f..34a80ee27c49 100644 --- a/app/Console/Commands/SendExpirationAlerts.php +++ b/app/Console/Commands/SendExpirationAlerts.php @@ -89,7 +89,7 @@ public function fire() } else { $license_data['email_content'] .= ''; } - $license_data['email_content'] .= ''; + $license_data['email_content'] .= ''; $license_data['email_content'] .= $license->name.''; $license_data['email_content'] .= ''.$license->expiration_date.''; $license_data['email_content'] .= ''.$difference.' days'; diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 3e04cb550bd7..12a05704722f 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -40,4 +40,9 @@ protected function schedule(Schedule $schedule) $schedule->command('snipeit:backup')->weekly(); $schedule->command('backup:clean')->daily(); } + + protected function commands() + { + require base_path('routes/console.php'); + } } diff --git a/app/Http/Controllers/AccessoriesController.php b/app/Http/Controllers/AccessoriesController.php index b24e4b4dd171..e99414c3faee 100755 --- a/app/Http/Controllers/AccessoriesController.php +++ b/app/Http/Controllers/AccessoriesController.php @@ -40,6 +40,7 @@ class AccessoriesController extends Controller */ public function index(Request $request) { + $this->authorize('index', Accessory::class); return View::make('accessories/index'); } @@ -52,6 +53,7 @@ public function index(Request $request) */ public function create(Request $request) { + $this->authorize('create', Accessory::class); // Show the page return View::make('accessories/edit') ->with('item', new Accessory) @@ -70,7 +72,7 @@ public function create(Request $request) */ public function store(Request $request) { - + $this->authorize(Accessory::class); // create a new model instance $accessory = new Accessory(); @@ -123,10 +125,10 @@ public function edit(Request $request, $accessoryId = null) if (is_null($item = Accessory::find($accessoryId))) { // Redirect to the blogs management page return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($item)) { - return redirect()->route('accessories.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize($item); + return View::make('accessories/edit', compact('item')) ->with('category_list', Helper::categoryList('accessory')) ->with('company_list', Helper::companyList()) @@ -148,10 +150,10 @@ public function update(Request $request, $accessoryId = null) if (is_null($accessory = Accessory::find($accessoryId))) { // Redirect to the accessory index page return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($accessory)) { - return redirect()->route('accessories.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize($accessory); + // Update the accessory data $accessory->name = e(Input::get('name')); @@ -205,10 +207,10 @@ public function destroy(Request $request, $accessoryId) if (is_null($accessory = Accessory::find($accessoryId))) { // Redirect to the blogs management page return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.not_found')); - } elseif (!Company::isCurrentUserHasAccess($accessory)) { - return redirect()->route('accessories.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize($accessory); + if ($accessory->hasUsers() > 0) { return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.assoc_users', array('count'=> $accessory->hasUsers()))); @@ -236,14 +238,9 @@ public function destroy(Request $request, $accessoryId) public function show(Request $request, $accessoryID = null) { $accessory = Accessory::find($accessoryID); - + $this->authorize('view', $accessory); if (isset($accessory->id)) { - - if (!Company::isCurrentUserHasAccess($accessory)) { - return redirect()->route('accessories.index')->with('error', trans('general.insufficient_permissions')); - } else { - return View::make('accessories/view', compact('accessory')); - } + return View::make('accessories/view', compact('accessory')); } else { // Prepare the error message $error = trans('admin/accessories/message.does_not_exist', compact('id')); @@ -267,11 +264,11 @@ public function getCheckout(Request $request, $accessoryId) // Check if the accessory exists if (is_null($accessory = Accessory::find($accessoryId))) { // Redirect to the accessory management page with error - return redirect()->to('accessories.index')->with('error', trans('admin/accessories/message.not_found')); - } elseif (!Company::isCurrentUserHasAccess($accessory)) { - return redirect()->route('accessories.index')->with('error', trans('general.insufficient_permissions')); + return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.not_found')); } + $this->authorize('checkout', $accessory); + // Get the dropdown of users and then pass it to the checkout view $users_list = Helper::usersList(); @@ -295,10 +292,10 @@ public function postCheckout(Request $request, $accessoryId) if (is_null($accessory = Accessory::find($accessoryId))) { // Redirect to the accessory management page with error return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.user_not_found')); - } elseif (!Company::isCurrentUserHasAccess($accessory)) { - return redirect()->route('accessories.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('checkout', $accessory); + if (!$user = User::find(Input::get('assigned_to'))) { return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.not_found')); } @@ -336,7 +333,7 @@ public function postCheckout(Request $request, $accessoryId) 'fields' => [ [ 'title' => 'Checked Out:', - 'value' => 'Accessory <'.url('/').'/admin/accessories/'.$accessory->id.'/view'.'|'.$accessory->name.'> checked out to <'.url('/').'/admin/users/'.$user->id.'/view|'.$user->fullName().'> by <'.url('/').'/admin/users/'.$admin_user->id.'/view'.'|'.$admin_user->fullName().'>.' + 'value' => 'Accessory <'.route('accessories.show', $accessory->id).'|'.$accessory->name.'> checked out to <'.route('users.show', $user->id).'|'.$user->fullName().'> by <'.route('users.show', $admin_user->id).'|'.$admin_user->fullName().'>.' ], [ 'title' => 'Note:', @@ -397,12 +394,8 @@ public function getCheckin(Request $request, $accessoryUserId = null, $backto = } $accessory = Accessory::find($accessory_user->accessory_id); - - if (!Company::isCurrentUserHasAccess($accessory)) { - return redirect()->route('accessories.index')->with('error', trans('general.insufficient_permissions')); - } else { - return View::make('accessories/checkin', compact('accessory'))->with('backto', $backto); - } + $this->authorize('checkin', $accessory); + return View::make('accessories/checkin', compact('accessory'))->with('backto', $backto); } @@ -425,9 +418,7 @@ public function postCheckin(Request $request, $accessoryUserId = null, $backto = $accessory = Accessory::find($accessory_user->accessory_id); - if (!Company::isCurrentUserHasAccess($accessory)) { - return redirect()->route('accessories.index')->with('error', trans('general.insufficient_permissions')); - } + $this->authorize('checkin', $accessory); $return_to = e($accessory_user->assigned_to); $logaction = $accessory->logCheckin(User::find($return_to), e(Input::get('note'))); @@ -456,7 +447,7 @@ public function postCheckin(Request $request, $accessoryUserId = null, $backto = 'fields' => [ [ 'title' => 'Checked In:', - 'value' => class_basename(strtoupper($logaction->item_type)).' <'.url('/').'/admin/accessories/'.e($accessory->id).'/view'.'|'.e($accessory->name).'> checked in by <'.url('/').'/admin/users/'.e($admin_user->id).'/view'.'|'.e($admin_user->fullName()).'>.' + 'value' => class_basename(strtoupper($logaction->item_type)).' <'.route('accessories.show', $accessory->id).'|'.e($accessory->name).'> checked in by <'.route('users.show', $admin_user->id).'|'.e($admin_user->fullName()).'>.' ], [ 'title' => 'Note:', @@ -493,9 +484,9 @@ public function postCheckin(Request $request, $accessoryUserId = null, $backto = } if ($backto=='user') { - return redirect()->to("admin/users/".$return_to.'/view')->with('success', trans('admin/accessories/message.checkin.success')); + return redirect()->route("users.show", $return_to)->with('success', trans('admin/accessories/message.checkin.success')); } else { - return redirect()->to("admin/accessories/".$accessory->id."/view")->with('success', trans('admin/accessories/message.checkin.success')); + return redirect()->route("accessories.show", $accessory->id)->with('success', trans('admin/accessories/message.checkin.success')); } } @@ -532,6 +523,7 @@ public function postCheckin(Request $request, $accessoryUserId = null, $backto = **/ public function getDatatable(Request $request) { + $this->authorize('index', Accessory::class); $accessories = Company::scopeCompanyables( Accessory::select('accessories.*') ->whereNull('accessories.deleted_at') @@ -578,15 +570,15 @@ public function getDatatable(Request $request) foreach ($accessories as $accessory) { $actions = ''; - if (Gate::allows('accessories.checkout')) { + if (Gate::allows('checkout', $accessory)) { $actions .= 'numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . ''; } - if (Gate::allows('accessories.edit')) { + if (Gate::allows('update', $accessory)) { $actions .= ''; } - if (Gate::allows('accessories.delete')) { + if (Gate::allows('delete', $accessory)) { $actions .= ''; } @@ -594,7 +586,7 @@ public function getDatatable(Request $request) $company = $accessory->company; $rows[] = array( - 'name' => ''. $accessory->name.'', + 'name' => ''. $accessory->name.'', 'category' => ($accessory->category) ? (string)link_to('admin/settings/categories/'.$accessory->category->id.'/view', $accessory->category->name) : '', 'model_number' => e($accessory->model_number), 'qty' => e($accessory->qty), @@ -606,7 +598,7 @@ public function getDatatable(Request $request) 'numRemaining' => $accessory->numRemaining(), 'actions' => $actions, 'companyName' => is_null($company) ? '' : e($company->name), - 'manufacturer' => $accessory->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$accessory->manufacturer_id.'/view', $accessory->manufacturer->name) : '' + 'manufacturer' => $accessory->manufacturer ? (string) link_to(route('manufacturers.show', $accessory->manufacturer_id), $accessory->manufacturer->name) : '' ); } @@ -657,13 +649,13 @@ public function getDataView(Request $request, $accessoryID) foreach ($accessory_users as $user) { $actions = ''; - if (Gate::allows('accessories.checkin')) { + if (Gate::allows('checkin', $accessory)) { $actions .= 'Checkin'; } - if (Gate::allows('users.view')) { - $name = (string) link_to('/admin/users/'.$user->id.'/view', e($user->fullName())); + if (Gate::allows('view', $user)) { + $name = (string) link_to_route('users.show', e($user->fullName()), [$user->id]); } else { $name = e($user->fullName()); } diff --git a/app/Http/Controllers/ActionlogController.php b/app/Http/Controllers/ActionlogController.php index 397c670f38c3..f0d4faad2f29 100644 --- a/app/Http/Controllers/ActionlogController.php +++ b/app/Http/Controllers/ActionlogController.php @@ -9,7 +9,7 @@ class ActionlogController extends Controller { public function displaySig($filename) { - + $this->authorize('view', \App\Models\Asset::class); $file = config('app.private_uploads') . '/signatures/' . $filename; $filetype = Helper::checkUploadIsImage($file); $contents = file_get_contents($file); diff --git a/app/Http/Controllers/AssetMaintenancesController.php b/app/Http/Controllers/AssetMaintenancesController.php index 42c3d125c188..b6f2f9dbfa2d 100644 --- a/app/Http/Controllers/AssetMaintenancesController.php +++ b/app/Http/Controllers/AssetMaintenancesController.php @@ -117,7 +117,7 @@ public function getDatatable(Request $request) foreach ($maintenances as $maintenance) { $actions = ''; - if (Gate::allows('assets.edit')) { + if (Gate::allows('update', Asset::class)) { $actions .= ''; @@ -134,13 +134,13 @@ public function getDatatable(Request $request) 'asset_name' => ($maintenance->asset) ? (string)link_to_route('maintenances.show', $maintenance->asset->showAssetName(), ['maintenance' => $maintenance->asset->id]) : 'Deleted Asset' , 'title' => $maintenance->title, 'notes' => $maintenance->notes, - 'supplier' => ($maintenance->supplier) ? (string)link_to('/admin/settings/suppliers/'.$maintenance->supplier->id.'/view', $maintenance->supplier->name) : 'Deleted Supplier', + 'supplier' => ($maintenance->supplier) ? (string)link_to_route('suppliers.show', $maintenance->supplier->name, ['maintenance'=>$maintenance->supplier->id]) : 'Deleted Supplier', 'cost' => $maintenance_cost, 'asset_maintenance_type' => e($maintenance->asset_maintenance_type), 'start_date' => $maintenance->start_date, 'asset_maintenance_time' => $maintenance->asset_maintenance_time, 'completion_date' => $maintenance->completion_date, - 'user_id' => ($maintenance->admin) ? (string)link_to('/admin/users/'.$maintenance->admin->id.'/view', $maintenance->admin->fullName()) : '', + 'user_id' => ($maintenance->admin) ? (string)link_to_route('users.show', $maintenance->admin->fullName(), ['user'=>$maintenance->admin->id]) : '', 'actions' => $actions, 'companyName' => ($maintenance->asset->company) ? $maintenance->asset->company->name : '' ); @@ -152,22 +152,22 @@ public function getDatatable(Request $request) } /** - * Returns a form view to create a new asset maintenance. - * - * @see AssetMaintenancesController::postCreate() method that stores the data - * @author Vincent Sposato - * @version v1.0 - * @since [v1.8] - * @return mixed - */ - public function create($assetId = null) + * Returns a form view to create a new asset maintenance. + * + * @see AssetMaintenancesController::postCreate() method that stores the data + * @author Vincent Sposato + * @version v1.0 + * @since [v1.8] + * @return mixed + */ + public function create() { // Prepare Asset Maintenance Type List $assetMaintenanceType = [ '' => 'Select an asset maintenance type', ] + AssetMaintenance::getImprovementOptions(); // Mark the selected asset, if it came in - $selectedAsset = $assetId; + $selectedAsset = request('asset_id'); $assets = Helper::detailedAssetList(); @@ -196,7 +196,7 @@ public function store(Request $request) // get the POST data $new = $request->all(); - +// dd($new); // create a new model instance $assetMaintenance = new AssetMaintenance(); @@ -308,7 +308,7 @@ public function edit($assetMaintenanceId = null) '' => 'Select an improvement type', ] + AssetMaintenance::getImprovementOptions(); - $assets = Company::scopeCompanyables(Asset::with('model','assignedUser')->get(), 'assets.company_id')->lists('detailed_name', 'id'); + $assets = Helper::detailedAssetList(); // Get Supplier List $supplier_list = Helper::suppliersList(); diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 8cd2d8a63b5a..6cd4282f75af 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -176,7 +176,7 @@ public function edit($modelId = null) // Check if the model exists if (is_null($item = AssetModel::find($modelId))) { // Redirect to the model management page - return redirect()->to('assets/models')->with('error', trans('admin/models/message.does_not_exist')); + return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist')); } $depreciation_list = Helper::depreciationList(); @@ -205,7 +205,7 @@ public function update(Request $request, $modelId = null) // Check if the model exists if (is_null($model = AssetModel::find($modelId))) { // Redirect to the models management page - return redirect()->to('admin/models')->with('error', trans('admin/models/message.does_not_exist')); + return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist')); } @@ -276,8 +276,7 @@ public function destroy($modelId) { // Check if the model exists if (is_null($model = AssetModel::find($modelId))) { - // Redirect to the blogs management page - return redirect()->to('hardware/models')->with('error', trans('admin/models/message.not_found')); + return redirect()->route('models.index')->with('error', trans('admin/models/message.not_found')); } if ($model->assets->count() > 0) { @@ -363,8 +362,7 @@ public function getClone($modelId = null) { // Check if the model exists if (is_null($model_to_clone = AssetModel::find($modelId))) { - // Redirect to the model management page - return redirect()->to('assets/models')->with('error', trans('admin/models/message.does_not_exist')); + return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist')); } $model = clone $model_to_clone; @@ -459,16 +457,16 @@ public function getDatatable(Request $request, $status = null) $rows[] = array( 'id' => $model->id, - 'manufacturer' => (string)link_to('/admin/settings/manufacturers/'.$model->manufacturer->id.'/view', $model->manufacturer->name), + 'manufacturer' => (string)link_to_route('manufacturers.show', $model->manufacturer->name, ['manufacturer' => $model->manufacturer->id]), 'name' => (string)link_to_route('models.show',$model->name, ['model' => $model->id]), - 'image' => ($model->image!='') ? '' : '', + 'image' => ($model->image!='') ? '' : '', 'modelnumber' => $model->model_number, 'numassets' => $model->assets->count(), 'depreciation' => (($model->depreciation) && ($model->depreciation->id > 0)) ? $model->depreciation->name.' ('.$model->depreciation->months.')' : trans('general.no_depreciation'), - 'category' => ($model->category) ? (string)link_to('admin/settings/categories/'.$model->category->id.'/view', $model->category->name) : '', + 'category' => ($model->category) ? (string)link_to_route('categories.show', $model->category->name, ['category' => $model->category->id]) : '', 'eol' => ($model->eol) ? $model->eol.' '.trans('general.months') : '', 'note' => $model->getNote(), - 'fieldset' => ($model->fieldset) ? (string)link_to('admin/custom_fields/'.$model->fieldset->id, $model->fieldset->name) : '', + 'fieldset' => ($model->fieldset) ? (string)link_to_route('custom_fields/model', $model->fieldset->name, ['model' => $model->fieldset->id]) : '', 'actions' => $actions ); } @@ -480,32 +478,24 @@ public function getDatatable(Request $request, $status = null) /** - * Get the asset information to present to the model view detail page - * - * @author [A. Gianotto] [] - * @since [v2.0] - * @param int $modelId - * @return String JSON - */ - public function getDataView($modelID) + * Get the asset information to present to the model view detail page + * + * @author [A. Gianotto] [] + * @since [v2.0] + * @param Request $request + * @param $modelID + * @return String JSON + * @internal param int $modelId + */ + public function getDataView(Request $request, $modelID) { $assets = Asset::where('model_id', '=', $modelID)->with('company', 'assetstatus'); if (Input::has('search')) { $assets = $assets->TextSearch(e($request->input('search'))); } - - if (Input::has('offset')) { - $offset = e($request->input('offset')); - } else { - $offset = 0; - } - - if (Input::has('limit')) { - $limit = e($request->input('limit')); - } else { - $limit = 50; - } + $offset = request('offset',0); + $limit = request('limit', 50); $allowed_columns = ['name', 'serial','asset_tag']; @@ -535,10 +525,10 @@ public function getDataView($modelID) $rows[] = array( 'id' => $asset->id, - 'name' => (string)link_to('/hardware/'.$asset->id.'/view', $asset->showAssetName()), - 'asset_tag' => (string)link_to('hardware/'.$asset->id.'/view', $asset->asset_tag), + 'name' => (string)link_to_route('hardware.show', $asset->showAssetName(), ['asset' => $asset->id]), + 'asset_tag' => (string)link_to_route('hardware.show', $asset->asset_tag, ['asset' => $asset->id]), 'serial' => $asset->serial, - 'assigned_to' => ($asset->assigned_to) ? (string)link_to('/admin/users/'.$asset->assigned_to.'/view', $asset->assigneduser->fullName()) : '', + 'assigned_to' => ($asset->assigned_to) ? (string)link_to_route('users.show', $asset->assigneduser->fullName(), ['asset' =>$asset->assigned_to]) : '', 'actions' => $actions, 'companyName' => Company::getName($asset) ); diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index 7272d0c11e75..0222c8ef1ce3 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -2,10 +2,10 @@ namespace App\Http\Controllers; use App\Helpers\Helper; -use App\Http\Requests\AssetRequest; -use App\Http\Requests\AssetFileRequest; use App\Http\Requests\AssetCheckinRequest; use App\Http\Requests\AssetCheckoutRequest; +use App\Http\Requests\AssetFileRequest; +use App\Http\Requests\AssetRequest; use App\Models\Actionlog; use App\Models\Asset; use App\Models\AssetMaintenance; @@ -14,20 +14,23 @@ use App\Models\CustomField; use App\Models\Depreciation; use App\Models\Location; -use App\Models\Manufacturer; //for embedded-create +use App\Models\Manufacturer; use App\Models\Setting; use App\Models\Statuslabel; use App\Models\Supplier; use App\Models\User; -use Validator; use Artisan; use Auth; +use Carbon\Carbon; use Config; -use League\Csv\Reader; use DB; +use Gate; +use Illuminate\Database\Eloquent\ModelNotFoundException; +use Illuminate\Http\Request; use Image; use Input; use Lang; +use League\Csv\Reader; use Log; use Mail; use Paginator; @@ -35,13 +38,11 @@ use Response; use Slack; use Str; -use Illuminate\Http\Request; use Symfony\Component\Console\Output\BufferedOutput; use Symfony\Component\HttpFoundation\JsonResponse; use TCPDF; +use Validator; use View; -use Carbon\Carbon; -use Gate; /** * This class controls all actions related to assets for @@ -73,6 +74,7 @@ public function __construct() */ public function index() { + $this->authorize('index', Asset::class); return View::make('hardware/index'); } @@ -90,10 +92,11 @@ public function getAssetByTag() } else { $topsearch = false; } - if ($asset = Asset::where('asset_tag', '=', Input::get('assetTag'))->first()) { - return redirect()->route('hardware.show', $asset->id)->with('topsearch', $topsearch); + if (!$asset = Asset::where('asset_tag', '=', Input::get('assetTag'))->first()) { + return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); } - return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); + $this->authorize('view', $asset); + return redirect()->route('hardware.show', $asset->id)->with('topsearch', $topsearch); } @@ -106,28 +109,19 @@ public function getAssetByTag() */ public function create($model_id = null) { + $this->authorize('create', Asset::class); // Grab the dropdown lists - $model_list = Helper::modelList(); - $statuslabel_list = Helper::statusLabelList(); - $location_list = Helper::locationsList(); - $manufacturer_list = Helper::manufacturerList(); - $category_list = Helper::categoryList('asset'); - $supplier_list = Helper::suppliersList(); - $company_list = Helper::companyList(); - $assigned_to = Helper::usersList(); - $statuslabel_types = Helper::statusTypeList(); - $view = View::make('hardware/edit'); - $view->with('supplier_list', $supplier_list); - $view->with('company_list', $company_list); - $view->with('model_list', $model_list); - $view->with('statuslabel_list', $statuslabel_list); - $view->with('assigned_to', $assigned_to); - $view->with('location_list', $location_list); + $view->with('supplier_list', Helper::suppliersList()); + $view->with('company_list', Helper::companyList()); + $view->with('model_list', Helper::modelList()); + $view->with('statuslabel_list', Helper::statusLabelList()); + $view->with('assigned_to', Helper::usersList()); + $view->with('location_list', Helper::locationsList()); $view->with('item', new Asset); - $view->with('manufacturer', $manufacturer_list); - $view->with('category', $category_list); - $view->with('statuslabel_types', $statuslabel_types); + $view->with('manufacturer', Helper::manufacturerList()); + $view->with('category', Helper::categoryList('asset')); + $view->with('statuslabel_types', Helper::statusTypeList()); if (!is_null($model_id)) { $selected_model = AssetModel::find($model_id); @@ -146,6 +140,7 @@ public function create($model_id = null) */ public function store(AssetRequest $request) { + $this->authorize(Asset::class); // create a new model instance $asset = new Asset(); $asset->model()->associate(AssetModel::find(e(Input::get('model_id')))); @@ -288,14 +283,12 @@ public function store(AssetRequest $request) */ public function edit($assetId = null) { - - // Check if the asset exists if (!$item = Asset::find($assetId)) { - // Redirect to the asset management page + // Redirect to the asset management page with error return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($item)) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); } + //Handles company checks and permissions. + $this->authorize($item); // Grab the dropdown lists $model_list = Helper::modelList(); @@ -330,16 +323,15 @@ public function edit($assetId = null) * @return Redirect */ - public function postEdit(AssetRequest $request, $assetId = null) + public function update(AssetRequest $request, $assetId = null) { // Check if the asset exists if (!$asset = Asset::find($assetId)) { // Redirect to the asset management page with error return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($asset)) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize($asset); if ($request->has('status_id')) { $asset->status_id = e($request->input('status_id')); @@ -477,10 +469,10 @@ public function destroy($assetId) if (is_null($asset = Asset::find($assetId))) { // Redirect to the asset management page with error return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($asset)) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('delete', $asset); + DB::table('assets') ->where('id', $asset->id) ->update(array('assigned_to' => null)); @@ -511,10 +503,10 @@ public function getCheckout($assetId) if (is_null($asset = Asset::find(e($assetId)))) { // Redirect to the asset management page with error return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($asset)) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('checkout', $asset); + // Get the dropdown of users and then pass it to the checkout view $users_list = Helper::usersList(); @@ -536,11 +528,10 @@ public function postCheckout(AssetCheckoutRequest $request, $assetId) // Check if the asset exists if (!$asset = Asset::find($assetId)) { return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($asset)) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); } elseif (!$asset->availableForCheckout()) { return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkout.not_available')); } + $this->authorize('checkout', $asset); $user = User::find(e(Input::get('assigned_to'))); $admin = Auth::user(); @@ -583,9 +574,9 @@ public function getCheckin($assetId, $backto = null) if (is_null($asset = Asset::find($assetId))) { // Redirect to the asset management page with error return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($asset)) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); } + + $this->authorize('checkin', $asset); $statusLabel_list = Helper::statusLabelList(); return View::make('hardware/checkin', compact('asset'))->with('statusLabel_list', $statusLabel_list)->with('backto', $backto); } @@ -605,10 +596,10 @@ public function postCheckin(AssetCheckinRequest $request, $assetId = null, $back if (is_null($asset = Asset::find($assetId))) { // Redirect to the asset management page with error return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($asset)) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('checkin', $asset); + $admin = Auth::user(); if (!is_null($asset->assigned_to)) { @@ -659,7 +650,11 @@ public function postCheckin(AssetCheckinRequest $request, $assetId = null, $back 'fields' => [ [ 'title' => 'Checked In:', - 'value' => class_basename(strtoupper($logaction->item_type)).' asset <'.url('/').'/hardware/'.$asset->id.'/view'.'|'.e($asset->showAssetName()).'> checked in by <'.url('/').'/admin/users/'.Auth::user()->id.'/view'.'|'.e(Auth::user()->fullName()).'>.' + 'value' => class_basename( + strtoupper($logaction->item_type)) + .' asset <'.route('hardware.show', $asset->id).'|'.e($asset->showAssetName()) + .'> checked in by <'.route('users.show',Auth::user()->id) + .'|'.e(Auth::user()->fullName()).'>.' ], [ 'title' => 'Note:', @@ -716,10 +711,8 @@ public function show($assetId = null) { $asset = Asset::withTrashed()->find($assetId); $settings = Setting::getSettings(); - - if (!Company::isCurrentUserHasAccess($asset)) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); - } elseif ($asset->userloc) { + $this->authorize('view', $asset); + if ($asset->userloc) { $use_currency = $asset->userloc->currency; } elseif ($asset->assetloc) { $use_currency = $asset->assetloc->currency; @@ -830,7 +823,7 @@ public function getBarCode($assetId = null) */ public function getImportUpload() { - + $this->authorize('create', Asset::class); $path = config('app.private_uploads').'/imports/assets'; $files = array(); @@ -930,10 +923,7 @@ public function postAPIImportUpload(AssetFileRequest $request) public function getDeleteImportFile($filename) { - if (!Company::isCurrentUserAuthorized()) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); - } - + $this->authorize('create', Asset::class); if (unlink(config('app.private_uploads').'/imports/assets/'.$filename)) { return redirect()->back()->with('success', trans('admin/hardware/message.import.file_delete_success')); } @@ -956,9 +946,7 @@ public function postProcessImportFile() $itemType = Input::get('import-type'); $updateItems = Input::get('import-update'); - if (!Company::isCurrentUserAuthorized()) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); - } + $this->authorize('create', Asset::class); $importOptions = ['filename'=> config('app.private_uploads').'/imports/assets/'.$filename, '--email_format'=>'firstname.lastname', '--username_format'=>'firstname.lastname', @@ -1011,10 +999,10 @@ public function getClone($assetId = null) if (is_null($asset_to_clone = Asset::find($assetId))) { // Redirect to the asset management page return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($asset_to_clone)) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('create',$asset_to_clone); + // Grab the dropdown lists $model_list = Helper::modelList(); $statuslabel_list = Helper::statusLabelList(); @@ -1056,7 +1044,7 @@ public function getClone($assetId = null) */ public function getImportHistory() { - + $this->authorize('checkout', Asset::class); return View::make('hardware/history'); } @@ -1230,12 +1218,10 @@ public function postImportHistory(Request $request) public function getRestore($assetId = null) { - // Get user information + // Get asset information $asset = Asset::withTrashed()->find($assetId); - - if (!Company::isCurrentUserHasAccess($asset)) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); - } elseif (isset($asset->id)) { + $this->authorize('delete', $asset); + if (isset($asset->id)) { // Restore the asset Asset::withTrashed()->where('id', $assetId)->restore(); @@ -1262,6 +1248,7 @@ public function postUpload(AssetFileRequest $request, $assetId = null) if (!$asset = Asset::find($assetId)) { return redirect()->route('hardware')->with('error', trans('admin/hardware/message.does_not_exist')); } + $this->authorize('update', $asset); $destinationPath = config('app.private_uploads').'/assets'; @@ -1309,6 +1296,7 @@ public function postUpload(AssetFileRequest $request, $assetId = null) public function getDeleteFile($assetId = null, $fileId = null) { $asset = Asset::find($assetId); + $this->authorize('update', $asset); $destinationPath = config('app.private_uploads').'/imports/assets'; // the asset is valid @@ -1351,9 +1339,9 @@ public function displayFile($assetId = null, $fileId = null) { $asset = Asset::find($assetId); - // the asset is valid if (isset($asset->id)) { + $this->authorize('view', $asset); if (!Company::isCurrentUserHasAccess($asset)) { @@ -1394,7 +1382,7 @@ public function displayFile($assetId = null, $fileId = null) */ public function postBulkEdit($assets = null) { - + $this->authorize('update', Asset::class); if (!Company::isCurrentUserAuthorized()) { return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); @@ -1430,6 +1418,9 @@ public function postBulkEdit($assets = null) $assets = Asset::with('assigneduser', 'assetloc')->find($asset_ids); + $assets->each(function($asset) { + $this->authorize('delete',$asset); + }); return View::make('hardware/bulk-delete')->with('assets', $assets); // Bulk edit @@ -1474,10 +1465,8 @@ public function postBulkEdit($assets = null) public function postBulkSave($assets = null) { - if (!Company::isCurrentUserAuthorized()) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); - - } elseif (Input::has('bulk_edit')) { + $this->authorize('update', Asset::class); + if (Input::has('bulk_edit')) { $assets = Input::get('bulk_edit'); @@ -1577,10 +1566,8 @@ public function postBulkSave($assets = null) */ public function postBulkDelete($assets = null) { - - if (!Company::isCurrentUserAuthorized()) { - return redirect()->route('hardware.index')->with('error', trans('general.insufficient_permissions')); - } elseif (Input::has('bulk_edit')) { + $this->authorize('delete', Asset::class); + if (Input::has('bulk_edit')) { //$assets = Input::get('bulk_edit'); $assets = Asset::find(Input::get('bulk_edit')); //print_r($assets); @@ -1631,7 +1618,7 @@ public function postBulkDelete($assets = null) public function getDatatable(Request $request, $status = null) { - + $this->authorize('index', Asset::class); $assets = Company::scopeCompanyables(Asset::select('assets.*'))->with('model', 'assigneduser', 'assigneduser.userloc', 'assetstatus', 'defaultLoc', 'assetlog', 'model', 'model.category', 'model.manufacturer', 'model.fieldset', 'assetstatus', 'assetloc', 'company') ->Hardware(); @@ -1756,15 +1743,15 @@ public function getDatatable(Request $request, $status = null) $inout = ''; $actions = '
'; if ($asset->deleted_at=='') { - if (Gate::allows('assets.create')) { + if (Gate::allows('create', $asset)) { $actions .= ' '; } - if (Gate::allows('assets.edit')) { + if (Gate::allows('update', $asset)) { $actions .= ' '; } - if (Gate::allows('assets.delete')) { + if (Gate::allows('delete', $asset)) { $actions .= ''; } @@ -1776,13 +1763,13 @@ public function getDatatable(Request $request, $status = null) if (($asset->availableForCheckout())) { - if (Gate::allows('assets.checkout')) { + if (Gate::allows('checkout', $asset)) { $inout = '' . trans('general.checkout') . ''; } } else { - if (Gate::allows('assets.checkin')) { + if (Gate::allows('checkin', $asset)) { $inout = '' . trans('general.checkin') . ''; } @@ -1792,18 +1779,30 @@ public function getDatatable(Request $request, $status = null) $row = array( 'checkbox' =>'
', - 'id' => $asset->id, - 'image' => (($asset->image) && ($asset->image!='')) ? '' : ((($asset->model) && ($asset->model->image!='')) ? '' : ''), - 'name' => ''.e($asset->name).'', - 'asset_tag' => ''.e($asset->asset_tag).'', + 'id' => $asset->id, + 'image' => (($asset->image) && ($asset->image!='')) + ? '' + : ((($asset->model) && ($asset->model->image!='')) + ? '' + : '' + ), + 'name' => (string) link_to_route('hardware.show', e($asset->name), $asset->id), + 'asset_tag' => (string) link_to_route('hardware.show', e($asset->asset_tag), $asset->id), 'serial' => e($asset->serial), - 'model' => ($asset->model) ? (string)link_to('/hardware/models/'.$asset->model->id.'/view', e($asset->model->name)) : 'No model', + 'model' => ($asset->model) ? (string)link_to_route('models.show', e($asset->model->name), ['model' => $asset->model->id]) : 'No model', 'model_number' => ($asset->model && $asset->model->model_number) ? (string)$asset->model->model_number : '', - 'status_label' => ($asset->assigneduser) ? 'Deployed' : ((e($asset->assetstatus)) ? e($asset->assetstatus->name) : ''), - 'assigned_to' => ($asset->assigneduser) ? (string)link_to(url('/').'/admin/users/'.$asset->assigned_to.'/view', e($asset->assigneduser->fullName())) : '', - 'location' => (($asset->assigneduser) && ($asset->assigneduser->userloc!='')) ? (string)link_to('admin/settings/locations/'.$asset->assigneduser->userloc->id.'/view', e($asset->assigneduser->userloc->name)) : (($asset->defaultLoc!='') ? (string)link_to('admin/settings/locations/'.$asset->defaultLoc->id.'/view', e($asset->defaultLoc->name)) : ''), - 'category' => (($asset->model) && ($asset->model->category)) ?(string)link_to('/admin/settings/categories/'.$asset->model->category->id.'/view', e($asset->model->category->name)) : '', - 'manufacturer' => (($asset->model) && ($asset->model->manufacturer)) ? (string)link_to('/admin/settings/manufacturers/'.$asset->model->manufacturer->id.'/view', e($asset->model->manufacturer->name)) : '', + 'status_label' => ($asset->assigneduser) ? 'Deployed' : ((e($asset->assetstatus)) ? e($asset->assetstatus->name) : ''), + 'assigned_to' => ($asset->assigneduser) ? (string)link_to_route('users.show', e($asset->assigneduser->fullName()), ['user' => $asset->assigned_to]) : '', + 'location' => (($asset->assigneduser) && ($asset->assigneduser->userloc!='')) + ? (string)link_to_route('locations.show', e($asset->assigneduser->userloc->name), ['location' => $asset->assigneduser->userloc->id]) + : (($asset->defaultLoc!='') + ? (string)link_to_route('locations.show', e($asset->defaultLoc->name), ['location' => $asset->defaultLoc->id]) + : '' + ), + 'category' => (($asset->model) && ($asset->model->category)) ?(string)link_to_route('categories.show', e($asset->model->category->name), ['category' => $asset->model->category->id]) : '', + 'manufacturer' => (($asset->model) && ($asset->model->manufacturer)) + ? (string)link_to_route('manufacturers.show', e($asset->model->manufacturer->name), ['manufacturer' => $asset->model->manufacturer->id]) + : '', 'eol' => ($asset->eol_date()) ? $asset->eol_date() : '', 'purchase_cost' => $purchase_cost, 'purchase_date' => ($asset->purchase_date) ? $asset->purchase_date : '', @@ -1811,7 +1810,7 @@ public function getDatatable(Request $request, $status = null) 'order_number' => ($asset->order_number!='') ? ''.e($asset->order_number).'' : '', 'last_checkout' => ($asset->last_checkout!='') ? e($asset->last_checkout) : '', 'expected_checkin' => ($asset->expected_checkin!='') ? e($asset->expected_checkin) : '', - 'created_at' => ($asset->created_at!='') ? e($asset->created_at->format('F j, Y h:iA')) : '', + 'created_at' => ($asset->created_at!='') ? e($asset->created_at->format('F j, Y h:iA')) : '', 'change' => ($inout) ? $inout : '', 'actions' => ($actions) ? $actions : '', 'companyName' => is_null($asset->company) ? '' : e($asset->company->name) @@ -1856,6 +1855,7 @@ public function getDatatable(Request $request, $status = null) public function getBulkCheckout() { + $this->authorize('checkout', Asset::class); // Get the dropdown of users and then pass it to the checkout view $users_list = Helper::usersList(); // Filter out assets that are not deployable. @@ -1868,7 +1868,6 @@ public function getBulkCheckout() public function postBulkCheckout(Request $request) { - $this->validate($request, [ "assigned_to" => 'required' ]); @@ -1897,7 +1896,7 @@ public function postBulkCheckout(Request $request) foreach($asset_ids as $asset_id) { $asset = Asset::find($asset_id); - + $this->authorize('checkout', $asset); $error = $asset->checkOutToUser($user, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), null); if($error) diff --git a/app/Http/Controllers/CategoriesController.php b/app/Http/Controllers/CategoriesController.php index 897463f52f72..eb1e7085de2e 100755 --- a/app/Http/Controllers/CategoriesController.php +++ b/app/Http/Controllers/CategoriesController.php @@ -338,11 +338,11 @@ public function getDataViewAssets(Request $request, $categoryID) } if ($asset->availableForCheckout()) { - if (Gate::allows('assets.checkout')) { + if (Gate::allows('checkout', $asset)) { $inout = ''.trans('general.checkout').''; } } else { - if (Gate::allows('assets.checkin')) { + if (Gate::allows('checkin', $asset)) { $inout = ''.trans('general.checkin').''; } } @@ -350,10 +350,10 @@ public function getDataViewAssets(Request $request, $categoryID) $rows[] = array( 'id' => $asset->id, 'name' => (string)link_to_route('hardware.show', $asset->showAssetName(), ['hardware' => $asset->id]), - 'model' => ($asset->model) ? (string)link_to('hardware/models/'.$asset->model->id.'/view', $asset->model->name) : '', + 'model' => ($asset->model) ? (string)link_to_route('models.show', $asset->model->name, ['model' => $asset->model->id]) : '', 'asset_tag' => $asset->asset_tag, 'serial' => $asset->serial, - 'assigned_to' => ($asset->assigneduser) ? (string)link_to('/admin/users/'.$asset->assigneduser->id.'/view', $asset->assigneduser->fullName()): '', + 'assigned_to' => ($asset->assigneduser) ? (string)link_to_route('users.show', $asset->assigneduser->fullName(), ['user' => $asset->assigneduser->id]): '', 'change' => $inout, 'actions' => $actions, 'companyName' => is_null($asset->company) ? '' : e($asset->company->name) @@ -420,7 +420,12 @@ public function getDataViewAccessories($categoryID) } - public function getDataViewConsumables($categoryID) + /** + * @param $categoryID + * @param Request $request + * @return array + */ + public function getDataViewConsumables($categoryID, Request $request) { $category = Category::with('accessories.company')->find($categoryID); @@ -429,18 +434,8 @@ public function getDataViewConsumables($categoryID) if (Input::has('search')) { $category_assets = $category_assets->TextSearch(e($request->input('search'))); } - - if (Input::has('offset')) { - $offset = e($request->input('offset')); - } else { - $offset = 0; - } - - if (Input::has('limit')) { - $limit = e($request->input('limit')); - } else { - $limit = 50; - } + $offset = request('offset', 0); + $limit = request('limit', 50); $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; @@ -463,7 +458,7 @@ public function getDataViewConsumables($categoryID) $rows[] = array( 'id' => $asset->id, - 'name' => (string) link_to_route('view/consumable', $asset->name, [$asset->id]), + 'name' => (string) link_to_route('consumables.show', $asset->name, [$asset->id]), 'actions' => $actions, 'companyName' => Company::getName($asset), ); diff --git a/app/Http/Controllers/ComponentsController.php b/app/Http/Controllers/ComponentsController.php index 5f7b7d639dd0..38e486fadc34 100644 --- a/app/Http/Controllers/ComponentsController.php +++ b/app/Http/Controllers/ComponentsController.php @@ -41,6 +41,7 @@ class ComponentsController extends Controller */ public function index() { + $this->authorize('view', Component::class); return View::make('components/index'); } @@ -55,6 +56,7 @@ public function index() */ public function create() { + $this->authorize('create', Component::class); // Show the page $category_list = Helper::categoryList('component'); $company_list = Helper::companyList(); @@ -78,7 +80,7 @@ public function create() */ public function store() { - + $this->authorize('create', Component::class); // create a new model instance $component = new Component(); @@ -133,10 +135,10 @@ public function edit($componentId = null) if (is_null($item = Component::find($componentId))) { // Redirect to the blogs management page return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($item)) { - return redirect()->route('components.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('update', $item); + $category_list = Helper::categoryList('component'); $company_list = Helper::companyList(); $location_list = Helper::locationsList(); @@ -163,10 +165,10 @@ public function update($componentId = null) if (is_null($component = Component::find($componentId))) { // Redirect to the blogs management page return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($component)) { - return redirect()->route('components.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('update', $component); + // Update the component data $component->name = e(Input::get('name')); @@ -211,10 +213,10 @@ public function destroy($componentId) { if (is_null($component = Component::find($componentId))) { return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found')); - } elseif (!Company::isCurrentUserHasAccess($component)) { - return redirect()->route('components.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('delete', $component); + $component->delete(); return redirect()->route('components.index')->with('success', trans('admin/components/message.delete.success')); @@ -222,11 +224,13 @@ public function destroy($componentId) public function postBulk($componentId = null) { + //$this->authorize('checkout', $component) echo 'Stubbed - not yet complete'; } public function postBulkSave($componentId = null) { + //$this->authorize('edit', Component::class); echo 'Stubbed - not yet complete'; } @@ -247,19 +251,15 @@ public function show($componentId = null) if (isset($component->id)) { - if (!Company::isCurrentUserHasAccess($component)) { - return redirect()->route('components.index')->with('error', trans('general.insufficient_permissions')); - } else { - return View::make('components/view', compact('component')); - } - } else { - // Prepare the error message - $error = trans('admin/components/message.does_not_exist', compact('id')); + $this->authorize('view', $component); - // Redirect to the user management page - return redirect()->route('components')->with('error', $error); + return View::make('components/view', compact('component')); } + // Prepare the error message + $error = trans('admin/components/message.does_not_exist', compact('id')); + // Redirect to the user management page + return redirect()->route('components')->with('error', $error); } @@ -278,10 +278,10 @@ public function getCheckout($componentId) if (is_null($component = Component::find($componentId))) { // Redirect to the component management page with error return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found')); - } elseif (!Company::isCurrentUserHasAccess($component)) { - return redirect()->route('components.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('checkout', $component); + // Get the dropdown of assets and then pass it to the checkout view $assets_list = Helper::detailedAssetList(); @@ -300,17 +300,13 @@ public function getCheckout($componentId) */ public function postCheckout(Request $request, $componentId) { - - - // Check if the component exists if (is_null($component = Component::find($componentId))) { // Redirect to the component management page with error return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found')); - } elseif (!Company::isCurrentUserHasAccess($component)) { - return redirect()->route('components.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('checkout', $component); $max_to_checkout = $component->numRemaining(); $validator = Validator::make($request->all(),[ @@ -363,7 +359,10 @@ public function postCheckout(Request $request, $componentId) 'fields' => [ [ 'title' => 'Checked Out:', - 'value' => class_basename(strtoupper($logaction->item_type)).' <'.route('components.show', ['component' => $component->id]).'|'.$component->name.'> checked out to <'.url('/').'/hardware/'.$asset->id.'|'.$asset->showAssetName().'> by <'.url('/').'/admin/users/'.$admin_user->id.'/view'.'|'.$admin_user->fullName().'>.' + 'value' => class_basename(strtoupper($logaction->item_type)) + .' <'.route('components.show', ['component' => $component->id]).'|'.$component->name + .'> checked out to <'.route('hardware.show', $asset->id).'|'.$asset->showAssetName() + .'> by <'.route('users.show', $admin_user->id).'|'.$admin_user->fullName().'>.' ], [ 'title' => 'Note:', @@ -395,6 +394,7 @@ public function postCheckout(Request $request, $componentId) **/ public function getDatatable() { + $this->authorize('view', Component::class); $components = Company::scopeCompanyables(Component::select('components.*')->whereNull('components.deleted_at') ->with('company', 'location', 'category')); @@ -440,17 +440,17 @@ public function getDatatable() foreach ($components as $component) { $actions = ''; - if (Gate::allows('components.checkout')) { + if (Gate::allows('checkout', $component)) { $actions .= 'numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . ''; } - if (Gate::allows('components.edit')) { + if (Gate::allows('edit', $component)) { $actions .= ''; } - if (Gate::allows('components.delete')) { + if (Gate::allows('delete', $component)) { $actions .= ''; } @@ -493,13 +493,15 @@ public function getDatatable() */ public function getDataView($componentId) { - //$component = Component::find($componentID); - $component = Component::with('assets')->find($componentId); - + if (is_null($component = Component::with('assets')->find($componentId))) { + // Redirect to the component management page with error + return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found')); + } if (!Company::isCurrentUserHasAccess($component)) { return ['total' => 0, 'rows' => []]; } + $this->authorize('view', $component); $rows = array(); diff --git a/app/Http/Controllers/ConsumablesController.php b/app/Http/Controllers/ConsumablesController.php index 6c9b8363a0fe..5612fe4788a3 100644 --- a/app/Http/Controllers/ConsumablesController.php +++ b/app/Http/Controllers/ConsumablesController.php @@ -38,6 +38,7 @@ class ConsumablesController extends Controller */ public function index() { + $this->authorize('index', Consumable::class); return View::make('consumables/index'); } @@ -52,6 +53,7 @@ public function index() */ public function create() { + $this->authorize('create', Consumable::class); // Show the page $category_list = Helper::categoryList('consumable'); $company_list = Helper::companyList(); @@ -77,6 +79,7 @@ public function create() */ public function store() { + $this->authorize('create', Consumable::class); $consumable = new Consumable(); $consumable->name = e(Input::get('name')); $consumable->category_id = e(Input::get('category_id')); @@ -130,10 +133,10 @@ public function edit($consumableId = null) if (is_null($item = Consumable::find($consumableId))) { // Redirect to the blogs management page return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($item)) { - return redirect()->route('consumables.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize($item); + $category_list = Helper::categoryList('consumable'); $company_list = Helper::companyList(); $location_list = Helper::locationsList(); @@ -160,10 +163,10 @@ public function update($consumableId = null) { if (is_null($consumable = Consumable::find($consumableId))) { return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($consumable)) { - return redirect()->route('consumables.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize($consumable); + $consumable->name = e(Input::get('name')); $consumable->category_id = e(Input::get('category_id')); $consumable->location_id = e(Input::get('location_id')); @@ -210,14 +213,14 @@ public function destroy($consumableId) if (is_null($consumable = Consumable::find($consumableId))) { // Redirect to the blogs management page return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.not_found')); - } elseif (!Company::isCurrentUserHasAccess($consumable)) { - return redirect()->route('consumables.index')->with('error', trans('general.insufficient_permissions')); } - $consumable->delete(); + $this->authorize($consumable); + + $consumable->delete(); - // Redirect to the locations management page - return redirect()->route('consumables.index')->with('success', trans('admin/consumables/message.delete.success')); + // Redirect to the locations management page + return redirect()->route('consumables.index')->with('success', trans('admin/consumables/message.delete.success')); } @@ -235,24 +238,15 @@ public function destroy($consumableId) public function show($consumableId = null) { $consumable = Consumable::find($consumableId); - + $this->authorize($consumable); if (isset($consumable->id)) { - - - if (!Company::isCurrentUserHasAccess($consumable)) { - return redirect()->route('consumables.index')->with('error', trans('general.insufficient_permissions')); - } else { - return View::make('consumables/view', compact('consumable')); - } - } else { - // Prepare the error message - $error = trans('admin/consumables/message.does_not_exist', compact('id')); - - // Redirect to the user management page - return redirect()->route('consumables')->with('error', $error); + return View::make('consumables/view', compact('consumable')); } + // Prepare the error message + $error = trans('admin/consumables/message.does_not_exist', compact('id')); - + // Redirect to the user management page + return redirect()->route('consumables')->with('error', $error); } /** @@ -270,9 +264,8 @@ public function getCheckout($consumableId) if (is_null($consumable = Consumable::find($consumableId))) { // Redirect to the consumable management page with error return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.not_found')); - } elseif (!Company::isCurrentUserHasAccess($consumable)) { - return redirect()->route('consumables.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('checkout', $consumable); // Get the dropdown of users and then pass it to the checkout view $users_list = Helper::usersList(); @@ -296,10 +289,10 @@ public function postCheckout($consumableId) if (is_null($consumable = Consumable::find($consumableId))) { // Redirect to the consumable management page with error return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.not_found')); - } elseif (!Company::isCurrentUserHasAccess($consumable)) { - return redirect()->route('consumables.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('checkout', $consumable); + $admin_user = Auth::user(); $assigned_to = e(Input::get('assigned_to')); @@ -337,7 +330,9 @@ public function postCheckout($consumableId) 'fields' => [ [ 'title' => 'Checked Out:', - 'value' => 'Consumable <'.url('/').'/admin/consumables/'.$consumable->id.'/view'.'|'.$consumable->name.'> checked out to <'.url('/').'/admin/users/'.$user->id.'/view|'.$user->fullName().'> by <'.url('/').'/admin/users/'.$admin_user->id.'/view'.'|'.$admin_user->fullName().'>.' + 'value' => 'Consumable <'.route('consumables.show', $consumable->id).'|'.$consumable->name + .'> checked out to <'.route('users.show', $user->id).'|'.$user->fullName() + .'> by <'.route('users.show', $admin_user->id).'|'.$admin_user->fullName().'>.' ], [ 'title' => 'Note:', @@ -390,6 +385,7 @@ public function postCheckout($consumableId) */ public function getDatatable() { + $this->authorize('index', Consumable::class); $consumables = Company::scopeCompanyables( Consumable::select('consumables.*') ->whereNull('consumables.deleted_at') @@ -441,16 +437,16 @@ public function getDatatable() foreach ($consumables as $consumable) { $actions = ''; - if (Gate::allows('consumables.checkout')) { + if (Gate::allows('checkout', $consumable)) { $actions .= 'numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . ''; } - if (Gate::allows('consumables.edit')) { + if (Gate::allows('update', $consumable)) { $actions .= ''; } - if (Gate::allows('consumables.delete')) { + if (Gate::allows('delete', $consumable)) { $actions .= ''; } @@ -461,14 +457,14 @@ public function getDatatable() $rows[] = array( 'id' => $consumable->id, - 'name' => (string)link_to('admin/consumables/'.$consumable->id.'/view', e($consumable->name)), + 'name' => (string)link_to_route('consumables.show', e($consumable->name), ['consumable' => $consumable->id]), 'location' => ($consumable->location) ? e($consumable->location->name) : '', 'min_amt' => e($consumable->min_amt), 'qty' => e($consumable->qty), - 'manufacturer' => ($consumable->manufacturer) ? (string) link_to('/admin/settings/manufacturers/'.$consumable->manufacturer_id.'/view', $consumable->manufacturer->name): '', + 'manufacturer' => ($consumable->manufacturer) ? (string) link_to_route('manufacturers.show', $consumable->manufacturer->name, ['manufacturer' => $consumable->manufacturer_id]): '', 'model_number' => e($consumable->model_number), 'item_no' => e($consumable->item_no), - 'category' => ($consumable->category) ? (string) link_to('/admin/settings/categories/'.$consumable->category_id.'/view', $consumable->category->name) : 'Missing category', + 'category' => ($consumable->category) ? (string) link_to_route('categories.show', $consumable->category->name, ['category' => $consumable->category_id]) : 'Missing category', 'order_number' => e($consumable->order_number), 'purchase_date' => e($consumable->purchase_date), 'purchase_cost' => Helper::formatCurrencyOutput($consumable->purchase_cost), @@ -516,7 +512,7 @@ function ($query) { foreach ($consumable->consumableAssigments as $consumable_assignment) { $rows[] = array( - 'name' => (string)link_to('/admin/users/'.$consumable_assignment->user->id.'/view', e($consumable_assignment->user->fullName())), + 'name' => (string)link_to_route('users.show', e($consumable_assignment->user->fullName()), ['user' => $consumable_assignment->user->id]), 'created_at' => ($consumable_assignment->created_at->format('Y-m-d H:i:s')=='-0001-11-30 00:00:00') ? '' : $consumable_assignment->created_at->format('Y-m-d H:i:s'), 'admin' => ($consumable_assignment->admin) ? e($consumable_assignment->admin->fullName()) : '', ); diff --git a/app/Http/Controllers/DepreciationsController.php b/app/Http/Controllers/DepreciationsController.php index b1039136cd55..2f5a868c6fa8 100755 --- a/app/Http/Controllers/DepreciationsController.php +++ b/app/Http/Controllers/DepreciationsController.php @@ -104,14 +104,15 @@ public function edit($depreciationId = null) /** - * Validates and stores the updated depreciation data. - * - * @author [A. Gianotto] [save()) { // Redirect to the depreciation page - return redirect()->to("admin/settings/depreciations/")->with('success', trans('admin/depreciations/message.update.success')); + return redirect()->route("depreciations.index")->with('success', trans('admin/depreciations/message.update.success')); } return redirect()->back()->withInput()->withErrors($depreciation->getErrors()); diff --git a/app/Http/Controllers/LicensesController.php b/app/Http/Controllers/LicensesController.php index cb87f347e637..de910be04a9d 100755 --- a/app/Http/Controllers/LicensesController.php +++ b/app/Http/Controllers/LicensesController.php @@ -46,6 +46,7 @@ class LicensesController extends Controller */ public function index() { + $this->authorize('view', License::class); return View::make('licenses/index'); } @@ -60,7 +61,7 @@ public function index() */ public function create() { - + $this->authorize('create', License::class); $maintained_list = array('' => 'Maintained', '1' => 'Yes', '0' => 'No'); return View::make('licenses/edit') @@ -86,7 +87,7 @@ public function create() */ public function store(Request $request) { - + $this->authorize('create', License::class); // create a new model instance $license = new License(); @@ -192,10 +193,10 @@ public function edit($licenseId = null) { if (is_null($item = License::find($licenseId))) { return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($item)) { - return redirect()->route('licenses.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('update', $item); + if ($item->purchase_date == "0000-00-00") { $item->purchase_date = null; } @@ -231,10 +232,10 @@ public function update(Request $request, $licenseId = null) if (is_null($license = License::find($licenseId))) { // Redirect to the blogs management page return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($license)) { - return redirect()->route('licenses.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('update', $license); + // Update the license data $license->name = e($request->input('name')); $license->serial = e($request->input('serial')); @@ -386,10 +387,10 @@ public function destroy($licenseId) if (is_null($license = License::find($licenseId))) { // Redirect to the license management page return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found')); - } elseif (!Company::isCurrentUserHasAccess($license)) { - return redirect()->route('licenses.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('delete', $license); + if ($license->assigned_seats_count > 0) { // Redirect to the license management page @@ -406,9 +407,6 @@ public function destroy($licenseId) $licenseseats->delete(); $license->delete(); - - - // Redirect to the licenses management page return redirect()->route('licenses.index')->with('success', trans('admin/licenses/message.delete.success')); } @@ -416,7 +414,6 @@ public function destroy($licenseId) } - /** * Provides the form view for checking out a license to a user. * Here we pass the license seat ID instead of the license ID, @@ -434,10 +431,10 @@ public function getCheckout($seatId) if (is_null($licenseseat = LicenseSeat::find($seatId))) { // Redirect to the asset management page with error return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found')); - } elseif (!Company::isCurrentUserHasAccess($licenseseat->license)) { - return redirect()->route('licenses.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('checkout', $licenseseat); + // Get the dropdown of users and then pass it to the checkout view $users_list = Helper::usersList(); @@ -467,9 +464,7 @@ public function postCheckout(Request $request, $seatId) $asset_id = e($request->input('asset_id')); $user = Auth::user(); - if (!Company::isCurrentUserHasAccess($licenseseat->license)) { - return redirect()->route('licenses.index')->with('error', trans('general.insufficient_permissions')); - } + $this->authorize('checkout', $licenseseat); // Declare the rules for the form validation $rules = array( @@ -611,9 +606,8 @@ public function getCheckin($seatId = null, $backto = null) if (is_null($licenseseat = LicenseSeat::find($seatId))) { // Redirect to the asset management page with error return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found')); - } elseif (!Company::isCurrentUserHasAccess($licenseseat->license)) { - return redirect()->route('licenses.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('checkin', $licenseseat); return View::make('licenses/checkin', compact('licenseseat'))->with('backto', $backto); } @@ -640,9 +634,7 @@ public function postCheckin($seatId = null, $backto = null) $license = License::find($licenseseat->license_id); - if (!Company::isCurrentUserHasAccess($license)) { - return redirect()->route('licenses.index')->with('error', trans('general.insufficient_permissions')); - } + $this->authorize('checkin', $licenseseat); if (!$license->reassignable) { // Not allowed to checkin @@ -697,7 +689,8 @@ public function postCheckin($seatId = null, $backto = null) 'fields' => [ [ 'title' => 'Checked In:', - 'value' => 'License: <'.url('/').'/admin/licenses/'.$license->id.'/view'.'|'.$license->name.'> checked in by <'.url('/').'/admin/users/'.$user->id.'/view'.'|'.$user->fullName().'>.' + 'value' => 'License: <'.route('licenses.show', $license->id).'|'.$license->name + .'> checked in by <'.route('users.show', $user->id).'|'.$user->fullName().'>.' ], [ 'title' => 'Note:', @@ -739,29 +732,23 @@ public function show($licenseId = null) { $license = License::find($licenseId); - $license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset'); - if (isset($license->id)) { - - if (!Company::isCurrentUserHasAccess($license)) { - return redirect()->route('licenses.index')->with('error', trans('general.insufficient_permissions')); - } + $license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset'); + $this->authorize('view', $license); return View::make('licenses/view', compact('license')); - - } else { - $error = trans('admin/licenses/message.does_not_exist', compact('id')); - return redirect()->route('licenses.index')->with('error', $error); } + $error = trans('admin/licenses/message.does_not_exist', compact('id')); + return redirect()->route('licenses.index')->with('error', $error); } public function getClone($licenseId = null) { if (is_null($license_to_clone = License::find($licenseId))) { return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist')); - } elseif (!Company::isCurrentUserHasAccess($license_to_clone)) { - return redirect()->route('licenses.index')->with('error', trans('general.insufficient_permissions')); } + $this->authorize('create', License::class); + $maintained_list = array('' => 'Maintained', '1' => 'Yes', '0' => 'No'); $company_list = Helper::companyList(); //clone the orig @@ -795,16 +782,11 @@ public function getClone($licenseId = null) public function postUpload($licenseId = null) { $license = License::find($licenseId); - // the license is valid $destinationPath = config('app.private_uploads').'/licenses'; if (isset($license->id)) { - - - if (!Company::isCurrentUserHasAccess($license)) { - return redirect()->route('licenses.index')->with('error', trans('general.insufficient_permissions')); - } + $this->authorize('update', $license); if (Input::hasFile('licensefile')) { @@ -815,40 +797,31 @@ public function postUpload($licenseId = null) ); $validator = Validator::make(array('licensefile'=> $file), $rules); - if ($validator->passes()) { - - $extension = $file->getClientOriginalExtension(); - $filename = 'license-'.$license->id.'-'.str_random(8); - $filename .= '-'.str_slug($file->getClientOriginalName()).'.'.$extension; - $upload_success = $file->move($destinationPath, $filename); - - //Log the upload to the log - $license->logUpload($filename, e($request->input('notes'))); - } else { + if ($validator->fails()) { return redirect()->back()->with('error', trans('admin/licenses/message.upload.invalidfiles')); } + $extension = $file->getClientOriginalExtension(); + $filename = 'license-'.$license->id.'-'.str_random(8); + $filename .= '-'.str_slug($file->getClientOriginalName()).'.'.$extension; + $upload_success = $file->move($destinationPath, $filename); - + //Log the upload to the log + $license->logUpload($filename, e($request->input('notes'))); } if ($upload_success) { return redirect()->back()->with('success', trans('admin/licenses/message.upload.success')); - } else { - return redirect()->back()->with('success', trans('admin/licenses/message.upload.error')); } + return redirect()->back()->with('error', trans('admin/licenses/message.upload.error')); - } else { - return redirect()->back()->with('error', trans('admin/licenses/message.upload.nofiles')); } - - - } else { - // Prepare the error message - $error = trans('admin/licenses/message.does_not_exist', compact('id')); - - // Redirect to the licence management page - return redirect()->route('licenses.index')->with('error', $error); + return redirect()->back()->with('error', trans('admin/licenses/message.upload.nofiles')); } + // Prepare the error message + $error = trans('admin/licenses/message.does_not_exist', compact('id')); + + // Redirect to the licence management page + return redirect()->route('licenses.index')->with('error', $error); } @@ -869,10 +842,7 @@ public function getDeleteFile($licenseId = null, $fileId = null) // the license is valid if (isset($license->id)) { - - if (!Company::isCurrentUserHasAccess($license)) { - return redirect()->route('licenses.index')->with('error', trans('general.insufficient_permissions')); - } + $this->authorize('edit', $license); $log = Actionlog::find($fileId); $full_filename = $destinationPath.'/'.$log->filename; @@ -882,13 +852,12 @@ public function getDeleteFile($licenseId = null, $fileId = null) $log->delete(); return redirect()->back()->with('success', trans('admin/licenses/message.deletefile.success')); - } else { - // Prepare the error message - $error = trans('admin/licenses/message.does_not_exist', compact('id')); - - // Redirect to the licence management page - return redirect()->route('licenses.index')->with('error', $error); } + // Prepare the error message + $error = trans('admin/licenses/message.does_not_exist', compact('id')); + + // Redirect to the licence management page + return redirect()->route('licenses.index')->with('error', $error); } @@ -910,20 +879,16 @@ public function displayFile($licenseId = null, $fileId = null) // the license is valid if (isset($license->id)) { - if (!Company::isCurrentUserHasAccess($license)) { - return redirect()->route('licenses.index')->with('error', trans('general.insufficient_permissions')); - } + $this->authorize('view', $license); - $log = Actionlog::find($fileId); - $file = $log->get_src('licenses'); - return Response::download($file); - } else { - // Prepare the error message - $error = trans('admin/licenses/message.does_not_exist', compact('id')); - - // Redirect to the licence management page - return redirect()->route('licenses.index')->with('error', $error); + $log = Actionlog::find($fileId); + $file = $log->get_src('licenses'); + return Response::download($file); } + // Prepare the error message + $error = trans('admin/licenses/message.does_not_exist', compact('id')); + // Redirect to the licence management page + return redirect()->route('licenses.index')->with('error', $error); } @@ -937,6 +902,7 @@ public function displayFile($licenseId = null, $fileId = null) */ public function getDatatable(Request $request) { + $this->authorize('view', License::class); $licenses = Company::scopeCompanyables(License::with('company', 'licenseSeatsRelation', 'manufacturer')); if (Input::has('search')) { @@ -973,20 +939,20 @@ public function getDatatable(Request $request) foreach ($licenses as $license) { $actions = ''; - if (Gate::allows('licenses.checkout')) { + if (Gate::allows('checkout', License::class)) { $actions .= '' . trans('general.checkout') . ' '; } - if (Gate::allows('licenses.create')) { + if (Gate::allows('create', $license)) { $actions .= ''; } - if (Gate::allows('licenses.edit')) { + if (Gate::allows('update', $license)) { $actions .= ''; } - if (Gate::allows('licenses.delete')) { + if (Gate::allows('delete', $license)) { $actions .= ''; @@ -1033,6 +999,7 @@ public function getDatatable(Request $request) */ public function getFreeLicense($licenseId) { + $this->authorize('checkout', License::class); if (is_null($license = License::find($licenseId))) { return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.not_found')); } diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 6345c67efdc9..357ceab07438 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -4,6 +4,7 @@ use Input; use Lang; use App\Models\Location; +use phpDocumentor\Reflection\Types\Array_; use Redirect; use App\Models\Setting; use App\Models\User; @@ -354,15 +355,16 @@ public function getDatatable() /** - * Returns a JSON response that contains the users association with the - * selected location, to be used by the location detail view. - * - * @author [A. Gianotto] [] - * @see LocationsController::getView() method that creates the display view - * @param int $locationId - * @since [v1.8] - * @return View - */ + * Returns a JSON response that contains the users association with the + * selected location, to be used by the location detail view. + * + * @author [A. Gianotto] [] + * @see LocationsController::getView() method that creates the display view + * @param $locationID + * @return array + * @internal param int $locationId + * @since [v1.8] + */ public function getDataViewUsers($locationID) { $location = Location::find($locationID); @@ -377,7 +379,7 @@ public function getDataViewUsers($locationID) foreach ($users as $user) { $rows[] = array( - 'name' => (string)link_to('/admin/users/'.$user->id.'/view', e($user->fullName())) + 'name' => (string)link_to_route('users.show', e($user->fullName()), ['user'=>$user->id]) ); } diff --git a/app/Http/Controllers/ManufacturersController.php b/app/Http/Controllers/ManufacturersController.php index 08c9454dbfb9..ff3f61905bbe 100755 --- a/app/Http/Controllers/ManufacturersController.php +++ b/app/Http/Controllers/ManufacturersController.php @@ -1,9 +1,7 @@ with('assets') + $manufacturers = Manufacturer::select(array('id','name'))->with('assets', 'licenses', 'accessories', 'consumables') ->whereNull('deleted_at'); if ($request->has('search')) { @@ -231,9 +229,12 @@ public function getDatatable(Request $request) $actions = ''; $rows[] = array( - 'id' => $manufacturer->id, + 'id' => $manufacturer->id, 'name' => (string)link_to_route('manufacturers.show', e($manufacturer->name),['manufacturer' => $manufacturer->id]), - 'assets' => $manufacturer->assets->count(), + 'assets' => $manufacturer->assets->count(), + 'licenses' => $manufacturer->licenses->count(), + 'accessories' => $manufacturer->accessories->count(), + 'consumables' => $manufacturer->consumables->count(), 'actions' => $actions ); } @@ -246,36 +247,37 @@ public function getDatatable(Request $request) /** - * Generates the JSON used to display the manufacturer detail. - * This JSON returns data on all of the assets with the specified - * manufacturer ID number. - * - * @author [A. Gianotto] [] - * @see ManufacturersController::getView() - * @param int $manufacturerId - * @since [v1.0] - * @return String JSON - */ - public function getDataView($manufacturerId, $itemtype = null) + * Generates the JSON used to display the manufacturer detail. + * This JSON returns data on all of the assets with the specified + * manufacturer ID number. + * + * @author [A. Gianotto] [] + * @see ManufacturersController::getView() + * @param int $manufacturerId + * @param string $itemtype + * @param Request $request + * @return String JSON* @since [v1.0] + */ + public function getDataView($manufacturerId, $itemtype = null, Request $request) { $manufacturer = Manufacturer::find($manufacturerId); switch ($itemtype) { case "assets": - return $this->getDataAssetsView($manufacturer); + return $this->getDataAssetsView($manufacturer, $request); case "licenses": - return $this->getDataLicensesView($manufacturer); + return $this->getDataLicensesView($manufacturer, $request); case "accessories": - return $this->getDataAccessoriesView($manufacturer); + return $this->getDataAccessoriesView($manufacturer, $request); case "consumables": - return $this->getDataConsumablesView($manufacturer); + return $this->getDataConsumablesView($manufacturer, $request); } throw new Exception("We shouldn't be here"); } - protected function getDataAssetsView(Manufacturer $manufacturer) + protected function getDataAssetsView(Manufacturer $manufacturer, Request $request) { $manufacturer = $manufacturer->load('assets.model', 'assets.assigneduser', 'assets.assetstatus', 'assets.company'); $manufacturer_assets = $manufacturer->assets; @@ -308,30 +310,29 @@ protected function getDataAssetsView(Manufacturer $manufacturer) $actions = ''; if ($asset->deleted_at=='') { - $actions = '
'; + $actions = '
'; } elseif ($asset->deleted_at!='') { $actions = ''; } if ($asset->availableForCheckout()) { - if (Gate::allows('assets.checkout')) { + if (Gate::allows('checkout', $asset)) { $inout = ''.trans('general.checkout').''; } } else { - if (Gate::allows('assets.checkin')) { + if (Gate::allows('checkin', $asset)) { $inout = ''.trans('general.checkin').''; } } $rows[] = array( 'id' => $asset->id, - 'name' => (string)link_to('/hardware/'.$asset->id.'/view', e($asset->showAssetName())), + 'name' => (string)link_to_route('hardware.show', e($asset->showAssetName()), [$asset->id]), 'model' => e($asset->model->name), 'asset_tag' => e($asset->asset_tag), 'serial' => e($asset->serial), - 'assigned_to' => ($asset->assigneduser) ? (string)link_to('/admin/users/'.$asset->assigneduser->id.'/view', e($asset->assigneduser->fullName())): '', + 'assigned_to' => ($asset->assigneduser) ? (string)link_to_route('users.show', e($asset->assigneduser->fullName()), [$asset->assigneduser->id]): '', 'actions' => $actions, - // 'companyName' => e(Company::getName($asset)), 'companyName' => is_null($asset->company) ? '' : $asset->company->name ); @@ -344,7 +345,7 @@ protected function getDataAssetsView(Manufacturer $manufacturer) return $data; } - protected function getDataLicensesView(Manufacturer $manufacturer) + protected function getDataLicensesView(Manufacturer $manufacturer, Request $request) { $manufacturer = $manufacturer->load('licenses.company', 'licenses.manufacturer', 'licenses.licenseSeatsRelation'); $licenses = $manufacturer->licenses; @@ -360,30 +361,30 @@ protected function getDataLicensesView(Manufacturer $manufacturer) foreach ($licenses as $license) { $actions = ''; - if (Gate::allows('licenses.checkout')) { + if (Gate::allows('checkout', \App\Models\License::class)) { $actions .= '' . trans('general.checkout') . ' '; } - if (Gate::allows('licenses.create')) { + if (Gate::allows('create', $license)) { $actions .= ''; } - if (Gate::allows('licenses.edit')) { + if (Gate::allows('edit', $license)) { $actions .= ''; } - if (Gate::allows('licenses.delete')) { + if (Gate::allows('delete', $license)) { $actions .= ''; } $actions .=''; $rows[] = array( 'id' => $license->id, - 'name' => (string) link_to('/admin/licenses/'.$license->id.'/view', $license->name), - 'serial' => (string) link_to('/admin/licenses/'.$license->id.'/view', mb_strimwidth($license->serial, 0, 50, "...")), + 'name' => (string) link_to_route('licenses.show', $license->name, [$license->id]), + 'serial' => (string) link_to_route('licenses.show', mb_strimwidth($license->serial, 0, 50, "..."), [$license->id]), 'totalSeats' => $license->licenseSeatCount, 'remaining' => $license->remaincount(), 'license_name' => e($license->license_name), @@ -396,7 +397,7 @@ protected function getDataLicensesView(Manufacturer $manufacturer) 'notes' => ($license->notes) ? e($license->notes) : '', 'actions' => $actions, 'companyName' => is_null($license->company) ? '' : e($license->company->name), - 'manufacturer' => $license->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$license->manufacturer_id.'/view', $license->manufacturer->name) : '' + 'manufacturer' => $license->manufacturer ? (string) link_to_route('manufacturers.show', $license->manufacturer->name, [$license->manufacturer_id]) : '' ); } @@ -405,7 +406,7 @@ protected function getDataLicensesView(Manufacturer $manufacturer) return $data; } - public function getDataAccessoriesView(Manufacturer $manufacturer) + public function getDataAccessoriesView(Manufacturer $manufacturer, Request $request) { $manufacturer = $manufacturer->load( 'accessories.location', @@ -433,15 +434,15 @@ public function getDataAccessoriesView(Manufacturer $manufacturer) foreach ($accessories as $accessory) { $actions = '
'; - if (Gate::allows('accessories.checkout')) { + if (Gate::allows('checkout', $accessory)) { $actions .= 'numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . ''; } - if (Gate::allows('accessories.edit')) { + if (Gate::allows('update', $accessory)) { $actions .= ''; } - if (Gate::allows('accessories.delete')) { + if (Gate::allows('delete', $accessory)) { $actions .= ''; } @@ -449,8 +450,8 @@ public function getDataAccessoriesView(Manufacturer $manufacturer) $company = $accessory->company; $rows[] = array( - 'name' => ''. $accessory->name.'', - 'category' => ($accessory->category) ? (string)link_to('admin/settings/categories/'.$accessory->category->id.'/view', $accessory->category->name) : '', + 'name' => (string)link_to_route('accessories.show', $accessory->name, [$accessory->id]), + 'category' => ($accessory->category) ? (string)link_to_route('categories.show', $accessory->category->name, [$accessory->category->id]) : '', 'qty' => e($accessory->qty), 'order_number' => e($accessory->order_number), 'min_amt' => e($accessory->min_amt), @@ -460,7 +461,7 @@ public function getDataAccessoriesView(Manufacturer $manufacturer) 'numRemaining' => $accessory->numRemaining(), 'actions' => $actions, 'companyName' => is_null($company) ? '' : e($company->name), - 'manufacturer' => $accessory->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$accessory->manufacturer_id.'/view', $accessory->manufacturer->name) : '' + 'manufacturer' => $accessory->manufacturer ? (string) link_to_route('manufacturers.show', $accessory->manufacturer->name, [$accessory->manufacturer_id]) : '' ); } @@ -470,7 +471,7 @@ public function getDataAccessoriesView(Manufacturer $manufacturer) return $data; } - public function getDataConsumablesView($manufacturer) + public function getDataConsumablesView($manufacturer, Request $request) { $manufacturer = $manufacturer->load( 'consumables.location', @@ -497,16 +498,16 @@ public function getDataConsumablesView($manufacturer) foreach ($consumables as $consumable) { $actions = ''; - if (Gate::allows('consumables.checkout')) { + if (Gate::allows('checkout', $consumable)) { $actions .= 'numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . ''; } - if (Gate::allows('consumables.edit')) { + if (Gate::allows('update', $consumable)) { $actions .= ''; } - if (Gate::allows('consumables.delete')) { + if (Gate::allows('delete', $consumable)) { $actions .= ''; } @@ -517,14 +518,14 @@ public function getDataConsumablesView($manufacturer) $rows[] = array( 'id' => $consumable->id, - 'name' => (string)link_to('admin/consumables/'.$consumable->id.'/view', e($consumable->name)), + 'name' => (string)link_to_route('consumables.show', e($consumable->name), [$consumable->id]), 'location' => ($consumable->location) ? e($consumable->location->name) : '', 'min_amt' => e($consumable->min_amt), 'qty' => e($consumable->qty), - 'manufacturer' => ($consumable->manufacturer) ? (string) link_to('/admin/settings/manufacturers/'.$consumable->manufacturer_id.'/view', $consumable->manufacturer->name): '', + 'manufacturer' => ($consumable->manufacturer) ? (string) link_to_route('manufacturers.show', $consumable->manufacturer->name, [$consumable->manufacturer_id]): '', 'model_number' => e($consumable->model_number), 'item_no' => e($consumable->item_no), - 'category' => ($consumable->category) ? (string) link_to('/admin/settings/categories/'.$consumable->category_id.'/view', $consumable->category->name) : 'Missing category', + 'category' => ($consumable->category) ? (string) link_to_route('categories.show', $consumable->category->name, [$consumable->category_id]) : 'Missing category', 'order_number' => e($consumable->order_number), 'purchase_date' => e($consumable->purchase_date), 'purchase_cost' => ($consumable->purchase_cost!='') ? number_format($consumable->purchase_cost, 2): '' , diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 36065cda5d55..572cb5a853f4 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -386,7 +386,7 @@ public function getActivityReportDataTable() 'icon' => '', 'created_at' => date("M d, Y g:iA", strtotime($activity->created_at)), 'action_type' => strtolower(trans('general.'.str_replace(' ','_',$activity->action_type))), - 'admin' => $activity->user ? (string) link_to('/admin/users/'.$activity->user_id.'/view', $activity->user->fullName()) : '', + 'admin' => $activity->user ? (string) link_to_route('users.show', $activity->user->fullName(), [$activity->user_id]) : '', 'target' => $activity_target, 'item' => $activity_item, 'item_type' => $item_type, diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index d3cf45d5b92b..378f4b2aee2d 100755 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -59,6 +59,7 @@ class UsersController extends Controller */ public function index() { + $this->authorize('index', User::class); return View::make('users/index'); } @@ -71,7 +72,7 @@ public function index() */ public function create() { - + $this->authorize('create', User::class); $groups = Group::pluck('name', 'id'); if (Input::old('groups')) { @@ -104,7 +105,7 @@ public function create() */ public function store(SaveUserRequest $request) { - + $this->authorize('create', User::class); $user = new User; //Username, email, and password need to be handled specially because the need to respect config values on an edit. $user->email = $data['email'] = e($request->input('email')); @@ -191,6 +192,7 @@ public function store(SaveUserRequest $request) */ public function apiStore() { + $this->authorize('create', User::class); $user = new User; $inputs = Input::except('csrf_token', 'password_confirm', 'groups', 'email_user'); @@ -260,12 +262,9 @@ public function edit($id = null) try { // Get the user information $user = User::find($id); + $this->authorize('update', $user); $permissions = config('permissions'); - if (!Company::isCurrentUserHasAccess($user)) { - return redirect()->route('users.index')->with('error', trans('general.insufficient_permissions')); - } - $groups = Group::pluck('name', 'id'); $userGroups = $user->groups()->pluck('name', 'id'); @@ -312,7 +311,7 @@ public function update(UpdateUserRequest $request, $id = null) try { $user = User::find($id); - + $this->authorize('update', $user); // Figure out of this user was an admin before this edit $orig_permissions_array = $user->decodePermissions(); @@ -326,11 +325,6 @@ public function update(UpdateUserRequest $request, $id = null) $orig_superuser = '0'; } - - if (!Company::isCurrentUserHasAccess($user)) { - return redirect()->route('users.index')->with('error', trans('general.insufficient_permissions')); - } - } catch (UserNotFoundException $e) { $error = trans('admin/users/message.user_not_found', compact('id')); return redirect()->route('users.index')->with('error', $error); @@ -422,22 +416,8 @@ public function destroy($id = null) try { // Get user information $user = User::find($id); - - // Check if we are not trying to delete ourselves - if ($user->id === Auth::user()->id) { - // Prepare the error message - $error = trans('admin/users/message.error.delete'); - - // Redirect to the user management page - return redirect()->route('users.index')->with('error', $error); - } - - - // Do we have permission to delete this user? - if ((!Auth::user()->isSuperUser()) || (config('app.lock_passwords'))) { - // Redirect to the user management page - return redirect()->route('users.index')->with('error', 'Insufficient permissions!'); - } + // Authorize takes care of many of our logic checks now. + $this->authorize('delete', User::class); if (count($user->assets) > 0) { @@ -483,7 +463,7 @@ public function destroy($id = null) */ public function postBulkEdit() { - + $this->authorize('update', User::class); if ((!Input::has('edit_user')) || (count(Input::has('edit_user')) == 0)) { return redirect()->back()->with('error', 'No users selected'); } else { @@ -509,6 +489,7 @@ public function postBulkEdit() */ public function postBulkSave() { + $this->authorize('update', User::class); if ((!Input::has('edit_user')) || (count(Input::has('edit_user')) == 0)) { return redirect()->back()->with('error', 'No users selected'); @@ -613,24 +594,18 @@ public function postBulkSave() */ public function getRestore($id = null) { - + $this->authorize('edit', User::class); // Get user information if (!$user = User::onlyTrashed()->find($id)) { return redirect()->route('users.index')->with('error', trans('admin/users/messages.user_not_found')); } - if (!Company::isCurrentUserHasAccess($user)) { - return redirect()->route('users.index')->with('error', trans('general.insufficient_permissions')); - } else { - - // Restore the user - if (User::withTrashed()->where('id', $id)->restore()) { - return redirect()->route('users.index')->with('success', trans('admin/users/message.success.restored')); - } else { - return redirect()->route('users.index')->with('error', 'User could not be restored.'); - } - + // Restore the user + if (User::withTrashed()->where('id', $id)->restore()) { + return redirect()->route('users.index')->with('success', trans('admin/users/message.success.restored')); } + return redirect()->route('users.index')->with('error', 'User could not be restored.'); + } @@ -644,25 +619,20 @@ public function getRestore($id = null) */ public function show($userId = null) { + if(!$user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($userId)) { + $error = trans('admin/users/message.user_not_found', compact('id')); - $user = User::with('assets', 'assets.model', 'consumables', 'accessories', 'licenses', 'userloc')->withTrashed()->find($userId); + // Redirect to the user management page + return redirect()->route('users.index')->with('error', $error); + } $userlog = $user->userlog->load('item'); if (isset($user->id)) { - - if (!Company::isCurrentUserHasAccess($user)) { - return redirect()->route('users.index')->with('error', trans('general.insufficient_permissions')); - } else { - return View::make('users/view', compact('user', 'userlog')); - } - } else { - // Prepare the error message - $error = trans('admin/users/message.user_not_found', compact('id')); - - // Redirect to the user management page - return redirect()->route('users.index')->with('error', $error); + $this->authorize('view', $user); + return View::make('users/view', compact('user', 'userlog')); } + } /** @@ -677,7 +647,8 @@ public function getUnsuspend($id = null) { try { // Get user information - //$user = User::find($id); + $user = User::find($id); + $this->authorize('edit', $user); // Check if we are not trying to unsuspend ourselves if ($user->id === Auth::user()->id) { @@ -720,6 +691,7 @@ public function getUnsuspend($id = null) */ public function getClone($id = null) { + $this->authorize('create', User::class); // We need to reverse the UI specific logic for our // permissions here before we update the user. $permissions = Input::get('permissions', array()); @@ -781,6 +753,7 @@ public function getClone($id = null) */ public function getImport() { + $this->authorize('update', User::class); // Get all the available groups //$groups = Sentry::getGroupProvider()->findAll(); // Selected groups @@ -804,7 +777,7 @@ public function getImport() */ public function postImport() { - + $this->authorize('update', User::class); if (!ini_get("auto_detect_line_endings")) { ini_set("auto_detect_line_endings", '1'); } @@ -906,7 +879,7 @@ public function postImport() */ public function getDatatable(Request $request, $status = null) { - + $this->authorize('view', User::class); if (Input::has('offset')) { $offset = e(Input::get('offset')); } else { @@ -971,31 +944,31 @@ public function getDatatable(Request $request, $status = null) $actions = ''; foreach ($user->groups as $group) { - $group_names .= '' . $group->name . ' '; + $group_names .= '' . $group->name . ' '; } if (!is_null($user->deleted_at)) { - if (Gate::allows('users.delete')) { + if (Gate::allows('delete', $user)) { $actions .= ' '; } } else { - if (Gate::allows('users.delete')) { + if (Gate::allows('delete', $user)) { if ($user->accountStatus() == 'suspended') { $actions .= ' '; } } - if (Gate::allows('users.edit')) { + if (Gate::allows('update', $user)) { $actions .= ' '; $actions .= ''; } - if (Gate::allows('users.delete')) { + if (Gate::allows('delete', $user)) { if ((Auth::user()->id !== $user->id) && (!config('app.lock_passwords'))) { $actions .= ' '; @@ -1052,15 +1025,11 @@ public function getDatatable(Request $request, $status = null) public function postUpload(AssetFileRequest $request, $userId = null) { - $user = User::find($userId); $destinationPath = config('app.private_uploads') . '/users'; if (isset($user->id)) { - - if (!Company::isCurrentUserHasAccess($user)) { - return redirect()->route('users.index')->with('error', trans('general.insufficient_permissions')); - } + $this->authorize('update', $user); foreach (Input::file('file') as $file) { @@ -1069,7 +1038,7 @@ public function postUpload(AssetFileRequest $request, $userId = null) $filename .= '-' . str_slug($file->getClientOriginalName()) . '.' . $extension; $upload_success = $file->move($destinationPath, $filename); - //Log the deletion of seats to the log + //Log the uploaded file to the log $logaction = new Actionlog(); $logaction->item_id = $user->id; $logaction->item_type = User::class; @@ -1084,9 +1053,8 @@ public function postUpload(AssetFileRequest $request, $userId = null) } return JsonResponse::create($logaction); - } else { - return JsonResponse::create(["error" => "Failed validation: ".print_r($logaction->getErrors(), true)], 500); } + return JsonResponse::create(["error" => "Failed validation: ".print_r($logaction->getErrors(), true)], 500); } @@ -1106,25 +1074,21 @@ public function getDeleteFile($userId = null, $fileId = null) // the license is valid if (isset($user->id)) { - - if (!Company::isCurrentUserHasAccess($user)) { - return redirect()->route('users.index')->with('error', trans('general.insufficient_permissions')); - } else { - $log = Actionlog::find($fileId); - $full_filename = $destinationPath . '/' . $log->filename; - if (file_exists($full_filename)) { - unlink($destinationPath . '/' . $log->filename); - } - $log->delete(); - return redirect()->back()->with('success', trans('admin/users/message.deletefile.success')); + $this->authorize('update', $user); + $log = Actionlog::find($fileId); + $full_filename = $destinationPath . '/' . $log->filename; + if (file_exists($full_filename)) { + unlink($destinationPath . '/' . $log->filename); } - } else { - // Prepare the error message - $error = trans('admin/users/message.does_not_exist', compact('id')); - - // Redirect to the licence management page - return redirect()->route('users.index')->with('error', $error); + $log->delete(); + return redirect()->back()->with('success', trans('admin/users/message.deletefile.success')); } + // Prepare the error message + $error = trans('admin/users/message.does_not_exist', compact('id')); + + // Redirect to the licence management page + return redirect()->route('users.index')->with('error', $error); + } /** @@ -1138,25 +1102,21 @@ public function getDeleteFile($userId = null, $fileId = null) */ public function displayFile($userId = null, $fileId = null) { - $user = User::find($userId); // the license is valid if (isset($user->id)) { - if (!Company::isCurrentUserHasAccess($user)) { - return redirect()->route('users.index')->with('error', trans('general.insufficient_permissions')); - } else { - $log = Actionlog::find($fileId); - $file = $log->get_src('users'); - return Response::download($file); - } - } else { - // Prepare the error message - $error = trans('admin/users/message.does_not_exist', compact('id')); + $this->authorize('view', $user); - // Redirect to the licence management page - return redirect()->route('users.index')->with('error', $error); + $log = Actionlog::find($fileId); + $file = $log->get_src('users'); + return Response::download($file); } + // Prepare the error message + $error = trans('admin/users/message.does_not_exist', compact('id')); + + // Redirect to the licence management page + return redirect()->route('users.index')->with('error', $error); } /** @@ -1168,20 +1128,20 @@ public function displayFile($userId = null, $fileId = null) */ public function getLDAP() { - + $this->authorize('update', User::class); $location_list = Helper::locationsList(); try { $ldapconn = Ldap::connectToLdap(); } catch (\Exception $e) { - return redirect()->route('users.index')->with('error',$e->getMessage()); + return redirect()->route('users.index')->with('error', $e->getMessage()); } try { Ldap::bindAdminToLdap($ldapconn); } catch (\Exception $e) { - return redirect()->route('users.index')->with('error',$e->getMessage()); + return redirect()->route('users.index')->with('error', $e->getMessage()); } return View::make('users/ldap') @@ -1217,6 +1177,7 @@ public function getLDAP() */ public function postLDAP(Request $request) { + $this->authorize('update', User::class); ini_set('max_execution_time', 600); //600 seconds = 10 minutes ini_set('memory_limit', '500M'); @@ -1313,6 +1274,7 @@ public function postLDAP(Request $request) */ public function getAssetList($userId) { + $this->authorize('view', User::class); $assets = Asset::where('assigned_to', '=', $userId)->with('model')->get(); return response()->json($assets); } @@ -1326,7 +1288,7 @@ public function getAssetList($userId) */ public function getExportUserCsv() { - + $this->authorize('view', User::class); \Debugbar::disable(); diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 40fa9c9190db..e0f032912ba8 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -56,6 +56,8 @@ class Kernel extends HttpKernel 'auth' => \App\Http\Middleware\Authenticate::class, 'authorize' => \App\Http\Middleware\CheckPermissions::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, + 'bindings' => \Illuminate\Routing\Middleware\SubstitutionBindings::class, + 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, ]; diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 826aea705719..9669e2ce9ba9 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -178,7 +178,9 @@ public function checkOutNotifySlack($settings, $admin, $note = null) 'fields' => [ [ 'title' => 'Checked Out:', - 'value' => 'HARDWARE asset <'.config('app.url').'/hardware/'.$this->id.'/view'.'|'.$this->showAssetName().'> checked out to <'.config('app.url').'/admin/users/'.$this->assigned_to.'/view|'.$this->assigneduser->fullName().'> by <'.config('app.url').'/admin/users/'.Auth::user()->id.'/view'.'|'.$admin->fullName().'>.' + 'value' => 'HARDWARE asset <'.route('hardware.show', $this->id).'|'.$this->showAssetName() + .'> checked out to <'.route('users.show', $this->assigned_to).'|'.$this->assigneduser->fullName() + .'> by <'.route('users.show', Auth::user()->id).'|'.$admin->fullName().'>.' ], [ 'title' => 'Note:', diff --git a/app/Models/AssetMaintenance.php b/app/Models/AssetMaintenance.php index 2cc945c41dd8..3b977ccb7831 100644 --- a/app/Models/AssetMaintenance.php +++ b/app/Models/AssetMaintenance.php @@ -28,9 +28,9 @@ class AssetMaintenance extends Model implements ICompanyableChild 'asset_maintenance_type' => 'required', 'title' => 'required|max:100', 'is_warranty' => 'boolean', - 'start_date' => 'required|date_format:Y-m-d', - 'completion_date' => 'date_format:Y-m-d', - 'notes' => 'string', + 'start_date' => 'required|date_format:"Y-m-d"', + 'completion_date' => 'date_format:"Y-m-d', + 'notes' => 'string|nullable', 'cost' => 'numeric|nullable' ]; diff --git a/app/Models/Setting.php b/app/Models/Setting.php index b57e62a15c1a..aefa88286544 100755 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -61,23 +61,15 @@ public static function getSettings() public static function setupCompleted() { - + $users_table_exists = Schema::hasTable('users'); $settings_table_exists = Schema::hasTable('settings'); - + if ($users_table_exists && $settings_table_exists) { $usercount = User::withTrashed()->count(); - - if ($usercount > 0) { - return true; - } - return false; - } else { - return false; + $settingsCount = Setting::count(); + return ($usercount > 0 && $settingsCount > 0); } - return false; - - } diff --git a/app/Models/User.php b/app/Models/User.php index 0786d5381476..efe3f2ba32a4 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -29,6 +29,10 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon protected $injectUniqueIdentifier = true; protected $fillable = ['first_name', 'last_name', 'email','password','username']; + protected $casts = [ + 'activated' => 'boolean', + 'employee_num' => 'integer' + ]; /** * Model validation rules @@ -41,16 +45,15 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon 'username' => 'required|string|min:2|unique_undeleted', 'email' => 'email', 'password' => 'required|min:6', + 'locale' => 'max:10' ]; public function hasAccess($section) { - if ($this->isSuperUser()) { return true; } - $user_groups = $this->groups; @@ -64,7 +67,6 @@ public function hasAccess($section) if (($user_permissions!='') && ((array_key_exists($section, $user_permissions)) && ($user_permissions[$section]=='1'))) { return true; } - // If the user is explicitly denied, return false if (($user_permissions=='') || array_key_exists($section, $user_permissions) && ($user_permissions[$section]=='-1')) { return false; diff --git a/app/Policies/AccessoryPolicy.php b/app/Policies/AccessoryPolicy.php new file mode 100644 index 000000000000..8405f146861b --- /dev/null +++ b/app/Policies/AccessoryPolicy.php @@ -0,0 +1,119 @@ +hasAccess('admin')) { + return true; + } + } + + public function index(User $user) + { + // dd('here'); + return $user->hasAccess('accessories.view'); + } + /** + * Determine whether the user can view the accessory. + * + * @param \App\User $user + * @param \App\Accessory $accessory + * @return mixed + */ + public function view(User $user, Accessory $accessory = null) + { + // + return $user->hasAccess('accessories.view'); + } + + /** + * Determine whether the user can create accessories. + * + * @param \App\User $user + * @return mixed + */ + public function create(User $user) + { + // + return $user->hasAccess('accessories.create'); + } + + /** + * Determine whether the user can update the accessory. + * + * @param \App\User $user + * @param \App\Accessory $accessory + * @return mixed + */ + public function update(User $user, Accessory $accessory = null) + { + // + return $user->hasAccess('accessories.edit'); + } + + /** + * Determine whether the user can delete the accessory. + * + * @param \App\User $user + * @param \App\Accessory $accessory + * @return mixed + */ + public function delete(User $user, Accessory $accessory = null) + { + // + return $user->hasAccess('accessories.delete'); + } + + /** + * Determine whether the user can checkout the accessory. + * + * @param \App\User $user + * @param \App\Accessory $accessory + * @return mixed + */ + public function checkout(User $user, Accessory $accessory = null) + { + return $user->hasAccess('accessories.checkout'); + } + + /** + * Determine whether the user can checkin the accessory. + * + * @param \App\User $user + * @param \App\Accessory $accessory + * @return mixed + */ + public function checkin(User $user, Accessory $accessory = null) + { + return $user->hasAccess('accessories.checkin'); + } + + /** + * Determine whether the user can manage the accessory. + * + * @param \App\User $user + * @param \App\Accessory $accessory + * @return mixed + */ + public function manage(User $user, Accessory $accessory = null) + { + return $user->hasAccess('accessories.checkin') + || $user->hasAccess('accessories.edit') + || $user->hasAccess('accessories.checkout'); + } +} diff --git a/app/Policies/AssetPolicy.php b/app/Policies/AssetPolicy.php new file mode 100644 index 000000000000..c4a72e178fa4 --- /dev/null +++ b/app/Policies/AssetPolicy.php @@ -0,0 +1,81 @@ +hasAccess('admin')) { + return true; + } + } + public function index(User $user) + { + return $user->hasAccess('assets.view'); + } + public function view(User $user, Asset $asset) + { + return $user->hasAccess('assets.view'); + } + + public function viewRequestable(User $user, Asset $asset=null) + { + return $user->hasAccess('assets.view.requestable'); + } + + public function create(User $user) + { + return $user->hasAccess('assets.create'); + } + + public function checkout(User $user, Asset $asset = null) + { + return $user->hasAccess('assets.checkout'); + } + + public function checkin(User $user, Asset $asset = null) + { + return $user->hasAccess('assets.checkin'); + } + + public function delete(User $user, Asset $asset = null) + { + return $user->hasAccess('assets.delete'); + } + public function manage(User $user, Asset $asset = null) + { + return $user->hasAccess('assets.checkin') + || $user->hasAccess('assets.edit') + || $user->hasAccess('assets.delete') + || $user->hasAccess('assets.checkout'); + } + + public function update(User $user, Asset $asset = null) + { + return $user->hasAccess('assets.edit'); + } + +} diff --git a/app/Policies/ComponentPolicy.php b/app/Policies/ComponentPolicy.php new file mode 100644 index 000000000000..5b138d0a5cf5 --- /dev/null +++ b/app/Policies/ComponentPolicy.php @@ -0,0 +1,114 @@ +hasAccess('admin')) { + return true; + } + } + /** + * Determine whether the user can view the component. + * + * @param \App\User $user + * @param \App\Component $component + * @return mixed + */ + public function view(User $user, Component $component = null) + { + // + return $user->hasAccess('components.view'); + } + + /** + * Determine whether the user can create components. + * + * @param \App\User $user + * @return mixed + */ + public function create(User $user) + { + // + return $user->hasAccess('components.create'); + } + + /** + * Determine whether the user can update the component. + * + * @param \App\User $user + * @param \App\Component $component + * @return mixed + */ + public function update(User $user, Component $component = null) + { + // + return $user->hasAccess('components.edit'); + } + + /** + * Determine whether the user can delete the component. + * + * @param \App\User $user + * @param \App\Component $component + * @return mixed + */ + public function delete(User $user, Component $component = null) + { + // + return $user->hasAccess('components.delete'); + } + + /** + * Determine whether the user can checkout the component. + * + * @param \App\User $user + * @param \App\Accessory $component + * @return mixed + */ + public function checkout(User $user, Component $component = null) + { + return $user->hasAccess('components.checkout'); + } + + /** + * Determine whether the user can checkin the component. + * + * @param \App\User $user + * @param \App\Component $component + * @return mixed + */ + public function checkin(User $user, Component $component = null) + { + return $user->hasAccess('components.checkin'); + } + + /** + * Determine whether the user can manage the component. + * + * @param \App\User $user + * @param \App\Component $component + * @return mixed + */ + public function manage(User $user, Component $component = null) + { + return $user->hasAccess('components.checkin') + || $user->hasAccess('components.edit') + || $user->hasAccess('components.checkout'); + } +} diff --git a/app/Policies/ConsumablePolicy.php b/app/Policies/ConsumablePolicy.php new file mode 100644 index 000000000000..d6f640845228 --- /dev/null +++ b/app/Policies/ConsumablePolicy.php @@ -0,0 +1,119 @@ +hasAccess('admin')) { + return true; + } + } + /** + * Determine whether the user can view the consumable. + * + * @param \App\User $user + * @param \App\Consumable $consumable + * @return mixed + */ + public function view(User $user, Consumable $consumable = null) + { + // + return $user->hasAccess('consumables.view'); + } + + /** + * Determine whether the user can create consumables. + * + * @param \App\User $user + * @return mixed + */ + public function create(User $user) + { + // + return $user->hasAccess('consumables.create'); + } + + /** + * Determine whether the user can update the consumable. + * + * @param \App\User $user + * @param \App\Consumable $consumable + * @return mixed + */ + public function update(User $user, Consumable $consumable = null) + { + // + return $user->hasAccess('consumables.edit'); + } + + /** + * Determine whether the user can delete the consumable. + * + * @param \App\User $user + * @param \App\Consumable $consumable + * @return mixed + */ + public function delete(User $user, Consumable $consumable = null) + { + // + return $user->hasAccess('consumables.delete'); + } + + /** + * Determine whether the user can checkout the consumable. + * + * @param \App\User $user + * @param \App\Accessory $consumable + * @return mixed + */ + public function checkout(User $user, Consumable $consumable = null) + { + return $user->hasAccess('consumables.checkout'); + } + + /** + * Determine whether the user can checkin the consumable. + * + * @param \App\User $user + * @param \App\Consumable $consumable + * @return mixed + */ + public function checkin(User $user, Consumable $consumable = null) + { + return $user->hasAccess('consumables.checkin'); + } + + public function index(User $user) + { + return $user->hasAccess('consumables.view'); + } + + /** + * Determine whether the user can manage the consumable. + * + * @param \App\User $user + * @param \App\Consumable $consumable + * @return mixed + */ + public function manage(User $user, Consumable $consumable = null) + { + return $user->hasAccess('consumables.checkin') + || $user->hasAccess('consumables.edit') + || $user->hasAccess('consumables.checkout'); + } +} diff --git a/app/Policies/LicensePolicy.php b/app/Policies/LicensePolicy.php new file mode 100644 index 000000000000..b6c7d9576079 --- /dev/null +++ b/app/Policies/LicensePolicy.php @@ -0,0 +1,127 @@ +hasAccess('admin')) { + return true; + } + } + /** + * Determine whether the user can view the license. + * + * @param \App\User $user + * @param \App\License $license + * @return mixed + */ + public function view(User $user, License $license = null) + { + // + return $user->hasAccess('licenses.view'); + } + + /** + * Determine whether the user can create licenses. + * + * @param \App\User $user + * @return mixed + */ + public function create(User $user) + { + // + return $user->hasAccess('licenses.create'); + } + + /** + * Determine whether the user can update the license. + * + * @param \App\User $user + * @param \App\License $license + * @return mixed + */ + public function update(User $user, License $license = null) + { + // + return $user->hasAccess('licenses.edit'); + } + + /** + * Determine whether the user can delete the license. + * + * @param \App\User $user + * @param \App\License $license + * @return mixed + */ + public function delete(User $user, License $license = null) + { + // + return $user->hasAccess('licenses.delete'); + } + + /** + * Determine whether the user can checkout the license. + * + * @param \App\User $user + * @param \App\Accessory $license + * @return mixed + */ + public function checkout(User $user, LicenseSeat $license = null) + { + return $user->hasAccess('licenses.checkout'); + } + + /** + * Determine whether the user can checkin the license. + * + * @param \App\User $user + * @param \App\License $license + * @return mixed + */ + public function checkin(User $user, LicenseSeat $license = null) + { + return $user->hasAccess('licenses.checkin'); + } + /** + * Determine whether the user can view license keys + * + * @param \App\User $user + * @param \App\License $license + * @return mixed + */ + public function viewKeys(User $user, License $license = null) + { + return $user->hasAccess('licenses.keys'); + } + + /** + * Determine whether the user can manage the license. + * + * @param \App\User $user + * @param \App\License $license + * @return mixed + */ + public function manage(User $user, License $license = null) + { + return $user->hasAccess('licenses.checkin') + || $user->hasAccess('licenses.edit') + || $user->hasAccess('licenses.delete') + || $user->hasAccess('licenses.checkout'); + } +} diff --git a/app/Policies/UserPolicy.php b/app/Policies/UserPolicy.php new file mode 100644 index 000000000000..77c1049288fc --- /dev/null +++ b/app/Policies/UserPolicy.php @@ -0,0 +1,90 @@ +hasAccess('admin')) { + return true; + } + } + /** + * Determine whether the user can view the targetUser. + * + * @param \App\User $user + * @param \App\Consumable $targetUser + * @return mixed + */ + public function view(User $user, User $targetUser = null) + { + // + return $user->hasAccess('users.view'); + } + + /** + * Determine whether the user can create users. + * + * @param \App\User $user + * @return mixed + */ + public function create(User $user) + { + // + return $user->hasAccess('users.create'); + } + + /** + * Determine whether the user can update the targetUser. + * + * @param \App\User $user + * @param \App\User $targetUser + * @return mixed + */ + public function update(User $user, User $targetUser = null) + { + // + return $user->hasAccess('users.edit'); + } + + /** + * Determine whether the user can delete the targetUser. + * + * @param \App\User $user + * @param \App\User $targetUser + * @return mixed + */ + public function delete(User $user, User $targetUser = null) + { + if($targetUser) { + //We can't delete ourselves. + if ($user->id == $targetUser->id) { + return false; + } + + if ((!Auth::user()->isSuperUser()) || (config('app.lock_passwords'))) { + return false; + } + } + return $user->hasAccess('users.delete'); + } + + public function index(User $user) + { + return $user->hasAccess('users.view'); + } +} diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 9c01223f200d..d76ffa486d46 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -2,9 +2,21 @@ namespace App\Providers; -use Laravel\Passport\Passport; -use Illuminate\Support\Facades\Gate; +use App\Models\Accessory; +use App\Models\Asset; +use App\Models\Component; +use App\Models\Consumable; +use App\Models\License; +use App\Models\User; +use App\Policies\AccessoryPolicy; +use App\Policies\AssetPolicy; +use App\Policies\ComponentPolicy; +use App\Policies\ConsumablePolicy; +use App\Policies\LicensePolicy; +use App\Policies\UserPolicy; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; +use Illuminate\Support\Facades\Gate; +use Laravel\Passport\Passport; class AuthServiceProvider extends ServiceProvider { @@ -14,9 +26,12 @@ class AuthServiceProvider extends ServiceProvider * @var array */ protected $policies = [ - //'App\Model' => 'App\Policies\ModelPolicy', - // We should switch to the below - // App\Post::class => PostPolicy::class + Asset::class => AssetPolicy::class, + Accessory::class => AccessoryPolicy::class, + Component::class => ComponentPolicy::class, + Consumable::class => ConsumablePolicy::class, + License::class => LicensePolicy::class, + User::class => UserPolicy::class, ]; /** @@ -28,7 +43,6 @@ public function boot() { $this->registerPolicies(); Passport::routes(); - // -------------------------------- // BEFORE ANYTHING ELSE // -------------------------------- @@ -60,271 +74,6 @@ public function boot() } }); - - # ----------------------------------------- - # Assets - # ----------------------------------------- - Gate::define('assets.view', function ($user) { - if (($user->hasAccess('assets.view')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('assets.view.requestable', function ($user) { - if (($user->hasAccess('assets.view.requestable')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('assets.create', function ($user) { - if (($user->hasAccess('assets.create')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('assets.checkout', function ($user) { - if (($user->hasAccess('assets.checkout')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('assets.checkin', function ($user) { - if (($user->hasAccess('assets.checkin')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('assets.edit', function ($user) { - if (($user->hasAccess('assets.edit')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - // Checks for some level of management - Gate::define('assets.manage', function ($user) { - if (($user->hasAccess('assets.checkin')) || ($user->hasAccess('assets.edit')) || ($user->hasAccess('assets.delete')) || ($user->hasAccess('assets.checkout')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - - # ----------------------------------------- - # Accessories - # ----------------------------------------- - Gate::define('accessories.view', function ($user) { - if (($user->hasAccess('accessories.view')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('accessories.create', function ($user) { - if (($user->hasAccess('accessories.create')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('accessories.edit', function ($user) { - if (($user->hasAccess('accessories.edit')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('accessories.delete', function ($user) { - if (($user->hasAccess('accessories.delete')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('accessories.checkout', function ($user) { - if (($user->hasAccess('accessories.checkout')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('accessories.checkin', function ($user) { - if (($user->hasAccess('accessories.checkin')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - // Checks for some level of management - Gate::define('accessories.manage', function ($user) { - if (($user->hasAccess('accessories.checkin')) || ($user->hasAccess('accessories.edit')) || ($user->hasAccess('accessories.checkout')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - # ----------------------------------------- - # Consumables - # ----------------------------------------- - Gate::define('consumables.view', function ($user) { - if (($user->hasAccess('consumables.view')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('consumables.create', function ($user) { - if (($user->hasAccess('consumables.create')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('consumables.edit', function ($user) { - if (($user->hasAccess('consumables.edit')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('consumables.delete', function ($user) { - if (($user->hasAccess('consumables.delete')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('consumables.checkout', function ($user) { - if (($user->hasAccess('consumables.checkout')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('consumables.checkin', function ($user) { - if (($user->hasAccess('consumables.checkin')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - // Checks for some level of management - Gate::define('consumables.manage', function ($user) { - if (($user->hasAccess('consumables.checkin')) || ($user->hasAccess('consumables.edit')) || ($user->hasAccess('consumables.delete')) || ($user->hasAccess('consumables.checkout')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - - - # ----------------------------------------- - # Users - # ----------------------------------------- - - Gate::define('users.view', function ($user) { - if (($user->hasAccess('users.view')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('users.create', function ($user) { - if (($user->hasAccess('users.create')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('users.edit', function ($user) { - if (($user->hasAccess('users.edit')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('users.delete', function ($user) { - if (($user->hasAccess('users.delete')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - - # ----------------------------------------- - # Components - # ----------------------------------------- - Gate::define('components.view', function ($user) { - if (($user->hasAccess('components.view')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('components.create', function ($user) { - if (($user->hasAccess('components.create')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('components.edit', function ($user) { - if (($user->hasAccess('components.edit')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('components.delete', function ($user) { - if (($user->hasAccess('components.delete')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('components.checkout', function ($user) { - if (($user->hasAccess('components.checkout')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - // Checks for some level of management - Gate::define('components.manage', function ($user) { - if (($user->hasAccess('components.edit')) || ($user->hasAccess('components.delete')) || ($user->hasAccess('components.checkout')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - - # ----------------------------------------- - # Licenses - # ----------------------------------------- - Gate::define('licenses.view', function ($user) { - if (($user->hasAccess('licenses.view')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('licenses.create', function ($user) { - if (($user->hasAccess('licenses.create')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('licenses.edit', function ($user) { - if (($user->hasAccess('licenses.edit')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('licenses.delete', function ($user) { - if (($user->hasAccess('licenses.delete')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('licenses.checkout', function ($user) { - if (($user->hasAccess('licenses.checkout')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('licenses.checkin', function ($user) { - if (($user->hasAccess('licenses.checkin')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - Gate::define('licenses.keys', function ($user) { - if (($user->hasAccess('licenses.keys')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - // Checks for some level of management - Gate::define('licenses.manage', function ($user) { - if (($user->hasAccess('licenses.checkin')) || ($user->hasAccess('licenses.edit')) || ($user->hasAccess('licenses.delete')) || ($user->hasAccess('licenses.checkout')) || ($user->hasAccess('admin'))) { - return true; - } - }); - - # ----------------------------------------- # Self # ----------------------------------------- @@ -333,8 +82,5 @@ public function boot() return true; } }); - - - } } diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php index 2f621abc07e3..aa929d56b3e9 100644 --- a/database/factories/ModelFactory.php +++ b/database/factories/ModelFactory.php @@ -17,393 +17,379 @@ use App\Models\Supplier; $factory->defineAs(App\Models\Asset::class, 'asset', function (Faker\Generator $faker) { - return [ + return [ 'name' => $faker->catchPhrase, - 'model_id' => $faker->numberBetween(1,5), - 'rtd_location_id' => $faker->numberBetween(1,5), + 'model_id' => $faker->numberBetween(1, 5), + 'rtd_location_id' => $faker->numberBetween(1, 5), 'serial' => $faker->uuid, 'status_id' => 1, 'user_id' => 1, 'asset_tag' => $faker->unixTime('now'), 'notes' => $faker->sentence, - 'purchase_date' => $faker->dateTime(), - 'purchase_cost' => $faker->randomFloat(2), - 'order_number' => $faker->numberBetween(1000000,50000000), - 'supplier_id' => $faker->numberBetween(1,5), - 'requestable' => $faker->numberBetween(0,1), + 'purchase_date' => $faker->dateTime(), + 'purchase_cost' => $faker->randomFloat(2), + 'order_number' => $faker->numberBetween(1000000, 50000000), + 'supplier_id' => $faker->numberBetween(1, 5), + 'requestable' => $faker->numberBetween(0, 1), 'company_id' => Company::inRandomOrder()->first()->id, 'requestable' => $faker->boolean() - ]; + ]; }); $factory->defineAs(App\Models\AssetModel::class, 'assetmodel', function (Faker\Generator $faker) { - return [ + return [ 'name' => $faker->catchPhrase, - 'manufacturer_id' => $faker->numberBetween(1,10), - 'category_id' => $faker->numberBetween(1,9), - 'model_number' => $faker->numberBetween(1000000,50000000), + 'manufacturer_id' => $faker->numberBetween(1, 10), + 'category_id' => $faker->numberBetween(1, 9), + 'model_number' => $faker->numberBetween(1000000, 50000000), 'eol' => 1, 'notes' => $faker->paragraph(), 'requestable' => $faker->boolean(), - ]; + ]; }); $factory->defineAs(App\Models\Location::class, 'location', function (Faker\Generator $faker) { return [ - 'name' => $faker->catchPhrase, - 'address' => $faker->streetAddress, - 'address2' => $faker->secondaryAddress, - 'city' => $faker->city, - 'state' => $faker->stateAbbr, - 'country' => $faker->countryCode, - 'currency' => $faker->currencyCode, - 'zip' => $faker->postcode + 'name' => $faker->catchPhrase, + 'address' => $faker->streetAddress, + 'address2' => $faker->secondaryAddress, + 'city' => $faker->city, + 'state' => $faker->stateAbbr, + 'country' => $faker->countryCode, + 'currency' => $faker->currencyCode, + 'zip' => $faker->postcode ]; }); $factory->defineAs(App\Models\Category::class, 'asset-category', function (Faker\Generator $faker) { - return [ + return [ 'name' => $faker->text(20), 'category_type' => $faker->randomElement($array = array ('asset')), 'eula_text' => $faker->paragraph(), 'require_acceptance' => $faker->boolean(), 'checkin_email' => $faker->boolean() - ]; + ]; }); $factory->defineAs(App\Models\Category::class, 'accessory-category', function (Faker\Generator $faker) { - return [ + return [ 'name' => $faker->text(20), 'category_type' => $faker->randomElement($array = array ('accessory')), - ]; + ]; }); $factory->defineAs(App\Models\Category::class, 'component-category', function (Faker\Generator $faker) { - return [ + return [ 'name' => $faker->text(20), 'category_type' => $faker->randomElement($array = array ('component')), - ]; + ]; }); $factory->defineAs(App\Models\Category::class, 'consumable-category', function (Faker\Generator $faker) { - return [ + return [ 'name' => $faker->text(20), 'category_type' => $faker->randomElement($array = array ('consumable')), - ]; + ]; }); $factory->defineAs(App\Models\Company::class, 'company', function (Faker\Generator $faker) { - return [ + return [ 'name' => $faker->company, - ]; + ]; }); $factory->defineAs(App\Models\Manufacturer::class, 'manufacturer', function (Faker\Generator $faker) { - return [ + return [ 'name' => $faker->company, - ]; + ]; }); $factory->defineAs(App\Models\Component::class, 'component', function (Faker\Generator $faker) { - return [ + return [ 'name' => $faker->text(20), - 'category_id' => $faker->numberBetween(21,25), + 'category_id' => $faker->numberBetween(21, 25), 'location_id' => Location::inRandomOrder()->first()->id, 'serial' => $faker->uuid, 'qty' => $faker->numberBetween(3, 10), - 'order_number' => $faker->numberBetween(1000000,50000000), - 'purchase_date' => $faker->dateTime(), - 'purchase_cost' => $faker->randomFloat(2), + 'order_number' => $faker->numberBetween(1000000, 50000000), + 'purchase_date' => $faker->dateTime(), + 'purchase_cost' => $faker->randomFloat(2), 'min_amt' => $faker->numberBetween($min = 1, $max = 2), 'company_id' => Company::inRandomOrder()->first()->id - ]; + ]; }); $factory->defineAs(App\Models\Depreciation::class, 'depreciation', function (Faker\Generator $faker) { - return [ + return [ 'name' => $faker->text(20), 'months' => $faker->numberBetween(1, 10), - ]; + ]; }); $factory->defineAs(App\Models\Accessory::class, 'accessory', function (Faker\Generator $faker) { - return [ + return [ 'company_id' => Company::inRandomOrder()->first()->id, 'name' => $faker->text(20), - 'category_id' => $faker->numberBetween(11,15), + 'category_id' => $faker->numberBetween(11, 15), 'manufacturer_id' => Manufacturer::inRandomOrder()->first()->id, - 'location_id' => $faker->numberBetween(1,5), - 'order_number' => $faker->numberBetween(1000000,50000000), - 'purchase_date' => $faker->dateTime(), - 'purchase_cost' => $faker->randomFloat(2), + 'location_id' => $faker->numberBetween(1, 5), + 'order_number' => $faker->numberBetween(1000000, 50000000), + 'purchase_date' => $faker->dateTime(), + 'purchase_cost' => $faker->randomFloat(2), 'qty' => $faker->numberBetween(5, 10), 'min_amt' => $faker->numberBetween($min = 1, $max = 2), - ]; + ]; }); $factory->defineAs(App\Models\Supplier::class, 'supplier', function (Faker\Generator $faker) { return [ - 'name' => $faker->company, - 'address' => $faker->streetAddress, - 'address2' => $faker->secondaryAddress, - 'city' => $faker->city, - 'state' => $faker->stateAbbr, - 'zip' => $faker->postCode, - 'country' => $faker->countryCode, - 'contact' => $faker->name, - 'phone' => $faker->phoneNumber, - 'fax' => $faker->phoneNumber, - 'email' => $faker->safeEmail, - 'url' => $faker->url, - 'notes' => $faker->paragraph + 'name' => $faker->company, + 'address' => $faker->streetAddress, + 'address2' => $faker->secondaryAddress, + 'city' => $faker->city, + 'state' => $faker->stateAbbr, + 'zip' => $faker->postCode, + 'country' => $faker->countryCode, + 'contact' => $faker->name, + 'phone' => $faker->phoneNumber, + 'fax' => $faker->phoneNumber, + 'email' => $faker->safeEmail, + 'url' => $faker->url, + 'notes' => $faker->text(255) // Supplier notes can be a max of 255 characters. ]; }); $factory->defineAs(App\Models\Consumable::class, 'consumable', function (Faker\Generator $faker) { - return [ + return [ 'name' => $faker->text(20), 'company_id' => Company::inRandomOrder()->first()->id, 'category_id' => $faker->numberBetween(16, 20), - 'model_number' => $faker->numberBetween(1000000,50000000), - 'item_no' => $faker->numberBetween(1000000,50000000), - 'order_number' => $faker->numberBetween(1000000,50000000), - 'purchase_date' => $faker->dateTime(), - 'purchase_cost' => $faker->randomFloat(2), + 'model_number' => $faker->numberBetween(1000000, 50000000), + 'item_no' => $faker->numberBetween(1000000, 50000000), + 'order_number' => $faker->numberBetween(1000000, 50000000), + 'purchase_date' => $faker->dateTime(), + 'purchase_cost' => $faker->randomFloat(2), 'qty' => $faker->numberBetween(5, 10), 'min_amt' => $faker->numberBetween($min = 1, $max = 2), - ]; + ]; }); $factory->defineAs(App\Models\Statuslabel::class, 'rtd', function (Faker\Generator $faker) { - return [ + return [ 'name' => 'Ready to Deploy', 'created_at' => $faker->dateTime(), 'updated_at' => $faker->dateTime(), 'user_id' => 1, - 'deleted_at' => NULL, - 'deployable' => 1, - 'pending' => 0, + 'deleted_at' => null, + 'deployable' => 1, + 'pending' => 0, 'archived' => 0, 'notes' => '' - ]; + ]; }); $factory->defineAs(App\Models\Statuslabel::class, 'pending', function (Faker\Generator $faker) { - return [ + return [ 'name' => 'Pending', 'created_at' => $faker->dateTime(), 'updated_at' => $faker->dateTime(), 'user_id' => 1, - 'deleted_at' => NULL, - 'deployable' => 0, - 'pending' => 1, + 'deleted_at' => null, + 'deployable' => 0, + 'pending' => 1, 'archived' => 0, 'notes' => $faker->sentence - ]; + ]; }); $factory->defineAs(App\Models\Statuslabel::class, 'archived', function (Faker\Generator $faker) { - return [ + return [ 'name' => 'Archived', 'created_at' => $faker->dateTime(), 'updated_at' => $faker->dateTime(), 'user_id' => 1, - 'deleted_at' => NULL, - 'deployable' => 0, - 'pending' => 0, + 'deleted_at' => null, + 'deployable' => 0, + 'pending' => 0, 'archived' => 1, 'notes' => 'These assets are permanently undeployable' - ]; + ]; }); $factory->defineAs(App\Models\Statuslabel::class, 'out_for_diagnostics', function (Faker\Generator $faker) { - return [ + return [ 'name' => 'Out for Diagnostics', 'created_at' => $faker->dateTime(), 'updated_at' => $faker->dateTime(), 'user_id' => 1, - 'deleted_at' => NULL, - 'deployable' => 0, - 'pending' => 0, + 'deleted_at' => null, + 'deployable' => 0, + 'pending' => 0, 'archived' => 0, 'notes' => '' - ]; + ]; }); $factory->defineAs(App\Models\Statuslabel::class, 'out_for_repair', function (Faker\Generator $faker) { - return [ + return [ 'name' => 'Out for Repair', 'created_at' => $faker->dateTime(), 'updated_at' => $faker->dateTime(), 'user_id' => 1, - 'deleted_at' => NULL, - 'deployable' => 0, - 'pending' => 0, + 'deleted_at' => null, + 'deployable' => 0, + 'pending' => 0, 'archived' => 0, 'notes' => '' - ]; + ]; }); $factory->defineAs(App\Models\Statuslabel::class, 'broken', function (Faker\Generator $faker) { - return [ + return [ 'name' => 'Broken - Not Fixable', 'created_at' => $faker->dateTime(), 'updated_at' => $faker->dateTime(), 'user_id' => 1, - 'deleted_at' => NULL, - 'deployable' => 0, - 'pending' => 0, + 'deleted_at' => null, + 'deployable' => 0, + 'pending' => 0, 'archived' => 1, - 'notes' => '' - ]; + 'notes' => '' + ]; }); $factory->defineAs(App\Models\Statuslabel::class, 'lost', function (Faker\Generator $faker) { - return [ + return [ 'name' => 'Lost/Stolen', 'created_at' => $faker->dateTime(), 'updated_at' => $faker->dateTime(), 'user_id' => 1, - 'deleted_at' => NULL, - 'deployable' => 0, - 'pending' => 0, + 'deleted_at' => null, + 'deployable' => 0, + 'pending' => 0, 'archived' => 1, 'notes' => '', - ]; + ]; }); $factory->defineAs(App\Models\License::class, 'license', function (Faker\Generator $faker) { return [ - 'name' => $faker->catchPhrase, - 'serial' => $faker->uuid, - 'seats' => $faker->numberBetween(1, 10), - 'license_email' => $faker->safeEmail, - 'license_name' => $faker->name, - 'order_number' => $faker->numberBetween(1500, 13250), - 'purchase_order' => $faker->numberBetween(1500, 13250), - 'purchase_date' => $faker->dateTime(), - 'purchase_cost' => $faker->randomFloat(2), - 'notes' => $faker->sentence, - 'supplier_id' => Supplier::inRandomOrder()->first()->id, - 'company_id' => Company::inRandomOrder()->first()->id + 'name' => $faker->catchPhrase, + 'serial' => $faker->uuid, + 'seats' => $faker->numberBetween(1, 10), + 'license_email' => $faker->safeEmail, + 'license_name' => $faker->name, + 'order_number' => $faker->numberBetween(1500, 13250), + 'purchase_order' => $faker->numberBetween(1500, 13250), + 'purchase_date' => $faker->dateTime(), + 'purchase_cost' => $faker->randomFloat(2), + 'notes' => $faker->sentence, + 'supplier_id' => Supplier::inRandomOrder()->first()->id, + 'company_id' => Company::inRandomOrder()->first()->id ]; }); $factory->defineAs(App\Models\LicenseSeat::class, 'license-seat', function (Faker\Generator $faker) { - return [ - 'license_id' => $faker->numberBetween(1, 10), - 'created_at' => $faker->dateTime(), - 'updated_at' => $faker->dateTime(), - 'notes' => $faker->sentence, - 'user_id' => '1', - ]; + return [ + 'license_id' => $faker->numberBetween(1, 10), + 'created_at' => $faker->dateTime(), + 'updated_at' => $faker->dateTime(), + 'notes' => $faker->sentence, + 'user_id' => '1', + ]; }); $factory->defineAs(App\Models\Actionlog::class, 'asset-checkout', function (Faker\Generator $faker) { - $company = Company::has('users')->has('assets')->inRandomOrder()->first(); - return [ - 'user_id' => $company->users()->inRandomOrder()->first()->id, - 'action_type' => 'checkout', - 'item_id' => $company->assets()->inRandomOrder()->first()->id, + $company = Company::has('users')->has('assets')->inRandomOrder()->first(); + return [ + 'user_id' => $company->users()->inRandomOrder()->first()->id, + 'action_type' => 'checkout', + 'item_id' => $company->assets()->inRandomOrder()->first()->id, 'target_id' => $company->users()->inRandomOrder()->first()->id, 'target_type' => 'App\\Models\\User', 'created_at' => $faker->dateTime(), 'item_type' => 'App\\Models\\Asset', - 'note' => $faker->sentence, + 'note' => $faker->sentence, 'company_id' => $company->id - ]; + ]; }); $factory->defineAs(App\Models\Actionlog::class, 'license-checkout-asset', function (Faker\Generator $faker) { - $company = Company::has('users')->has('licenses')->inRandomOrder()->first(); + $company = Company::has('users')->has('licenses')->inRandomOrder()->first(); - return [ - 'user_id' => $company->users()->inRandomOrder()->first()->id, - 'action_type' => 'checkout', - 'item_id' => $company->licenses()->whereNotNull('company_id')->inRandomOrder()->first()->id, + return [ + 'user_id' => $company->users()->inRandomOrder()->first()->id, + 'action_type' => 'checkout', + 'item_id' => $company->licenses()->whereNotNull('company_id')->inRandomOrder()->first()->id, 'target_id' => $company->assets()->inRandomOrder()->first()->id, 'target_type' => 'App\\Models\\Asset', 'created_at' => $faker->dateTime(), 'item_type' => 'App\\Models\\License', - 'note' => $faker->sentence, + 'note' => $faker->sentence, 'company_id' => $company->id - ]; + ]; }); $factory->defineAs(App\Models\Actionlog::class, 'accessory-checkout', function (Faker\Generator $faker) { $company = Company::has('users')->has('accessories')->inRandomOrder()->first(); - return [ - 'user_id' => $company->users()->inRandomOrder()->first()->id, - 'action_type' => 'checkout', - 'item_id' => $company->accessories()->whereNotNull('company_id')->inRandomOrder()->first()->id, + return [ + 'user_id' => $company->users()->inRandomOrder()->first()->id, + 'action_type' => 'checkout', + 'item_id' => $company->accessories()->whereNotNull('company_id')->inRandomOrder()->first()->id, 'target_id' => $company->users()->inRandomOrder()->first()->id, 'target_type' => 'App\\Models\\User', 'created_at' => $faker->dateTime(), 'item_type' => 'App\\Models\\Accessory', - 'note' => $faker->sentence, + 'note' => $faker->sentence, 'company_id' => $company->id - ]; + ]; }); $factory->defineAs(App\Models\Actionlog::class, 'consumable-checkout', function (Faker\Generator $faker) { $company = Company::has('users')->has('consumables')->inRandomOrder()->first(); - return [ - 'user_id' => $company->users()->inRandomOrder()->first()->id, - 'action_type' => 'checkout', - 'item_id' => $company->consumables()->whereNotNull('company_id')->inRandomOrder()->first()->id, + return [ + 'user_id' => $company->users()->inRandomOrder()->first()->id, + 'action_type' => 'checkout', + 'item_id' => $company->consumables()->whereNotNull('company_id')->inRandomOrder()->first()->id, 'target_id' => $company->users()->inRandomOrder()->first()->id, 'target_type' => 'App\\Models\\User', 'created_at' => $faker->dateTime(), 'item_type' => 'App\\Models\\Consumable', - 'note' => $faker->sentence, + 'note' => $faker->sentence, 'company_id' => $company->id - ]; + ]; }); $factory->defineAs(App\Models\Actionlog::class, 'component-checkout', function (Faker\Generator $faker) { - $company = Company::has('users')->has('components')->inRandomOrder()->first(); + $company = Company::has('users')->has('components')->inRandomOrder()->first(); - return [ - 'user_id' => $company->users()->inRandomOrder()->first()->id, - 'action_type' => 'checkout', - 'item_id' => $company->components()->whereNotNull('company_id')->inRandomOrder()->first()->id, + return [ + 'user_id' => $company->users()->inRandomOrder()->first()->id, + 'action_type' => 'checkout', + 'item_id' => $company->components()->whereNotNull('company_id')->inRandomOrder()->first()->id, 'target_id' => $company->users()->inRandomOrder()->first()->id, 'target_type' => 'App\\Models\\User', 'created_at' => $faker->dateTime(), 'item_type' => 'App\\Models\\Component', - 'note' => $faker->sentence, + 'note' => $faker->sentence, 'company_id' => $company->id - ]; + ]; }); $factory->defineAs(App\Models\CustomField::class, 'customfield-ip', function (Faker\Generator $faker) { - return [ + return [ 'name' => $faker->catchPhrase, 'format' => 'IP', 'element' => 'text', - ]; + ]; }); -$factory->defineAs(App\Models\User::class, 'valid-user', function (Faker\Generator $faker) { - return [ - 'first_name' => $faker->firstName, - 'last_name' => $faker->lastName, - 'username' => $faker->username, - 'password' => $faker->password, - 'email' => $faker->safeEmail, - 'company_id' => Company::inRandomOrder()->first()->id, - 'locale' => $faker->locale, - 'employee_num' => $faker->numberBetween(3500, 35050), - 'jobtitle' => $faker->word, - 'phone' => $faker->phoneNumber, - 'notes' => $faker->sentence - ]; -}); + diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php new file mode 100644 index 000000000000..c0b628e80cc0 --- /dev/null +++ b/database/factories/UserFactory.php @@ -0,0 +1,249 @@ +defineAs(App\Models\User::class, 'valid-user', function (Faker\Generator $faker) { + return [ + 'first_name' => $faker->firstName, + 'last_name' => $faker->lastName, + 'username' => $faker->username, + 'password' => $faker->password, + 'permissions' => '{"user":"0"}', + 'email' => $faker->safeEmail, + 'company_id' => function () { + return factory(App\Models\Company::class, 'company')->create()->id; + }, + 'locale' => $faker->locale, + 'employee_num' => $faker->numberBetween(3500, 35050), + 'jobtitle' => $faker->word, + 'phone' => $faker->phoneNumber, + 'notes' => $faker->sentence + ]; +}); +// USER GLOBAL PERMISSION STATES +$factory->state(App\Models\User::class, 'superuser', function ($faker) { + return [ + 'permissions' => '{"superuser":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'admin', function ($faker) { + return [ + 'permissions' => '{"admin":"1"}', + ]; +}); +// USER ASSET PERMISSION STATES +$factory->state(App\Models\User::class, 'view-assets', function ($faker) { + return [ + 'permissions' => '{"assets.view":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'create-assets', function ($faker) { + return [ + 'permissions' => '{"assets.create":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'edit-assets', function ($faker) { + return [ + 'permissions' => '{"assets.edit":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'delete-assets', function ($faker) { + return [ + 'permissions' => '{"assets.delete":"1",}', + ]; +}); + +$factory->state(App\Models\User::class, 'checkin-assets', function ($faker) { + return [ + 'permissions' => '{"assets.checkin":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'checkout-assets', function ($faker) { + return [ + 'permissions' => '{"assets.checkout":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'view-requestable-assets', function ($faker) { + return [ + 'permissions' => '{"assets.view.requestable":"1"}', + ]; +}); + +// USER ACCESSORY PERMISSION STATES +$factory->state(App\Models\User::class, 'view-accessories', function ($faker) { + return [ + 'permissions' => '{"accessories.view":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'create-accessories', function ($faker) { + return [ + 'permissions' => '{"accessories.create":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'edit-accessories', function ($faker) { + return [ + 'permissions' => '{"accessories.edit":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'delete-accessories', function ($faker) { + return [ + 'permissions' => '{"accessories.delete":"1",}', + ]; +}); + +$factory->state(App\Models\User::class, 'checkin-accessories', function ($faker) { + return [ + 'permissions' => '{"accessories.checkin":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'checkout-accessories', function ($faker) { + return [ + 'permissions' => '{"accessories.checkout":"1"}', + ]; +}); + +// USER CONSUMABLE PERMISSION STATES +$factory->state(App\Models\User::class, 'view-consumables', function ($faker) { + return [ + 'permissions' => '{"consumables.view":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'create-consumables', function ($faker) { + return [ + 'permissions' => '{"consumables.create":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'edit-consumables', function ($faker) { + return [ + 'permissions' => '{"consumables.edit":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'delete-consumables', function ($faker) { + return [ + 'permissions' => '{"consumables.delete":"1",}', + ]; +}); + +$factory->state(App\Models\User::class, 'checkin-consumables', function ($faker) { + return [ + 'permissions' => '{"consumables.checkin":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'checkout-consumables', function ($faker) { + return [ + 'permissions' => '{"consumables.checkout":"1"}', + ]; +}); + +// USER LICENSE PERMISSION STATES +$factory->state(App\Models\User::class, 'view-licenses', function ($faker) { + return [ + 'permissions' => '{"licenses.view":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'create-licenses', function ($faker) { + return [ + 'permissions' => '{"licenses.create":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'edit-licenses', function ($faker) { + return [ + 'permissions' => '{"licenses.edit":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'delete-licenses', function ($faker) { + return [ + 'permissions' => '{"licenses.delete":"1",}', + ]; +}); + +$factory->state(App\Models\User::class, 'checkout-licenses', function ($faker) { + return [ + 'permissions' => '{"licenses.checkout":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'view-keys-licenses', function ($faker) { + return [ + 'permissions' => '{"licenses.keys":"1"}', + ]; +}); + +// USER COMPONENTS PERMISSION STATES +$factory->state(App\Models\User::class, 'view-components', function ($faker) { + return [ + 'permissions' => '{"components.view":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'create-components', function ($faker) { + return [ + 'permissions' => '{"components.create":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'edit-components', function ($faker) { + return [ + 'permissions' => '{"components.edit":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'delete-components', function ($faker) { + return [ + 'permissions' => '{"components.delete":"1",}', + ]; +}); + +$factory->state(App\Models\User::class, 'checkin-components', function ($faker) { + return [ + 'permissions' => '{"components.checkin":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'checkout-components', function ($faker) { + return [ + 'permissions' => '{"components.checkout":"1"}', + ]; +}); + +// USER USER PERMISSION STATES +$factory->state(App\Models\User::class, 'view-users', function ($faker) { + return [ + 'permissions' => '{"users.view":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'create-users', function ($faker) { + return [ + 'permissions' => '{"users.create":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'edit-users', function ($faker) { + return [ + 'permissions' => '{"users.edit":"1"}', + ]; +}); + +$factory->state(App\Models\User::class, 'delete-users', function ($faker) { + return [ + 'permissions' => '{"users.delete":"1",}', + ]; +}); diff --git a/database/migrations/2016_12_19_004212_adjust_locale_length_to_10.php b/database/migrations/2016_12_19_004212_adjust_locale_length_to_10.php new file mode 100644 index 000000000000..ef31f4080e9c --- /dev/null +++ b/database/migrations/2016_12_19_004212_adjust_locale_length_to_10.php @@ -0,0 +1,34 @@ +string('locale', 10)->nullable()->default(config('app.locale'))->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + // + $table->string('locale', 5)->nullable()->default(config('app.locale'))->change(); + }); + } +} diff --git a/resources/views/accessories/index.blade.php b/resources/views/accessories/index.blade.php index c8059ba03137..592b0b8dc5c1 100755 --- a/resources/views/accessories/index.blade.php +++ b/resources/views/accessories/index.blade.php @@ -7,7 +7,7 @@ @stop @section('header_right') - @can('accessories.create') + @can('create', \App\Models\Accessory::class) {{ trans('general.create') }} @endcan @stop diff --git a/resources/views/accessories/view.blade.php b/resources/views/accessories/view.blade.php index 3518f7ff6274..947047c539e1 100644 --- a/resources/views/accessories/view.blade.php +++ b/resources/views/accessories/view.blade.php @@ -14,22 +14,22 @@ {{-- Right header --}} @section('header_right') - @can('accessories.manage') + @can('manage', \App\Models\Accessory::class)
diff --git a/resources/views/components/index.blade.php b/resources/views/components/index.blade.php index 2421ab44f0ad..1bb5c3f2c2cf 100644 --- a/resources/views/components/index.blade.php +++ b/resources/views/components/index.blade.php @@ -7,7 +7,7 @@ @stop @section('header_right') - @can('components.create') + @can('create', \App\Models\Component::class) {{ trans('general.create') }} @endcan @stop diff --git a/resources/views/components/view.blade.php b/resources/views/components/view.blade.php index ea995aca98e5..a8f630703926 100644 --- a/resources/views/components/view.blade.php +++ b/resources/views/components/view.blade.php @@ -10,27 +10,27 @@ {{-- Right header --}} @section('header_right') - @can('components.manage') - + @can('manage', $component) + @endcan @stop diff --git a/resources/views/consumables/index.blade.php b/resources/views/consumables/index.blade.php index c3a4f6e4ef8c..25caca4c369a 100644 --- a/resources/views/consumables/index.blade.php +++ b/resources/views/consumables/index.blade.php @@ -7,7 +7,7 @@ @stop @section('header_right') - @can('consumables.create') + @can('create', \App\Models\Consumable::class) {{ trans('general.create') }} @endcan @stop diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 5a147aba7abf..d855ebf879c8 100755 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -24,7 +24,7 @@
- @can('assets.view') + @can('index', \App\Models\Asset::class) {{ trans('general.moreinfo') }} @endcan @@ -40,7 +40,7 @@
- @can('licenses.view') + @can('view', \App\Models\License::class) {{ trans('general.moreinfo') }} @endcan @@ -56,7 +56,7 @@
- @can('accessories.view') + @can('index', \App\Models\Accessory::class) {{ trans('general.moreinfo') }} @endcan @@ -72,7 +72,7 @@
- @can('consumables.view') + @can('index', \App\Models\Consumable::class) {{ trans('general.moreinfo') }} @endcan diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 4a1ef8251f99..77d04615a9f4 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -11,23 +11,23 @@ {{-- Right header --}} @section('header_right') - @can('assets.manage') - + @can('manage', \App\Models\Asset::class) + @endcan @stop @@ -496,10 +496,10 @@
- @can('assets.edit') -
{{ trans('general.asset_maintenances') }} - [ {{ trans('button.add') }} ] -
+ @can('update', \App\Models\Asset::class) +
{{ trans('general.asset_maintenances') }} + [ {{ trans('button.add') }} ] +
@endcan @@ -516,7 +516,7 @@ {{ trans('admin/asset_maintenances/table.is_warranty') }} {{ trans('admin/asset_maintenances/form.cost') }} {{ trans('general.admin') }} - @can('assets.edit') + @can('update', \App\Models\Asset::class) {{ trans('table.actions') }} @endcan @@ -537,14 +537,14 @@
{{ $use_currency.$assetMaintenance->cost }} @if ($assetMaintenance->admin) - {{ $assetMaintenance->admin->fullName() }} + {{ $assetMaintenance->admin->fullName() }} @endif cost; ?> - @can('assets.edit') - - - + @can('update', \App\Models\Asset::class) + + + @endcan @endif @@ -671,31 +671,31 @@
- @can('assets.edit') - {{ Form::open([ - 'method' => 'POST', - 'route' => ['upload/asset', $asset->id], - 'files' => true, 'class' => 'form-horizontal' ]) }} + @can('update', \App\Models\Asset::class) + {{ Form::open([ + 'method' => 'POST', + 'route' => ['upload/asset', $asset->id], + 'files' => true, 'class' => 'form-horizontal' ]) }} -
- Browse for file... - {{ Form::file('assetfile[]', ['multiple' => 'multiple']) }} - -
-
- {{ Form::text('notes', Input::old('notes', Input::old('notes')), array('class' => 'form-control','placeholder' => 'Notes')) }} -
-
- -
+
+ Browse for file... + {{ Form::file('assetfile[]', ['multiple' => 'multiple']) }} + +
+
+ {{ Form::text('notes', Input::old('notes', Input::old('notes')), array('class' => 'form-control','placeholder' => 'Notes')) }} +
+
+ +
-
-

{{ trans('admin/hardware/general.filetype_info') }}

-
-
+
+

{{ trans('admin/hardware/general.filetype_info') }}

+
+
- {{ Form::close() }} - @endcan + {{ Form::close() }} + @endcan
@@ -732,8 +732,8 @@ @endif - @can('assets.edit') - + @can('update', \App\Models\Asset::class) + @endcan diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 723abbc62a1e..4cfe42fd4f63 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -128,35 +128,35 @@