Skip to content

A free open source IT asset/license management system

Discussion: Moving to policies for controller based authorization (#3080)

Daniel Meltzercd8c58537756
diff --git a/.env.testing b/.env.testing
index 1c2b1b9634..7a44e2154d 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 d783b2712c..e68578b2bc 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 protected] --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 protected] --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 d25a3cb799..34a80ee27c 100644
--- a/app/Console/Commands/SendExpirationAlerts.php
+++ b/app/Console/Commands/SendExpirationAlerts.php
@@ -89,7 +89,7 @@ class SendExpirationAlerts extends Command
} else {
$license_data['email_content'] .= '<tr style="background-color:#d9534f;">';
}
- $license_data['email_content'] .= '<td><a href="'.config('app.url').'/admin/licenses/'.$license->id.'/view">';
+ $license_data['email_content'] .= '<td><a href="'.route('licenses.show', $license->id).'">';
$license_data['email_content'] .= $license->name.'</a></td>';
$license_data['email_content'] .= '<td>'.$license->expiration_date.'</td>';
$license_data['email_content'] .= '<td>'.$difference.' days</td>';
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 3e04cb550b..12a0570472 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -40,4 +40,9 @@ class Kernel extends ConsoleKernel
$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 b24e4b4dd1..e99414c3fa 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 @@ class AccessoriesController extends Controller
*/
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 @@ class AccessoriesController extends Controller
*/
public function store(Request $request)
{
-
+ $this->authorize(Accessory::class);
// create a new model instance
$accessory = new Accessory();
@@ -123,10 +125,10 @@ class AccessoriesController extends Controller
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 @@ class AccessoriesController extends Controller
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 @@ class AccessoriesController extends Controller
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 @@ class AccessoriesController extends Controller
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 @@ class AccessoriesController extends Controller
// 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 @@ class AccessoriesController extends Controller
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 @@ class AccessoriesController extends Controller
'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 @@ class AccessoriesController extends Controller
}
$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 @@ class AccessoriesController extends Controller
$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 @@ class AccessoriesController extends Controller
'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 @@ class AccessoriesController extends Controller
}
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 @@ class AccessoriesController extends Controller
**/
public function getDatatable(Request $request)
{
+ $this->authorize('index', Accessory::class);
$accessories = Company::scopeCompanyables(
Accessory::select('accessories.*')
->whereNull('accessories.deleted_at')
@@ -578,15 +570,15 @@ class AccessoriesController extends Controller
foreach ($accessories as $accessory) {
$actions = '<nobr>';
- if (Gate::allows('accessories.checkout')) {
+ if (Gate::allows('checkout', $accessory)) {
$actions .= '<a href="' . route('checkout/accessory',
$accessory->id) . '" style="margin-right:5px;" class="btn btn-info btn-sm" ' . (($accessory->numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . '</a>';
}
- if (Gate::allows('accessories.edit')) {
+ if (Gate::allows('update', $accessory)) {
$actions .= '<a href="' . route('accessories.update',
$accessory->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
}
- if (Gate::allows('accessories.delete')) {
+ if (Gate::allows('delete', $accessory)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('accessories.destroy',
$accessory->id) . '" data-content="' . trans('admin/accessories/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($accessory->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
}
@@ -594,7 +586,7 @@ class AccessoriesController extends Controller
$company = $accessory->company;
$rows[] = array(
- 'name' => '<a href="'.url('admin/accessories/'.$accessory->id).'/view">'. $accessory->name.'</a>',
+ 'name' => '<a href="'.route('accessories.show',$accessory->id).'">'. $accessory->name.'</a>',
'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 @@ class AccessoriesController extends Controller
'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 @@ class AccessoriesController extends Controller
foreach ($accessory_users as $user) {
$actions = '';
- if (Gate::allows('accessories.checkin')) {
+ if (Gate::allows('checkin', $accessory)) {
$actions .= '<a href="' . route('checkin/accessory',
$user->pivot->id) . '" class="btn btn-info btn-sm">Checkin</a>';
}
- 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 397c670f38..f0d4faad2f 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 42c3d125c1..b6f2f9dbfa 100644
--- a/app/Http/Controllers/AssetMaintenancesController.php
+++ b/app/Http/Controllers/AssetMaintenancesController.php
@@ -117,7 +117,7 @@ class AssetMaintenancesController extends Controller
foreach ($maintenances as $maintenance) {
$actions = '';
- if (Gate::allows('assets.edit')) {
+ if (Gate::allows('update', Asset::class)) {
$actions .= '<nobr><a href="' . route('maintenances.edit',
$maintenance->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('maintenances.destroy',
$maintenance->id) . '" data-content="' . trans('admin/asset_maintenances/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($maintenance->title) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></nobr>';
@@ -134,13 +134,13 @@ class AssetMaintenancesController extends Controller
'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 @@ class AssetMaintenancesController extends Controller
}
/**
- * Returns a form view to create a new asset maintenance.
- *
- * @see AssetMaintenancesController::postCreate() method that stores the data
- * @author Vincent Sposato <[email protected]>
- * @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 <[email protected]>
+ * @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 @@ class AssetMaintenancesController extends Controller
// get the POST data
$new = $request->all();
-
+// dd($new);
// create a new model instance
$assetMaintenance = new AssetMaintenance();
@@ -308,7 +308,7 @@ class AssetMaintenancesController extends Controller
'' => '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 8cd2d8a63b..6cd4282f75 100755
--- a/app/Http/Controllers/AssetModelsController.php
+++ b/app/Http/Controllers/AssetModelsController.php
@@ -176,7 +176,7 @@ class AssetModelsController extends Controller
// 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 @@ class AssetModelsController extends Controller
// 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 @@ class AssetModelsController extends Controller
{
// 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 @@ class AssetModelsController extends Controller
{
// 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 @@ class AssetModelsController extends Controller
$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!='') ? '<img src="'.url('/').'/uploads/models/'.$model->image.'" height=50 width=50>' : '',
+ 'image' => ($model->image!='') ? '<img src="'.url('/').'/uploads/models/'.$model->image.'" height=50 width=50>' : '',
'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 @@ class AssetModelsController extends Controller
/**
- * Get the asset information to present to the model view detail page
- *
- * @author [A. Gianotto] [<[email protected]>]
- * @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] [<[email protected]>]
+ * @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 @@ class AssetModelsController extends Controller
$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 7272d0c11e..0222c8ef1c 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\Company;
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 Redirect;
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 @@ class AssetsController extends Controller
*/
public function index()
{
+ $this->authorize('index', Asset::class);
return View::make('hardware/index');
}
@@ -90,10 +92,11 @@ class AssetsController extends Controller
} 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 @@ class AssetsController extends Controller
*/
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 @@ class AssetsController extends Controller
*/
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 @@ class AssetsController extends Controller
*/
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 @@ class AssetsController extends Controller
* @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 @@ class AssetsController extends Controller
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 @@ class AssetsController extends Controller
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 @@ class AssetsController extends Controller
// 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 @@ class AssetsController extends Controller
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 @@ class AssetsController extends Controller
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 @@ class AssetsController extends Controller
'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 @@ class AssetsController extends Controller
{
$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 @@ class AssetsController extends Controller
*/
public function getImportUpload()
{
-
+ $this->authorize('create', Asset::class);
$path = config('app.private_uploads').'/imports/assets';
$files = array();
@@ -930,10 +923,7 @@ class AssetsController extends Controller
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 @@ class AssetsController extends Controller
$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 @@ class AssetsController extends Controller
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 @@ class AssetsController extends Controller
*/
public function getImportHistory()
{
-
+ $this->authorize('checkout', Asset::class);
return View::make('hardware/history');
}
@@ -1230,12 +1218,10 @@ class AssetsController extends Controller
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 @@ class AssetsController extends Controller
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 @@ class AssetsController extends Controller
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 @@ class AssetsController extends Controller
{
$asset = Asset::find($assetId);
-
// the asset is valid
if (isset($asset->id)) {
+ $this->authorize('view', $asset);
if (!Company::isCurrentUserHasAccess($asset)) {
@@ -1394,7 +1382,7 @@ class AssetsController extends Controller
*/
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 @@ class AssetsController extends Controller
$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 @@ class AssetsController extends Controller
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 @@ class AssetsController extends Controller
*/
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 @@ class AssetsController extends Controller
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 @@ class AssetsController extends Controller
$inout = '';
$actions = '<div style="white-space: nowrap;">';
if ($asset->deleted_at=='') {
- if (Gate::allows('assets.create')) {
+ if (Gate::allows('create', $asset)) {
$actions .= '<a href="' . route('clone/hardware',
$asset->id) . '" class="btn btn-info btn-sm" title="Clone asset" data-toggle="tooltip"><i class="fa fa-clone"></i></a> ';
}
- if (Gate::allows('assets.edit')) {
+ if (Gate::allows('update', $asset)) {
$actions .= '<a href="' . route('hardware.edit',
$asset->id) . '" class="btn btn-warning btn-sm" title="Edit asset" data-toggle="tooltip"><i class="fa fa-pencil icon-white"></i></a> ';
}
- if (Gate::allows('assets.delete')) {
+ if (Gate::allows('delete', $asset)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('hardware.destroy',
$asset->id) . '" data-content="' . trans('admin/hardware/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($asset->asset_tag) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
}
@@ -1776,13 +1763,13 @@ class AssetsController extends Controller
if (($asset->availableForCheckout()))
{
- if (Gate::allows('assets.checkout')) {
+ if (Gate::allows('checkout', $asset)) {
$inout = '<a href="' . route('checkout/hardware',
$asset->id) . '" class="btn btn-info btn-sm" title="Checkout this asset to a user" data-toggle="tooltip">' . trans('general.checkout') . '</a>';
}
} else {
- if (Gate::allows('assets.checkin')) {
+ if (Gate::allows('checkin', $asset)) {
$inout = '<a href="' . route('checkin/hardware',
$asset->id) . '" class="btn btn-primary btn-sm" title="Checkin this asset" data-toggle="tooltip">' . trans('general.checkin') . '</a>';
}
@@ -1792,18 +1779,30 @@ class AssetsController extends Controller
$row = array(
'checkbox' =>'<div class="text-center"><input type="checkbox" name="edit_asset['.$asset->id.']" class="one_required"></div>',
- 'id' => $asset->id,
- 'image' => (($asset->image) && ($asset->image!='')) ? '<img src="'.url('/').'/uploads/assets/'.$asset->image.'" height=50 width=50>' : ((($asset->model) && ($asset->model->image!='')) ? '<img src="'.url('/').'/uploads/models/'.$asset->model->image.'" height=40 width=50>' : ''),
- 'name' => '<a title="'.e($asset->name).'" href="hardware/'.$asset->id.'/view">'.e($asset->name).'</a>',
- 'asset_tag' => '<a title="'.e($asset->asset_tag).'" href="hardware/'.$asset->id.'/view">'.e($asset->asset_tag).'</a>',
+ 'id' => $asset->id,
+ 'image' => (($asset->image) && ($asset->image!=''))
+ ? '<img src="'.url('/').'/uploads/assets/'.$asset->image.'" height=50 width=50>'
+ : ((($asset->model) && ($asset->model->image!=''))
+ ? '<img src="'.url('/').'/uploads/models/'.$asset->model->image.'" height=40 width=50>'
+ : ''
+ ),
+ '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 @@ class AssetsController extends Controller
'order_number' => ($asset->order_number!='') ? '<a href="'.url('/').'/hardware?order_number='.e($asset->order_number).'">'.e($asset->order_number).'</a>' : '',
'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 @@ class AssetsController extends Controller
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 @@ class AssetsController extends Controller
public function postBulkCheckout(Request $request)
{
-
$this->validate($request, [
"assigned_to" => 'required'
]);
@@ -1897,7 +1896,7 @@ class AssetsController extends Controller
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 897463f52f..eb1e7085de 100755
--- a/app/Http/Controllers/CategoriesController.php
+++ b/app/Http/Controllers/CategoriesController.php
@@ -338,11 +338,11 @@ class CategoriesController extends Controller
}
if ($asset->availableForCheckout()) {
- if (Gate::allows('assets.checkout')) {
+ if (Gate::allows('checkout', $asset)) {
$inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>';
}
} else {
- if (Gate::allows('assets.checkin')) {
+ if (Gate::allows('checkin', $asset)) {
$inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>';
}
}
@@ -350,10 +350,10 @@ class CategoriesController extends Controller
$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 @@ class CategoriesController extends Controller
}
- 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 @@ class CategoriesController extends Controller
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 @@ class CategoriesController extends Controller
$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 5f7b7d639d..38e486fadc 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 @@ class ComponentsController extends Controller
*/
public function create()
{
+ $this->authorize('create', Component::class);
// Show the page
$category_list = Helper::categoryList('component');
$company_list = Helper::companyList();
@@ -78,7 +80,7 @@ class ComponentsController extends Controller
*/
public function store()
{
-
+ $this->authorize('create', Component::class);
// create a new model instance
$component = new Component();
@@ -133,10 +135,10 @@ class ComponentsController extends Controller
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 @@ class ComponentsController extends Controller
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 @@ class ComponentsController extends Controller
{
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 @@ class ComponentsController extends Controller
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 @@ class ComponentsController extends Controller
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 @@ class ComponentsController extends Controller
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 @@ class ComponentsController extends Controller
*/
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 @@ class ComponentsController extends Controller
'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 @@ class ComponentsController extends Controller
**/
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 @@ class ComponentsController extends Controller
foreach ($components as $component) {
$actions = '<nobr>';
- if (Gate::allows('components.checkout')) {
+ if (Gate::allows('checkout', $component)) {
$actions .= '<a href="' . route('checkout/component',
$component->id) . '" style="margin-right:5px;" class="btn btn-info btn-sm ' . (($component->numRemaining() > 0) ? '' : ' disabled') . '" ' . (($component->numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . '</a>';
}
- if (Gate::allows('components.edit')) {
+ if (Gate::allows('edit', $component)) {
$actions .= '<a href="' . route('components.edit',
$component->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
}
- if (Gate::allows('components.delete')) {
+ if (Gate::allows('delete', $component)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('components.destroy',
$component->id) . '" data-content="' . trans('admin/components/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($component->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
}
@@ -493,13 +493,15 @@ class ComponentsController extends Controller
*/
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 6c9b8363a0..5612fe4788 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 @@ class ConsumablesController extends Controller
*/
public function create()
{
+ $this->authorize('create', Consumable::class);
// Show the page
$category_list = Helper::categoryList('consumable');
$company_list = Helper::companyList();
@@ -77,6 +79,7 @@ class ConsumablesController extends Controller
*/
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 @@ class ConsumablesController extends Controller
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 @@ class ConsumablesController extends Controller
{
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 @@ class ConsumablesController extends Controller
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 @@ class ConsumablesController extends Controller
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 @@ class ConsumablesController extends Controller
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 @@ class ConsumablesController extends Controller
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 @@ class ConsumablesController extends Controller
'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 @@ class ConsumablesController extends Controller
*/
public function getDatatable()
{
+ $this->authorize('index', Consumable::class);
$consumables = Company::scopeCompanyables(
Consumable::select('consumables.*')
->whereNull('consumables.deleted_at')
@@ -441,16 +437,16 @@ class ConsumablesController extends Controller
foreach ($consumables as $consumable) {
$actions = '<nobr>';
- if (Gate::allows('consumables.checkout')) {
+ if (Gate::allows('checkout', $consumable)) {
$actions .= '<a href="' . route('checkout/consumable',
$consumable->id) . '" style="margin-right:5px;" class="btn btn-info btn-sm" ' . (($consumable->numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . '</a>';
}
- if (Gate::allows('consumables.edit')) {
+ if (Gate::allows('update', $consumable)) {
$actions .= '<a href="' . route('consumables.edit',
$consumable->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
}
- if (Gate::allows('consumables.delete')) {
+ if (Gate::allows('delete', $consumable)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('consumables.destroy',
$consumable->id) . '" data-content="' . trans('admin/consumables/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($consumable->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
}
@@ -461,14 +457,14 @@ class ConsumablesController extends Controller
$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 @@ class ConsumablesController extends Controller
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 b1039136cd..2f5a868c6f 100755
--- a/app/Http/Controllers/DepreciationsController.php
+++ b/app/Http/Controllers/DepreciationsController.php
@@ -104,14 +104,15 @@ class DepreciationsController extends Controller
/**
- * Validates and stores the updated depreciation data.
- *
- * @author [A. Gianotto] [<[email protected]]
- * @see DepreciationsController::getEdit()
- * @param int $depreciationId
- * @since [v1.0]
- * @return Redirect
- */
+ * Validates and stores the updated depreciation data.
+ *
+ * @author [A. Gianotto] [<[email protected]]
+ * @see DepreciationsController::getEdit()
+ * @param Request $request
+ * @param int $depreciationId
+ * @return Redirect
+ * @since [v1.0]
+ */
public function update(Request $request, $depreciationId = null)
{
// Check if the depreciation exists
@@ -127,7 +128,7 @@ class DepreciationsController extends Controller
// Was the asset created?
if ($depreciation->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 cb87f347e6..de910be04a 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 @@ class LicensesController extends Controller
*/
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 @@ class LicensesController extends Controller
*/
public function store(Request $request)
{
-
+ $this->authorize('create', License::class);
// create a new model instance
$license = new License();
@@ -192,10 +193,10 @@ class LicensesController extends Controller
{
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 @@ class LicensesController extends Controller
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 @@ class LicensesController extends Controller
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 @@ class LicensesController extends Controller
$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 @@ class LicensesController extends Controller
}
-
/**
* 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 @@ class LicensesController extends Controller
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 @@ class LicensesController extends Controller
$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 @@ class LicensesController extends Controller
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 @@ class LicensesController extends Controller
$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 @@ class LicensesController extends Controller
'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 @@ class LicensesController extends Controller
{
$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 @@ class LicensesController extends Controller
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 @@ class LicensesController extends Controller
);
$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 @@ class LicensesController extends Controller
// 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 @@ class LicensesController extends Controller
$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 @@ class LicensesController extends Controller
// 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 @@ class LicensesController extends Controller
*/
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 @@ class LicensesController extends Controller
foreach ($licenses as $license) {
$actions = '<span style="white-space: nowrap;">';
- if (Gate::allows('licenses.checkout')) {
+ if (Gate::allows('checkout', License::class)) {
$actions .= '<a href="' . route('licenses.freecheckout', $license->id)
. '" class="btn btn-primary btn-sm' . (($license->remaincount() > 0) ? '' : ' disabled') . '" style="margin-right:5px;">' . trans('general.checkout') . '</a> ';
}
- if (Gate::allows('licenses.create')) {
+ if (Gate::allows('create', $license)) {
$actions .= '<a href="' . route('clone/license', $license->id)
. '" class="btn btn-info btn-sm" style="margin-right:5px;" title="Clone license"><i class="fa fa-files-o"></i></a>';
}
- if (Gate::allows('licenses.edit')) {
+ if (Gate::allows('update', $license)) {
$actions .= '<a href="' . route('licenses.edit', $license->id)
. '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
}
- if (Gate::allows('licenses.delete')) {
+ if (Gate::allows('delete', $license)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'
. route('licenses.destroy', $license->id)
. '" data-content="' . trans('admin/licenses/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($license->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
@@ -1033,6 +999,7 @@ class LicensesController extends Controller
*/
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 6345c67efd..357ceab074 100755
--- a/app/Http/Controllers/LocationsController.php
+++ b/app/Http/Controllers/LocationsController.php
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
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 @@ class LocationsController extends Controller
/**
- * Returns a JSON response that contains the users association with the
- * selected location, to be used by the location detail view.
- *
- * @author [A. Gianotto] [<[email protected]>]
- * @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] [<[email protected]>]
+ * @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 @@ class LocationsController extends Controller
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 08c9454dbf..ff3f61905b 100755
--- a/app/Http/Controllers/ManufacturersController.php
+++ b/app/Http/Controllers/ManufacturersController.php
@@ -1,9 +1,7 @@
<?php
namespace App\Http\Controllers;
-use App\Models\Company;
use App\Models\Manufacturer;
-use App\Models\Setting;
use Auth;
use Gate;
use Input;
@@ -197,7 +195,7 @@ class ManufacturersController extends Controller
*/
public function getDatatable(Request $request)
{
- $manufacturers = Manufacturer::select(array('id','name'))->with('assets')
+ $manufacturers = Manufacturer::select(array('id','name'))->with('assets', 'licenses', 'accessories', 'consumables')
->whereNull('deleted_at');
if ($request->has('search')) {
@@ -231,9 +229,12 @@ class ManufacturersController extends Controller
$actions = '<a href="'.route('manufacturers.edit', $manufacturer->id).'" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a><a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('manufacturers.destroy', $manufacturer->id).'" data-content="'.trans('admin/manufacturers/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($manufacturer->name).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
$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 @@ class ManufacturersController extends Controller
/**
- * 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] [<[email protected]>]
- * @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] [<[email protected]>]
+ * @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 @@ class ManufacturersController extends Controller
$actions = '';
if ($asset->deleted_at=='') {
- $actions = '<div style=" white-space: nowrap;"><a href="'.route('clone/hardware', $asset->id).'" class="btn btn-info btn-sm" title="Clone asset"><i class="fa fa-files-o"></i></a> <a href="'.route('hardware.edit', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('delete/hardware', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->asset_tag).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
+ $actions = '<div style=" white-space: nowrap;"><a href="'.route('clone/hardware', $asset->id).'" class="btn btn-info btn-sm" title="Clone asset"><i class="fa fa-files-o"></i></a> <a href="'.route('hardware.edit', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> <a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'.route('hardware.destroy', $asset->id).'" data-content="'.trans('admin/hardware/message.delete.confirm').'" data-title="'.trans('general.delete').' '.htmlspecialchars($asset->asset_tag).'?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a></div>';
} elseif ($asset->deleted_at!='') {
$actions = '<a href="'.route('restore/hardware', $asset->id).'" class="btn btn-warning btn-sm"><i class="fa fa-recycle icon-white"></i></a>';
}
if ($asset->availableForCheckout()) {
- if (Gate::allows('assets.checkout')) {
+ if (Gate::allows('checkout', $asset)) {
$inout = '<a href="'.route('checkout/hardware', $asset->id).'" class="btn btn-info btn-sm">'.trans('general.checkout').'</a>';
}
} else {
- if (Gate::allows('assets.checkin')) {
+ if (Gate::allows('checkin', $asset)) {
$inout = '<a href="'.route('checkin/hardware', $asset->id).'" class="btn btn-primary btn-sm">'.trans('general.checkin').'</a>';
}
}
$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 @@ class ManufacturersController extends Controller
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 @@ class ManufacturersController extends Controller
foreach ($licenses as $license) {
$actions = '<span style="white-space: nowrap;">';
- if (Gate::allows('licenses.checkout')) {
+ if (Gate::allows('checkout', \App\Models\License::class)) {
$actions .= '<a href="' . route('licenses.freecheckout', $license->id)
. '" class="btn btn-primary btn-sm' . (($license->remaincount() > 0) ? '' : ' disabled') . '" style="margin-right:5px;">' . trans('general.checkout') . '</a> ';
}
- if (Gate::allows('licenses.create')) {
+ if (Gate::allows('create', $license)) {
$actions .= '<a href="' . route('clone/license', $license->id)
. '" class="btn btn-info btn-sm" style="margin-right:5px;" title="Clone asset"><i class="fa fa-files-o"></i></a>';
}
- if (Gate::allows('licenses.edit')) {
+ if (Gate::allows('edit', $license)) {
$actions .= '<a href="' . route('licenses.edit', ['license' => $license->id])
. '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
}
- if (Gate::allows('licenses.delete')) {
+ if (Gate::allows('delete', $license)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="'
- . route('delete/license', $license->id)
+ . route('licenses.destroy', $license->id)
. '" data-content="' . trans('admin/licenses/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($license->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
}
$actions .='</span>';
$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 @@ class ManufacturersController extends Controller
'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 @@ class ManufacturersController extends Controller
return $data;
}
- public function getDataAccessoriesView(Manufacturer $manufacturer)
+ public function getDataAccessoriesView(Manufacturer $manufacturer, Request $request)
{
$manufacturer = $manufacturer->load(
'accessories.location',
@@ -433,15 +434,15 @@ class ManufacturersController extends Controller
foreach ($accessories as $accessory) {
$actions = '<nobr>';
- if (Gate::allows('accessories.checkout')) {
+ if (Gate::allows('checkout', $accessory)) {
$actions .= '<a href="' . route('checkout/accessory',
$accessory->id) . '" style="margin-right:5px;" class="btn btn-info btn-sm" ' . (($accessory->numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . '</a>';
}
- if (Gate::allows('accessories.edit')) {
+ if (Gate::allows('update', $accessory)) {
$actions .= '<a href="' . route('accessories.update',
$accessory->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
}
- if (Gate::allows('accessories.delete')) {
+ if (Gate::allows('delete', $accessory)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('accessories.destroy',
$accessory->id) . '" data-content="' . trans('admin/accessories/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($accessory->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
}
@@ -449,8 +450,8 @@ class ManufacturersController extends Controller
$company = $accessory->company;
$rows[] = array(
- 'name' => '<a href="'.url('admin/accessories/'.$accessory->id).'/view">'. $accessory->name.'</a>',
- '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 @@ class ManufacturersController extends Controller
'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 @@ class ManufacturersController extends Controller
return $data;
}
- public function getDataConsumablesView($manufacturer)
+ public function getDataConsumablesView($manufacturer, Request $request)
{
$manufacturer = $manufacturer->load(
'consumables.location',
@@ -497,16 +498,16 @@ class ManufacturersController extends Controller
foreach ($consumables as $consumable) {
$actions = '<nobr>';
- if (Gate::allows('consumables.checkout')) {
+ if (Gate::allows('checkout', $consumable)) {
$actions .= '<a href="' . route('checkout/consumable',
$consumable->id) . '" style="margin-right:5px;" class="btn btn-info btn-sm" ' . (($consumable->numRemaining() > 0) ? '' : ' disabled') . '>' . trans('general.checkout') . '</a>';
}
- if (Gate::allows('consumables.edit')) {
+ if (Gate::allows('update', $consumable)) {
$actions .= '<a href="' . route('consumables.edit',
$consumable->id) . '" class="btn btn-warning btn-sm" style="margin-right:5px;"><i class="fa fa-pencil icon-white"></i></a>';
}
- if (Gate::allows('consumables.delete')) {
+ if (Gate::allows('delete', $consumable)) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('consumables.destroy',
$consumable->id) . '" data-content="' . trans('admin/consumables/message.delete.confirm') . '" data-title="' . trans('general.delete') . ' ' . htmlspecialchars($consumable->name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a>';
}
@@ -517,14 +518,14 @@ class ManufacturersController extends Controller
$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 36065cda5d..572cb5a853 100644
--- a/app/Http/Controllers/ReportsController.php
+++ b/app/Http/Controllers/ReportsController.php
@@ -386,7 +386,7 @@ class ReportsController extends Controller
'icon' => '<i class="'.$activity->parseItemIcon().'"></i>',
'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 d3cf45d5b9..378f4b2aee 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 @@ class UsersController extends Controller
*/
public function create()
{
-
+ $this->authorize('create', User::class);
$groups = Group::pluck('name', 'id');
if (Input::old('groups')) {
@@ -104,7 +105,7 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
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 @@ class UsersController extends Controller
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 @@ class UsersController extends Controller
$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 @@ class UsersController extends Controller
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 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
{
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 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
*/
public function getImport()
{
+ $this->authorize('update', User::class);
// Get all the available groups
//$groups = Sentry::getGroupProvider()->findAll();
// Selected groups
@@ -804,7 +777,7 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
$actions = '<nobr>';
foreach ($user->groups as $group) {
- $group_names .= '<a href="' . \url('/') . '/admin/groups/' . $group->id . '/edit" class="label label-default">' . $group->name . '</a> ';
+ $group_names .= '<a href="' . route('update/group', $group->id) . '" class="label label-default">' . $group->name . '</a> ';
}
if (!is_null($user->deleted_at)) {
- if (Gate::allows('users.delete')) {
+ if (Gate::allows('delete', $user)) {
$actions .= '<a href="' . route('restore/user',
$user->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-share icon-white"></i></a> ';
}
} else {
- if (Gate::allows('users.delete')) {
+ if (Gate::allows('delete', $user)) {
if ($user->accountStatus() == 'suspended') {
$actions .= '<a href="' . route('unsuspend/user',
$user->id) . '" class="btn btn-default btn-sm"><span class="fa fa-clock-o"></span></a> ';
}
}
- if (Gate::allows('users.edit')) {
+ if (Gate::allows('update', $user)) {
$actions .= '<a href="' . route('users.edit',
$user->id) . '" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a> ';
$actions .= '<a href="' . route('clone/user',
$user->id) . '" class="btn btn-info btn-sm"><i class="fa fa-clone"></i></a>';
}
- if (Gate::allows('users.delete')) {
+ if (Gate::allows('delete', $user)) {
if ((Auth::user()->id !== $user->id) && (!config('app.lock_passwords'))) {
$actions .= '<a data-html="false" class="btn delete-asset btn-danger btn-sm" data-toggle="modal" href="' . route('users.destroy',
$user->id) . '" data-content="Are you sure you wish to delete this user?" data-title="Delete ' . htmlspecialchars($user->first_name) . '?" onClick="return false;"><i class="fa fa-trash icon-white"></i></a> ';
@@ -1052,15 +1025,11 @@ class UsersController extends Controller
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 @@ class UsersController extends Controller
$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 @@ class UsersController extends Controller
}
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 @@ class UsersController extends Controller
// 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 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
*/
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 @@ class UsersController extends Controller
*/
public function getExportUserCsv()
{
-
+ $this->authorize('view', User::class);
\Debugbar::disable();
diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php
index 40fa9c9190..e0f032912b 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 826aea7057..9669e2ce9b 100644
--- a/app/Models/Asset.php
+++ b/app/Models/Asset.php
@@ -178,7 +178,9 @@ class Asset extends Depreciable
'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 2cc945c41d..3b977ccb78 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 b57e62a15c..aefa882865 100755
--- a/app/Models/Setting.php
+++ b/app/Models/Setting.php
@@ -61,23 +61,15 @@ class Setting extends Model
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 0786d53814..efe3f2ba32 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 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
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 0000000000..8405f14686
--- /dev/null
+++ b/app/Policies/AccessoryPolicy.php
@@ -0,0 +1,119 @@
+<?php
+
+namespace App\Policies;
+
+use App\Models\Accessory;
+use App\Models\Company;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class AccessoryPolicy
+{
+ use HandlesAuthorization;
+
+ public function before(User $user, $ability, $accessory)
+ {
+ // Lets move all company related checks here.
+ if ($accessory instanceof \App\Models\Accessory && !Company::isCurrentUserHasAccess($accessory)) {
+ return false;
+ }
+ // If an admin, they can do all asset related tasks.
+ if ($user->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 0000000000..c4a72e178f
--- /dev/null
+++ b/app/Policies/AssetPolicy.php
@@ -0,0 +1,81 @@
+<?php
+
+namespace App\Policies;
+
+use App\Models\Asset;
+use App\Models\Company;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class AssetPolicy
+{
+ use HandlesAuthorization;
+
+ /**
+ * Create a new policy instance.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ //
+ }
+
+ public function before(User $user, $ability, $asset)
+ {
+ // Lets move all company related checks here.
+ if ($asset instanceof \App\Models\Asset && !Company::isCurrentUserHasAccess($asset)) {
+ return false;
+ }
+ // If an admin, they can do all asset related tasks.
+ if ($user->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 0000000000..5b138d0a5c
--- /dev/null
+++ b/app/Policies/ComponentPolicy.php
@@ -0,0 +1,114 @@
+<?php
+
+namespace App\Policies;
+
+use App\Models\Company;
+use App\Models\Component;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class ComponentPolicy
+{
+ use HandlesAuthorization;
+
+
+ public function before(User $user, $ability, $component)
+ {
+ // Lets move all company related checks here.
+ if ($component instanceof \App\Models\Component && !Company::isCurrentUserHasAccess($component)) {
+ return false;
+ }
+ // If an admin, they can do all asset related tasks.
+ if ($user->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 0000000000..d6f6408452
--- /dev/null
+++ b/app/Policies/ConsumablePolicy.php
@@ -0,0 +1,119 @@
+<?php
+
+namespace App\Policies;
+
+use App\Models\Company;
+use App\Models\Consumable;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class ConsumablePolicy
+{
+ use HandlesAuthorization;
+
+
+ public function before(User $user, $ability, $consumable)
+ {
+ // Lets move all company related checks here.
+ if ($consumable instanceof \App\Models\Consumable && !Company::isCurrentUserHasAccess($consumable)) {
+ return false;
+ }
+ // If an admin, they can do all asset related tasks.
+ if ($user->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 0000000000..b6c7d95760
--- /dev/null
+++ b/app/Policies/LicensePolicy.php
@@ -0,0 +1,127 @@
+<?php
+
+namespace App\Policies;
+
+use App\Models\Company;
+use App\Models\License;
+use App\Models\LicenseSeat;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class LicensePolicy
+{
+ use HandlesAuthorization;
+
+
+ public function before(User $user, $ability, $license)
+ {
+ // Lets move all company related checks here.
+ if ($license instanceof \App\Models\License && !Company::isCurrentUserHasAccess($license)) {
+ return false;
+ }
+ // If an admin, they can do all asset related tasks.
+ if ($user->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 0000000000..77c1049288
--- /dev/null
+++ b/app/Policies/UserPolicy.php
@@ -0,0 +1,90 @@
+<?php
+
+namespace App\Policies;
+
+use App\Models\Company;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+use Illuminate\Support\Facades\Auth;
+
+class UserPolicy
+{
+ use HandlesAuthorization;
+
+
+ public function before(User $user, $ability, $targetUser)
+ {
+ // Lets move all company related checks here.
+ if ($targetUser instanceof \App\Models\User && !Company::isCurrentUserHasAccess($targetUser)) {
+ return false;
+ }
+ // If an admin, they can do all asset related tasks.
+ if ($user->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 9c01223f20..d76ffa486d 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 @@ class AuthServiceProvider extends ServiceProvider
{
$this->registerPolicies();
Passport::routes();
-
// --------------------------------
// BEFORE ANYTHING ELSE
// --------------------------------
@@ -60,271 +74,6 @@ class AuthServiceProvider extends ServiceProvider
}
});
-
- # -----------------------------------------
- # 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 @@ class AuthServiceProvider extends ServiceProvider
return true;
}
});
-
-
-
}
}
diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php
index 2f621abc07..aa929d56b3 100644
--- a/database/factories/ModelFactory.php
+++ b/database/factories/ModelFactory.php
@@ -17,393 +17,379 @@ use App\Models\Manufacturer;
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 0000000000..c0b628e80c
--- /dev/null
+++ b/database/factories/UserFactory.php
@@ -0,0 +1,249 @@
+<?php
+
+use App\Models\Company;
+
+$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,
+ '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 0000000000..ef31f4080e
--- /dev/null
+++ b/database/migrations/2016_12_19_004212_adjust_locale_length_to_10.php
@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class AdjustLocaleLengthTo10 extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('users', function (Blueprint $table) {
+ //
+ $table->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 c8059ba031..592b0b8dc5 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)
<a href="{{ route('accessories.create') }}" class="btn btn-primary pull-right"> {{ trans('general.create') }}</a>
@endcan
@stop
diff --git a/resources/views/accessories/view.blade.php b/resources/views/accessories/view.blade.php
index 3518f7ff62..947047c539 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)
<div class="dropdown pull-right">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">{{ trans('button.actions') }}
<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-right" role="menu" aria-labelledby="dropdownMenu1">
@if ($accessory->assigned_to != '')
- @can('accessories.checkin')
+ @can('checkin', \App\Models\Accessory::class)
<li role="presentation"><a href="{{ route('checkin/accessory', $accessory->id) }}">{{ trans('admin/accessories/general.checkin') }}</a></li>
@endcan
@else
- @can('accessories.checkout')
+ @can('checkout', \App\Models\Accessory::class)
<li role="presentation"><a href="{{ route('checkout/accessory', $accessory->id) }}">{{ trans('admin/accessories/general.checkout') }}</a></li>
@endcan
@endif
- @can('accessories.edit')
+ @can('update', \App\Models\Accessory::class)
<li role="presentation"><a href="{{ route('accessories.edit', $accessory->id) }}">{{ trans('admin/accessories/general.edit') }}</a></li>
@endcan
@@ -76,7 +76,7 @@
<h4>{{ trans('admin/accessories/general.about_accessories_title') }}</h4>
<p>{{ trans('admin/accessories/general.about_accessories_text') }} </p>
<div class="text-center">
- @can('accessories.checkout')
+ @can('checkout', \App\Models\Accessory::class)
<a href="{{ route('checkout/accessory', $accessory->id) }}" style="margin-right:5px;" class="btn btn-info btn-sm" {{ (($accessory->numRemaining() > 0 ) ? '' : ' disabled') }}>{{ trans('general.checkout') }}</a>
@endcan
</div>
diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php
index d1c8b3c975..5210e60837 100755
--- a/resources/views/account/view-assets.blade.php
+++ b/resources/views/account/view-assets.blade.php
@@ -102,7 +102,7 @@ View Assets for {{ $user->fullName() }}
<td>{{ $license->name }}</td>
<td>
- @can('licenses.keys')
+ @can('viewKeys', $license)
{{ mb_strimwidth($license->serial, 0, 50, "...") }}
@else
diff --git a/resources/views/asset_maintenances/index.blade.php b/resources/views/asset_maintenances/index.blade.php
index a270c9430a..6a5c7cf3ef 100644
--- a/resources/views/asset_maintenances/index.blade.php
+++ b/resources/views/asset_maintenances/index.blade.php
@@ -8,8 +8,8 @@
@section('header_right')
- @can('assets.edit')
-<a href="{{ route('maintenances.create') }}" class="btn btn-primary pull-right"> {{ trans('general.create') }}</a>
+ @can('update', \App\Models\Asset::class)
+ <a href="{{ route('maintenances.create') }}" class="btn btn-primary pull-right"> {{ trans('general.create') }}</a>
@endcan
@stop
@@ -47,7 +47,7 @@
<th data-searchable="true" data-sortable="true" data-field="cost" class="text-right">{{ trans('admin/asset_maintenances/form.cost') }}</th>
<th data-searchable="true" data-sortable="true" data-field="user_id">{{ trans('general.admin') }}</th>
<th data-searchable="true" data-sortable="true" data-field="notes" data-visible="false">{{ trans('admin/asset_maintenances/form.notes') }}</th>
- @can('assets.edit')
+ @can('update', \App\Models\Asset::class)
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>
@endcan
</tr>
diff --git a/resources/views/asset_maintenances/view.blade.php b/resources/views/asset_maintenances/view.blade.php
index 8052c9abe2..4044dfea1b 100644
--- a/resources/views/asset_maintenances/view.blade.php
+++ b/resources/views/asset_maintenances/view.blade.php
@@ -25,7 +25,7 @@ use Carbon\Carbon;
<span class="caret"></span>
</button>
<ul class="dropdown-menu pull-right" role="menu" aria-labelledby="dropdownMenu1">
- <li role="presentation"><a href="{{ route('update/asset_maintenance', $assetMaintenance->id) }}">{{ trans('admin/asset_maintenances/general.edit') }}</a></li>
+ <li role="presentation"><a href="{{ route('maintenances.update', $assetMaintenance->id) }}">{{ trans('admin/asset_maintenances/general.edit') }}</a></li>
</ul>
</div>
</div>
diff --git a/resources/views/components/index.blade.php b/resources/views/components/index.blade.php
index 2421ab44f0..1bb5c3f2c2 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)
<a href="{{ route('components.create') }}" class="btn btn-primary pull-right"> {{ trans('general.create') }}</a>
@endcan
@stop
diff --git a/resources/views/components/view.blade.php b/resources/views/components/view.blade.php
index ea995aca98..a8f6307039 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')
-<div class="dropdown pull-right">
- <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">{{ trans('button.actions') }}
- <span class="caret"></span>
- </button>
- <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="dropdownMenu1">
- @if ($component->assigned_to != '')
- @can('components.checkin')
- <li role="presentation"><a href="{{ route('checkin/component', $component->id) }}">{{ trans('admin/components/general.checkin') }}</a></li>
- @endcan
- @else
- @can('components.checkout')
- <li role="presentation"><a href="{{ route('checkout/component', $component->id) }}">{{ trans('admin/components/general.checkout') }}</a></li>
- @endcan
- @endif
- @can('components.edit')
- <li role="presentation"><a href="{{ route('components.edit', $component->id) }}">{{ trans('admin/components/general.edit') }}</a></li>
- @endcan
-
- </ul>
-</div>
+ @can('manage', $component)
+ <div class="dropdown pull-right">
+ <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">{{ trans('button.actions') }}
+ <span class="caret"></span>
+ </button>
+ <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="dropdownMenu1">
+ @if ($component->assigned_to != '')
+ @can('checkin', $component)
+ <li role="presentation"><a href="{{ route('checkin/component', $component->id) }}">{{ trans('admin/components/general.checkin') }}</a></li>
+ @endcan
+ @else
+ @can('checkout', $component)
+ <li role="presentation"><a href="{{ route('checkout/component', $component->id) }}">{{ trans('admin/components/general.checkout') }}</a></li>
+ @endcan
+ @endif
+ @can('update', $component)
+ <li role="presentation"><a href="{{ route('components.edit', $component->id) }}">{{ trans('admin/components/general.edit') }}</a></li>
+ @endcan
+
+ </ul>
+ </div>
@endcan
@stop
diff --git a/resources/views/consumables/index.blade.php b/resources/views/consumables/index.blade.php
index c3a4f6e4ef..25caca4c36 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)
<a href="{{ route('consumables.create') }}" class="btn btn-primary pull-right"> {{ trans('general.create') }}</a>
@endcan
@stop
diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php
index 5a147aba7a..d855ebf879 100755
--- a/resources/views/dashboard.blade.php
+++ b/resources/views/dashboard.blade.php
@@ -24,7 +24,7 @@
<div class="icon">
<i class="fa fa-barcode"></i>
</div>
- @can('assets.view')
+ @can('index', \App\Models\Asset::class)
<a href="{{ route('hardware.index') }}" class="small-box-footer">{{ trans('general.moreinfo') }} <i class="fa fa-arrow-circle-right"></i></a>
@endcan
</div>
@@ -40,7 +40,7 @@
<div class="icon">
<i class="fa fa-floppy-o"></i>
</div>
- @can('licenses.view')
+ @can('view', \App\Models\License::class)
<a href="{{ route('licenses.index') }}" class="small-box-footer">{{ trans('general.moreinfo') }} <i class="fa fa-arrow-circle-right"></i></a>
@endcan
</div>
@@ -56,7 +56,7 @@
<div class="icon">
<i class="fa fa-keyboard-o"></i>
</div>
- @can('accessories.view')
+ @can('index', \App\Models\Accessory::class)
<a href="{{ route('accessories.index') }}" class="small-box-footer">{{ trans('general.moreinfo') }} <i class="fa fa-arrow-circle-right"></i></a>
@endcan
</div>
@@ -72,7 +72,7 @@
<div class="icon">
<i class="fa fa-tint"></i>
</div>
- @can('consumables.view')
+ @can('index', \App\Models\Consumable::class)
<a href="{{ route('consumables.index') }}" class="small-box-footer">{{ trans('general.moreinfo') }} <i class="fa fa-arrow-circle-right"></i></a>
@endcan
</div>
diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php
index 4a1ef8251f..77d04615a9 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')
-<div class="dropdown pull-right">
- <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">{{ trans('button.actions') }}
- <span class="caret"></span>
- </button>
- <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="dropdownMenu1">
- @if ($asset->assetstatus->deployable=='1')
- @if ($asset->assigned_to != '')
- <li role="presentation"><a href="{{ route('checkin/hardware', $asset->id) }}">{{ trans('admin/hardware/general.checkin') }}</a></li>
- @else
- <li role="presentation"><a href="{{ route('checkout/hardware', $asset->id) }}">{{ trans('admin/hardware/general.checkout') }}</a></li>
- @endif
- @endif
- <li role="presentation"><a href="{{ route('hardware.edit', $asset->id) }}">{{ trans('admin/hardware/general.edit') }}</a></li>
- <li role="presentation"><a href="{{ route('clone/hardware', $asset->id) }}">{{ trans('admin/hardware/general.clone') }}</a></li>
- </ul>
-</div>
+ @can('manage', \App\Models\Asset::class)
+ <div class="dropdown pull-right">
+ <button class="btn btn-default dropdown-toggle" data-toggle="dropdown">{{ trans('button.actions') }}
+ <span class="caret"></span>
+ </button>
+ <ul class="dropdown-menu pull-right" role="menu" aria-labelledby="dropdownMenu1">
+ @if ($asset->assetstatus->deployable=='1')
+ @if ($asset->assigned_to != '')
+ <li role="presentation"><a href="{{ route('checkin/hardware', $asset->id) }}">{{ trans('admin/hardware/general.checkin') }}</a></li>
+ @else
+ <li role="presentation"><a href="{{ route('checkout/hardware', $asset->id) }}">{{ trans('admin/hardware/general.checkout') }}</a></li>
+ @endif
+ @endif
+ <li role="presentation"><a href="{{ route('hardware.edit', $asset->id) }}">{{ trans('admin/hardware/general.edit') }}</a></li>
+ <li role="presentation"><a href="{{ route('clone/hardware', $asset->id) }}">{{ trans('admin/hardware/general.clone') }}</a></li>
+ </ul>
+ </div>
@endcan
@stop
@@ -496,10 +496,10 @@
<div class="tab-pane fade" id="maintenances">
<div class="row">
<div class="col-md-12">
- @can('assets.edit')
- <h6>{{ trans('general.asset_maintenances') }}
- [ <a href="{{ route('maintenances.create', $asset->id) }}">{{ trans('button.add') }}</a> ]
- </h6>
+ @can('update', \App\Models\Asset::class)
+ <h6>{{ trans('general.asset_maintenances') }}
+ [ <a href="{{ route('maintenances.edit', ['asset_id'=>$asset->id]) }}">{{ trans('button.add') }}</a> ]
+ </h6>
@endcan
<!-- Asset Maintenance table -->
@@ -516,7 +516,7 @@
<th>{{ trans('admin/asset_maintenances/table.is_warranty') }}</th>
<th>{{ trans('admin/asset_maintenances/form.cost') }}</th>
<th>{{ trans('general.admin') }}</th>
- @can('assets.edit')
+ @can('update', \App\Models\Asset::class)
<th>{{ trans('table.actions') }}</th>
@endcan
</tr>
@@ -537,14 +537,14 @@
<td class="text-right"><nobr>{{ $use_currency.$assetMaintenance->cost }}</nobr></td>
<td>
@if ($assetMaintenance->admin)
- <a href="{{ url('/') }}/admin/users/{{ $assetMaintenance->admin->id }}/view">{{ $assetMaintenance->admin->fullName() }}</a>
+ <a href="{{ route('users.show', $assetMaintenance->admin->id) }}">{{ $assetMaintenance->admin->fullName() }}</a>
@endif
</td>
<?php $totalCost += $assetMaintenance->cost; ?>
- @can('assets.edit')
- <td>
- <a href="{{ route('update/asset_maintenance', $assetMaintenance->id) }}" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a>
- </td>
+ @can('update', \App\Models\Asset::class)
+ <td>
+ <a href="{{ route('maintenances.edit', $assetMaintenance->id) }}" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a>
+ </td>
@endcan
</tr>
@endif
@@ -671,31 +671,31 @@
<div class="tab-pane fade" id="files">
<div class="row">
- @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' ]) }}
- <div class="col-md-2">
- <span class="btn btn-default btn-file">Browse for file...
- {{ Form::file('assetfile[]', ['multiple' => 'multiple']) }}
- </span>
- </div>
- <div class="col-md-7">
- {{ Form::text('notes', Input::old('notes', Input::old('notes')), array('class' => 'form-control','placeholder' => 'Notes')) }}
- </div>
- <div class="col-md-3">
- <button type="submit" class="btn btn-primary">{{ trans('button.upload') }}</button>
- </div>
+ <div class="col-md-2">
+ <span class="btn btn-default btn-file">Browse for file...
+ {{ Form::file('assetfile[]', ['multiple' => 'multiple']) }}
+ </span>
+ </div>
+ <div class="col-md-7">
+ {{ Form::text('notes', Input::old('notes', Input::old('notes')), array('class' => 'form-control','placeholder' => 'Notes')) }}
+ </div>
+ <div class="col-md-3">
+ <button type="submit" class="btn btn-primary">{{ trans('button.upload') }}</button>
+ </div>
- <div class="col-md-12">
- <p>{{ trans('admin/hardware/general.filetype_info') }}</p>
- <hr>
- </div>
+ <div class="col-md-12">
+ <p>{{ trans('admin/hardware/general.filetype_info') }}</p>
+ <hr>
+ </div>
- {{ Form::close() }}
- @endcan
+ {{ Form::close() }}
+ @endcan
<div class="col-md-12">
@@ -732,8 +732,8 @@
@endif
</td>
<td>
- @can('assets.edit')
- <a class="btn delete-asset btn-danger btn-sm" href="{{ route('delete/assetfile', [$asset->id, $file->id]) }}"><i class="fa fa-trash icon-white"></i></a>
+ @can('update', \App\Models\Asset::class)
+ <a class="btn delete-asset btn-danger btn-sm" href="{{ route('delete/assetfile', [$asset->id, $file->id]) }}"><i class="fa fa-trash icon-white"></i></a>
@endcan
</td>
</tr>
diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php
index 723abbc62a..4cfe42fd4f 100644
--- a/resources/views/layouts/default.blade.php
+++ b/resources/views/layouts/default.blade.php
@@ -128,35 +128,35 @@
<!-- Navbar Right Menu -->
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
- @can('assets.view')
+ @can('index', \App\Models\Asset::class)
<li {!! (Request::is('hardware*') ? ' class="active"' : '') !!}>
<a href="{{ url('hardware') }}">
<i class="fa fa-barcode"></i>
</a>
</li>
@endcan
- @can('licenses.view')
+ @can('view', \App\Models\License::class)
<li {!! (Request::is('licenses*') ? ' class="active"' : '') !!}>
<a href="{{ route('licenses.index') }}">
<i class="fa fa-floppy-o"></i>
</a>
</li>
@endcan
- @can('accessories.view')
+ @can('index', \App\Models\Accessory::class)
<li {!! (Request::is('accessories*') ? ' class="active"' : '') !!}>
<a href="{{ route('accessories.index') }}">
<i class="fa fa-keyboard-o"></i>
</a>
</li>
@endcan
- @can('consumables.view')
+ @can('index', \App\Models\Consumable::class)
<li {!! (Request::is('consunmables*') ? ' class="active"' : '') !!}>
<a href="{{ url('consumables') }}">
<i class="fa fa-tint"></i>
</a>
</li>
@endcan
- @can('components.view')
+ @can('view', \App\Models\Component::class)
<li {!! (Request::is('components*') ? ' class="active"' : '') !!}>
<a href="{{ route('components.index') }}">
<i class="fa fa-hdd-o"></i>
@@ -164,7 +164,7 @@
</li>
@endcan
- @can('assets.view')
+ @can('index', \App\Models\Asset::class)
<form class="navbar-form navbar-left form-horizontal" role="search" action="{{ route('findbytag/hardware') }}" method="get">
<div class="col-xs-12 col-md-12">
<div class="col-xs-12 form-group">
@@ -186,42 +186,42 @@
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
- @can('assets.create')
+ @can('create', \App\Models\Asset::class)
<li {!! (Request::is('hardware/create') ? 'class="active>"' : '') !!}>
<a href="{{ route('hardware.create') }}">
<i class="fa fa-barcode fa-fw"></i>
@lang('general.asset')</a>
</li>
@endcan
- @can('licenses.create')
+ @can('create', \App\Models\License::class)
<li {!! (Request::is('licenses/create') ? 'class="active"' : '') !!}>
<a href="{{ route('licenses.create') }}">
<i class="fa fa-floppy-o fa-fw"></i>
@lang('general.license')</a>
</li>
@endcan
- @can('accessories.create')
+ @can('create', \App\Models\Accessory::class)
<li {!! (Request::is('accessories/create') ? 'class="active"' : '') !!}>
<a href="{{ route('accessories.create') }}">
<i class="fa fa-keyboard-o fa-fw"></i>
@lang('general.accessory')</a>
</li>
@endcan
- @can('consumables.create')
+ @can('create', \App\Models\Consumable::class)
<li {!! (Request::is('consunmables/create') ? 'class="active"' : '') !!}>
<a href="{{ route('consumables.create') }}">
<i class="fa fa-tint fa-fw"></i>
@lang('general.consumable')</a>
</li>
@endcan
- @can('users.create')
+ @can('create', \App\Models\User::class)
<li {!! (Request::is('users/create') ? 'class="active"' : '') !!}>
<a href="{{ route('users.create') }}">
<i class="fa fa-user fa-fw"></i>
@lang('general.user')</a>
</li>
@endcan
- @can('components.create')
+ @can('create', \App\Models\Component::class)
<li {!! (Request::is('components/create') ? 'class="active"' : '') !!}>
<a href="{{ route('components.create') }}">
<i class="fa fa-hdd-o"></i>
@@ -403,7 +403,7 @@
</a>
</li>
@endcan
- @can('assets.view')
+ @can('index', \App\Models\Asset::class)
<li class="treeview{{ (Request::is('hardware*') ? ' active' : '') }}">
<a href="#"><i class="fa fa-barcode"></i>
<span>{{ trans('general.assets') }}</span>
@@ -437,7 +437,7 @@
<li{!! (Request::query('status') == 'Requestable' ? ' class="active"' : '') !!}><a href="{{ url('hardware?status=Requestable') }}">@lang('admin/hardware/general.requestable')</a></li>
<li class="divider">&nbsp;</li>
- @can('assets.checkout')
+ @can('checkout', \App\Models\Asset::class)
<li{!! (Request::is('hardware/bulkcheckout') ? ' class="active>"' : '') !!}>
<a href="{{ route('hardware/bulkcheckout') }}">
{{ trans('general.bulk_checkout') }}</a>
@@ -448,7 +448,7 @@
<li{!! (Request::is('hardware/models*') ? ' class="active"' : '') !!}><a href="{{ route('models.index') }}">@lang('general.asset_models')</a></li>
<li><a href="{{ url('admin/settings/categories') }}" {!! (Request::is('settings/categories*') ? ' class="active"' : '') !!} >@lang('general.categories')</a></li>
@endcan
- @can('assets.create')
+ @can('create', \App\Models\Asset::class)
<li{!! (Request::query('Deleted') ? ' class="active"' : '') !!}><a href="{{ url('hardware?status=Deleted') }}">@lang('general.deleted')</a></li>
<li><a href="{{ route('maintenances.index') }}">@lang('general.asset_maintenances') </a></li>
<li><a href="{{ url('hardware/import') }}">@lang('general.import') </a></li>
@@ -457,7 +457,7 @@
</ul>
</li>
@endcan
- @can('licenses.view')
+ @can('view', \App\Models\License::class)
<li{!! (Request::is('licenses*') ? ' class="active"' : '') !!}>
<a href="{{ route('licenses.index') }}">
<i class="fa fa-floppy-o"></i>
@@ -465,7 +465,7 @@
</a>
</li>
@endcan
- @can('accessories.view')
+ @can('index', \App\Models\Accessory::class)
<li{!! (Request::is('accessories*') ? ' class="active"' : '') !!}>
<a href="{{ route('accessories.index') }}">
<i class="fa fa-keyboard-o"></i>
@@ -473,7 +473,7 @@
</a>
</li>
@endcan
- @can('consumables.view')
+ @can('index', \App\Models\Consumable::class)
<li{!! (Request::is('consunmables*') ? ' class="active"' : '') !!}>
<a href="{{ url('consumables') }}">
<i class="fa fa-tint"></i>
@@ -481,7 +481,7 @@
</a>
</li>
@endcan
- @can('components.view')
+ @can('view', \App\Models\Components::class)
<li{!! (Request::is('components*') ? ' class="active"' : '') !!}>
<a href="{{ route('components.index') }}">
<i class="fa fa-hdd-o"></i>
@@ -489,7 +489,7 @@
</a>
</li>
@endcan
- @can('users.view')
+ @can('view', \App\Models\User::class)
<li{!! (Request::is('users*') ? ' class="active"' : '') !!}>
<a href="{{ route('users.index') }}">
<i class="fa fa-users"></i>
@@ -518,7 +518,7 @@
</ul>
</li>
@endcan
- @can('assets.view.requestable')
+ @can('viewRequestable', \App\Models\Asset::class)
<li{!! (Request::is('account/requestable-assets') ? ' class="active"' : '') !!}>
<a href="{{ route('requestable-assets') }}">
<i class="fa fa-laptop"></i>
diff --git a/resources/views/licenses/index.blade.php b/resources/views/licenses/index.blade.php
index bf8b965f33..cfbea498ba 100755
--- a/resources/views/licenses/index.blade.php
+++ b/resources/views/licenses/index.blade.php
@@ -8,7 +8,7 @@
@section('header_right')
-@can('licenses.create')
+@can('create', \App\Models\License::class)
<a href="{{ route('licenses.create') }}" class="btn btn-primary pull-right">
{{ trans('general.create') }}
</a>
diff --git a/resources/views/licenses/view.blade.php b/resources/views/licenses/view.blade.php
index fb608ecd12..57e7732c6f 100755
--- a/resources/views/licenses/view.blade.php
+++ b/resources/views/licenses/view.blade.php
@@ -10,7 +10,7 @@
{{-- Right header --}}
@section('header_right')
<div class="btn-group pull-right">
- @can('licenses.edit')
+ @can('update', $license)
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">{{ trans('button.actions') }}
<span class="caret"></span>
</button>
@@ -88,7 +88,7 @@
</td>
<td>
@if ($licensedto->asset_id)
- @can('assets.view')
+ @can('view', $licensedto->asset)
<a href="{{ route('hardware.show', $licensedto->asset_id) }}">
{{ $licensedto->asset->name }} {{ $licensedto->asset->asset_tag }}
</a>
@@ -99,7 +99,7 @@
@endif
</td>
<td>
- @can('licenses.checkout')
+ @can('checkout', $licensedto)
@if (($licensedto->assigned_to) || ($licensedto->asset_id))
@if ($license->reassignable)
@@ -144,7 +144,7 @@
</tr>
@endif
- @can('licenses.keys')
+ @can('viewKeys', $license)
@if (!is_null($license->serial))
<tr>
<td>{{ trans('admin/licenses/form.license_key') }}</td>
diff --git a/resources/views/manufacturers/index.blade.php b/resources/views/manufacturers/index.blade.php
index d453eebb2d..97f6c94240 100755
--- a/resources/views/manufacturers/index.blade.php
+++ b/resources/views/manufacturers/index.blade.php
@@ -34,6 +34,9 @@
<th data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
<th data-sortable="true" data-field="name">{{ trans('admin/manufacturers/table.name') }}</th>
<th data-switchable="true" data-searchable="false" data-sortable="false" data-field="assets">{{ trans('general.assets') }}</th>
+ <th data-switchable="true" data-searchable="false" data-sortable="false" data-field="licenses">{{ trans('general.licenses') }}</th>
+ <th data-switchable="true" data-searchable="false" data-sortable="false" data-field="accessories">{{ trans('general.accessories') }}</th>
+ <th data-switchable="true" data-searchable="false" data-sortable="false" data-field="consumables">{{ trans('general.consumables') }}</th>
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions">{{ trans('table.actions') }}</th>
</tr>
</thead>
diff --git a/resources/views/manufacturers/view.blade.php b/resources/views/manufacturers/view.blade.php
index 04f077b13f..6148abebaa 100644
--- a/resources/views/manufacturers/view.blade.php
+++ b/resources/views/manufacturers/view.blade.php
@@ -110,7 +110,7 @@
data-url="{{ route('api.manufacturers.view', ['manufacturerId' => $manufacturer->id, 'itemtype' => 'accessories']) }}"
data-cookie="true"
data-click-to-select="true"
- data-cookie-id-table="maufacturerLicensesTable-{{config('version.hash_version') }}"
+ data-cookie-id-table="manufacturerAccessoriesTable-{{config('version.hash_version') }}"
>
<thead>
<tr>
@@ -121,7 +121,7 @@
<th data-searchable="true" data-sortable="true" data-field="location">{{ trans('general.location') }}</th>
<th data-searchable="false" data-sortable="false" data-field="qty">{{ trans('admin/accessories/general.total') }}</th>
<th data-searchable="true" data-sortable="true" data-field="purchase_date" data-visible="false">{{ trans('admin/accessories/general.date') }}</th>
- <th data-searchable="true" data-sortable="true" data-field="purchase_cost">{{ trans('admin/accessories/general.cost') }}</th>
+ <th data-searchable="true" data-sortable="true" data-field="purchase_cost">{{ trans('general.purchase_cost') }}</th>
<th data-searchable="true" data-sortable="true" data-field="order_number" data-visible="false">{{ trans('admin/accessories/general.order') }}</th>
<th data-searchable="false" data-sortable="true" data-field="min_amt">{{ trans('general.min_amt') }}</th>
<th data-searchable="false" data-sortable="false" data-field="numRemaining">{{ trans('admin/accessories/general.remaining') }}</th>
@@ -155,7 +155,7 @@
<th data-sortable="true" data-field="item_no" data-visible="false">{{ trans('admin/consumables/general.item_no') }}</th>
<th data-sortable="true" data-searchable="true" data-field="order_number" data-visible="false">{{ trans('admin/consumables/general.order') }}</th>
<th data-sortable="true" data-searchable="true" data-field="purchase_date" data-visible="false">{{ trans('admin/consumables/general.date') }}</th>
- <th data-sortable="true" data-searchable="true" data-field="purchase_cost" data-visible="false">{{ trans('admin/consumables/general.cost') }}</th>
+ <th data-sortable="true" data-searchable="true" data-field="purchase_cost" data-visible="false">{{ trans('general.purchase_cost') }}</th>
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions"> {{ trans('table.actions') }}</th>
</tr>
</thead>
diff --git a/resources/views/models/view.blade.php b/resources/views/models/view.blade.php
index fb78123d57..ac3f6913d6 100755
--- a/resources/views/models/view.blade.php
+++ b/resources/views/models/view.blade.php
@@ -98,7 +98,7 @@
@if ($model->fieldset)
<li>{{ trans('admin/models/general.fieldset') }}:
- <a href="{{ url('/') }}/admin/custom_fields/{{ $model->fieldset->id }}">{{ $model->fieldset->name }}</a>
+ <a href="{{ route('fieldsets.show', $model->fieldset->id) }}">{{ $model->fieldset->name }}</a>
</li>
@endif
diff --git a/resources/views/reports/unaccepted_assets.blade.php b/resources/views/reports/unaccepted_assets.blade.php
index a889275226..006266b7c3 100644
--- a/resources/views/reports/unaccepted_assets.blade.php
+++ b/resources/views/reports/unaccepted_assets.blade.php
@@ -41,9 +41,9 @@
<td>{{ is_null($assetItem->company) ? '' : $assetItem->company->name }}</td>
<td>{{ $assetItem->model->category->name }}</td>
<td>{{ $assetItem->model->name }}</td>
- <td>{{ link_to(url('/').'/hardware/'.$assetItem->id.'/view',$assetItem->showAssetName()) }}</td>
+ <td>{{ link_to_route('hardware.show',$assetItem->showAssetName(), [$assetItem->id]) }}</td>
<td>{{ $assetItem->asset_tag }}</td>
- <td>{{ link_to(url('/').'/admin/users/'.$assetItem->assigned_to.'/view', $assetItem->assigneduser->fullName())}}</td>
+ <td>{{ link_to_route('users.show', $assetItem->assigneduser->fullName(), [$assetItem->assigned_to])}}</td>
</tr>
@endforeach
@endif
diff --git a/resources/views/suppliers/view.blade.php b/resources/views/suppliers/view.blade.php
index 44572141f4..0a8e594113 100755
--- a/resources/views/suppliers/view.blade.php
+++ b/resources/views/suppliers/view.blade.php
@@ -203,7 +203,7 @@
<td>{{ $improvement->is_warranty ? trans('admin/asset_maintenances/message.warranty') : trans('admin/asset_maintenances/message.not_warranty') }}</td>
<td>{{ sprintf( trans( 'general.currency' ) . '%01.2f', $improvement->cost) }}</td>
<?php $totalCost += $improvement->cost; ?>
- <td><a href="{{ route('update/asset_maintenance', $improvement->id) }}" class="btn btn-warning"><i class="fa fa-pencil icon-white"></i></a>
+ <td><a href="{{ route('maintenances.edit', $improvement->id) }}" class="btn btn-warning"><i class="fa fa-pencil icon-white"></i></a>
</td>
</tr>
@endif
diff --git a/resources/views/users/confirm-bulk-delete.blade.php b/resources/views/users/confirm-bulk-delete.blade.php
index fa55f369bd..5bdcb0911a 100644
--- a/resources/views/users/confirm-bulk-delete.blade.php
+++ b/resources/views/users/confirm-bulk-delete.blade.php
@@ -82,7 +82,7 @@ Bulk Checkin &amp; Delete
</td>
<td>
@foreach ($user->groups as $group)
- <a href=" {{ url('/') }}/admin/groups/{{ $group->id }}'/edit" class="label label-default">
+ <a href=" {{ route('update/group', $group->id) }}" class="label label-default">
{{ $group->name }}
</a>
@endforeach
diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php
index 32a30fb0ba..cc81d3b44b 100755
--- a/resources/views/users/edit.blade.php
+++ b/resources/views/users/edit.blade.php
@@ -75,7 +75,9 @@
<form class="form-horizontal" method="post" autocomplete="off" action="{{ ($user) ? route('users.update', ['user' => $user->id]) : route('users.store') }}" id="userForm">
<!-- CSRF Token -->
<input type="hidden" name="_token" value="{{ csrf_token() }}">
-
+@if($user->id)
+ {{ method_field('PUT') }}
+@endif
<!-- Custom Tabs -->
<div class="nav-tabs-custom">
<ul class="nav nav-tabs">
diff --git a/resources/views/users/index.blade.php b/resources/views/users/index.blade.php
index 2ed03231a8..9c6a018c39 100755
--- a/resources/views/users/index.blade.php
+++ b/resources/views/users/index.blade.php
@@ -15,7 +15,7 @@
@stop
@section('header_right')
- @can('users.create')
+ @can('create', \App\Models\User::class)
@if ($snipeSettings->ldap_enabled == 1)
<a href="{{ route('ldap/user') }}" class="btn btn-default pull-right"><span class="fa fa-upload"></span> LDAP</a>
@endif
@@ -28,7 +28,7 @@
@else
<a class="btn btn-default pull-right" href="{{ route('users.index', ['status' => 'deleted']) }}" style="margin-right: 5px;">{{ trans('admin/users/table.show_deleted') }}</a>
@endif
- @can('users.view')
+ @can('view', \App\Models\User::class)
<a class="btn btn-default pull-right" href="{{ url('admin/users/export') }}" style="margin-right: 5px;">Export</a>
@endcan
@@ -50,7 +50,7 @@
'class' => 'form-inline' ]) }}
@if (Input::get('status')!='deleted')
- @can('users.delete')
+ @can('delete', \App\Models\User::class)
<div id="toolbar">
<select name="bulk_actions" class="form-control select2" style="width: 200px;">
<option value="delete">Bulk Checkin &amp; Delete</option>
diff --git a/resources/views/users/view.blade.php b/resources/views/users/view.blade.php
index b2daefb14f..b5503168b2 100755
--- a/resources/views/users/view.blade.php
+++ b/resources/views/users/view.blade.php
@@ -23,21 +23,21 @@
<li><a href="#files_tab" data-toggle="tab"><span class="hidden-lg hidden-md"><i class="fa fa-paperclip"></i></span> <span class="hidden-xs hidden-sm">{{ trans('general.file_uploads') }}</span></a></li>
<li><a href="#history_tab" data-toggle="tab"><span class="hidden-lg hidden-md"><i class="fa fa-clock-o"></i></span> <span class="hidden-xs hidden-sm">{{ trans('general.history') }}</span></a></li>
- @can('users.edit')
- <li class="dropdown pull-right">
-
- <a class="dropdown-toggle" data-toggle="dropdown" href="#">
- <i class="fa fa-gear"></i> {{ trans('button.actions') }}
- <span class="caret"></span>
- </a>
- <ul class="dropdown-menu">
- <li><a href="{{ route('users.edit', $user->id) }}">{{ trans('admin/users/general.edit') }}</a></li>
- <li><a href="{{ route('clone/user', $user->id) }}">{{ trans('admin/users/general.clone') }}</a></li>
- @if ((Auth::user()->id !== $user->id) && (!config('app.lock_passwords')) && ($user->deleted_at==''))
- <li><a href="{{ route('users.destroy', $user->id) }}">{{ trans('button.delete') }}</a></li>
- @endif
- </ul>
- </li>
+ @can('update', $user)
+ <li class="dropdown pull-right">
+
+ <a class="dropdown-toggle" data-toggle="dropdown" href="#">
+ <i class="fa fa-gear"></i> {{ trans('button.actions') }}
+ <span class="caret"></span>
+ </a>
+ <ul class="dropdown-menu">
+ <li><a href="{{ route('users.edit', $user->id) }}">{{ trans('admin/users/general.edit') }}</a></li>
+ <li><a href="{{ route('clone/user', $user->id) }}">{{ trans('admin/users/general.clone') }}</a></li>
+ @if ((Auth::user()->id !== $user->id) && (!config('app.lock_passwords')) && ($user->deleted_at==''))
+ <li><a href="{{ route('users.destroy', $user->id) }}">{{ trans('button.delete') }}</a></li>
+ @endif
+ </ul>
+ </li>
@endcan
</ul>
<div class="tab-content">
@@ -48,7 +48,7 @@
<div class="callout callout-warning">
<i class="icon fa fa-warning"></i>
This user has been marked as deleted.
- @can('users.edit')
+ @can('update', $user)
<a href="{{ route('restore/user', $user->id) }}">Click here</a> to restore them.
@endcan
</div>
@@ -132,7 +132,7 @@
<!-- Start button column -->
<div class="col-md-2">
- @can('users.edit')
+ @can('update', $user)
<div class="col-md-12">
<a href="{{ route('users.edit', $user->id) }}" style="width: 100%;" class="btn btn-sm btn-default">{{ trans('admin/users/general.edit') }}</a>
@@ -192,14 +192,14 @@
@endif
</td>
<td>
- @can('assets.view')
+ @can('view', $asset)
<a href="{{ route('hardware.show', $asset->id) }}">{{ $asset->asset_tag }}</a>
@endcan
</td>
<td><a href="{{ route('hardware.show', $asset->id) }}">{{ $asset->name }}</a></td>
<td class="hidden-print">
- @can('assets.edit')
+ @can('checkin', $asset)
<a href="{{ route('checkin/hardware', array('assetId'=> $asset->id, 'backto'=>'user')) }}" class="btn btn-primary btn-sm">Checkin</a>
@endcan
</td>
@@ -228,7 +228,7 @@
</td>
<td><a href="{{ route('licenses.show', $license->id) }}">{{ mb_strimwidth($license->serial, 0, 50, "...") }}</a></td>
<td class="hidden-print">
- @can('licenses.edit')
+ @can('update', $license)
<a href="{{ route('licenses.checkin', array('licenseseat_id'=> $license->pivot->id, 'backto'=>'user')) }}" class="btn btn-primary btn-sm">Checkin</a>
@endcan
</td>
@@ -252,7 +252,7 @@
<tr>
<td><a href="{{ route('accessories.show', $accessory->id) }}">{{ $accessory->name }}</a></td>
<td class="hidden-print">
- @can('accessories.edit')
+ @can('checkin', $accessory)
<a href="{{ route('checkin/accessory', array('accessory_id'=> $accessory->pivot->id, 'backto'=>'user')) }}" class="btn btn-primary btn-sm">Checkin</a>
@endcan
</td>
@@ -290,7 +290,7 @@
</div>
<div class="col-md-2">
<!-- The fileinput-button span is used to style the file input field as button -->
- @can('users.edit')
+ @can('update', $user)
<span class="btn btn-info fileinput-button">
<i class="fa fa-plus icon-white"></i>
<span>Select File...</span>
@@ -353,7 +353,7 @@
@endif
</td>
<td>
- @can('users.edit')
+ @can('update', $user)
<a class="btn delete-asset btn-danger btn-sm" href="{{ route('users.destroyfile', [$user->id, $file->id]) }}" data-content="Are you sure you wish to delete this file?" data-title="Delete {{ $file->filename }}?"><i class="fa fa-trash icon-white"></i></a>
@endcan
</td>
diff --git a/routes/console.php b/routes/console.php
index 75dd0cdedb..785b9387e4 100644
--- a/routes/console.php
+++ b/routes/console.php
@@ -1,5 +1,6 @@
<?php
+use App\Models\Setting;
use Illuminate\Foundation\Inspiring;
/*
@@ -16,3 +17,21 @@ use Illuminate\Foundation\Inspiring;
Artisan::command('inspire', function () {
$this->comment(Inspiring::quote());
})->describe('Display an inspiring quote');
+
+Artisan::command('snipeit:travisci-install', function () {
+ if(!Setting::setupCompleted()) {
+ $settings = new Setting;
+ $settings->site_name = 'test-ci';
+ $settings->alert_email = '[email protected]';
+ $settings->alerts_enabled = 1;
+ $settings->brand = 1;
+ $settings->locale = 'en';
+ $settings->default_currency = 'USD';
+ $settings->user_id = 1;
+ $settings->email_domain = 'example.com';
+ $settings->email_format = 'filastname';
+ $settings->save();
+ } else {
+ $this->comment('Setup already ran');
+ }
+})->describe('Travis-cli install script for unit tests');
diff --git a/routes/web.php b/routes/web.php
index ff405d908d..e8ba1c19db 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -69,7 +69,6 @@ Route::group(['middleware' => 'auth'], function () {
'display-sig/{filename}',
[
'as' => 'log.signature.view',
- 'middleware' => 'authorize:assets.view',
'uses' => 'ActionlogController@displaySig' ]
);
diff --git a/routes/web/accessories.php b/routes/web/accessories.php
index 08a436b6d5..dbfd922f3b 100644
--- a/routes/web/accessories.php
+++ b/routes/web/accessories.php
@@ -3,25 +3,24 @@
/*
* Accessories
*/
-Route::group([ 'prefix' => 'accessories', 'middleware'=>'authorize:accessories.view' ], function () {
-
+Route::group([ 'prefix' => 'accessories', ], function () {
Route::get(
'{accessoryID}/checkout',
- [ 'as' => 'checkout/accessory', 'middleware' => 'authorize:accessories.checkout','uses' => 'AccessoriesController@getCheckout' ]
+ [ 'as' => 'checkout/accessory', 'uses' => 'AccessoriesController@getCheckout' ]
);
Route::post(
'{accessoryID}/checkout',
- [ 'as' => 'checkout/accessory', 'middleware' => 'authorize:accessories.checkout','uses' => 'AccessoriesController@postCheckout' ]
+ [ 'as' => 'checkout/accessory', 'uses' => 'AccessoriesController@postCheckout' ]
);
Route::get(
'{accessoryID}/checkin/{backto?}',
- [ 'as' => 'checkin/accessory', 'middleware' => 'authorize:accessories.checkin','uses' => 'AccessoriesController@getCheckin' ]
+ [ 'as' => 'checkin/accessory', 'uses' => 'AccessoriesController@getCheckin' ]
);
Route::post(
'{accessoryID}/checkin/{backto?}',
- [ 'as' => 'checkin/accessory', 'middleware' => 'authorize:accessories.checkin','uses' => 'AccessoriesController@postCheckin' ]
+ [ 'as' => 'checkin/accessory', 'uses' => 'AccessoriesController@postCheckin' ]
);
});
diff --git a/routes/web/components.php b/routes/web/components.php
index 447fc6b604..e3f17f6fab 100644
--- a/routes/web/components.php
+++ b/routes/web/components.php
@@ -1,18 +1,18 @@
<?php
# Components
-Route::group([ 'prefix' => 'components', 'middleware'=>'authorize:components.view' ], function () {
+Route::group([ 'prefix' => 'components' ], function () {
Route::get(
'{componentID}/checkout',
- [ 'as' => 'checkout/component', 'middleware'=>'authorize:components.checkout','uses' => 'ComponentsController@getCheckout' ]
+ [ 'as' => 'checkout/component', 'uses' => 'ComponentsController@getCheckout' ]
);
Route::post(
'{componentID}/checkout',
- [ 'as' => 'checkout/component', 'middleware'=>'authorize:components.checkout','uses' => 'ComponentsController@postCheckout' ]
+ [ 'as' => 'checkout/component', 'uses' => 'ComponentsController@postCheckout' ]
);
- Route::post('bulk', [ 'as' => 'component/bulk-form', 'middleware'=>'authorize:components.checkout','uses' => 'ComponentsController@postBulk' ]);
- Route::post('bulksave', [ 'as' => 'component/bulk-save', 'middleware'=>'authorize:components.edit','uses' => 'ComponentsController@postBulkSave' ]);
+ Route::post('bulk', [ 'as' => 'component/bulk-form', 'uses' => 'ComponentsController@postBulk' ]);
+ Route::post('bulksave', [ 'as' => 'component/bulk-save', 'uses' => 'ComponentsController@postBulkSave' ]);
});
diff --git a/routes/web/consumables.php b/routes/web/consumables.php
index c895f8a4a1..da58ec099b 100644
--- a/routes/web/consumables.php
+++ b/routes/web/consumables.php
@@ -3,19 +3,13 @@
# Consumables
Route::group([ 'prefix' => 'consumables', 'middleware'=>'authorize:consumables.view' ], function () {
-
-
- Route::get(
- '{consumableID}/view',
- [ 'as' => 'view/consumable', 'middleware'=>'authorize:consumables.view','uses' => 'ConsumablesController@getView' ]
- );
Route::get(
'{consumableID}/checkout',
- [ 'as' => 'checkout/consumable', 'middleware'=>'authorize:consumables.checkout','uses' => 'ConsumablesController@getCheckout' ]
+ [ 'as' => 'checkout/consumable','uses' => 'ConsumablesController@getCheckout' ]
);
Route::post(
'{consumableID}/checkout',
- [ 'as' => 'checkout/consumable', 'middleware'=>'authorize:consumables.checkout','uses' => 'ConsumablesController@postCheckout' ]
+ [ 'as' => 'checkout/consumable', 'uses' => 'ConsumablesController@postCheckout' ]
);
});
diff --git a/routes/web/hardware.php b/routes/web/hardware.php
index 61c145d527..67c644830b 100644
--- a/routes/web/hardware.php
+++ b/routes/web/hardware.php
@@ -20,7 +20,6 @@ Route::group(
Route::get('history', [
'as' => 'asset.import-history',
- 'middleware' => 'authorize:assets.checkout',
'uses' => 'AssetsController@getImportHistory'
]);
@@ -31,13 +30,11 @@ Route::group(
Route::get('/bytag', [
'as' => 'findbytag/hardware',
- 'middleware' => 'authorize:assets.view',
'uses' => 'AssetsController@getAssetByTag'
]);
Route::get('{assetId}/clone', [
'as' => 'clone/hardware',
- 'middleware' => 'authorize:assets.create',
'uses' => 'AssetsController@getClone'
]);
@@ -45,73 +42,56 @@ Route::group(
Route::get('{assetId}/checkout', [
'as' => 'checkout/hardware',
- 'middleware' => 'authorize:assets.checkout',
'uses' => 'AssetsController@getCheckout'
]);
Route::post('{assetId}/checkout', [
'as' => 'checkout/hardware',
- 'middleware' => 'authorize:assets.checkout',
'uses' => 'AssetsController@postCheckout'
]);
Route::get('{assetId}/checkin/{backto?}', [
'as' => 'checkin/hardware',
- 'middleware' => 'authorize:assets.checkin',
'uses' => 'AssetsController@getCheckin'
]);
Route::post('{assetId}/checkin/{backto?}', [
'as' => 'checkin/hardware',
- 'middleware' => 'authorize:assets.checkin',
'uses' => 'AssetsController@postCheckin'
]);
Route::get('{assetId}/view', [
'as' => 'hardware.view',
- 'middleware' => ['authorize:assets.view'],
'uses' => 'AssetsController@show'
]);
Route::get('{assetId}/qr_code', [ 'as' => 'qr_code/hardware', 'uses' => 'AssetsController@getQrCode' ]);
Route::get('{assetId}/barcode', [ 'as' => 'barcode/hardware', 'uses' => 'AssetsController@getBarCode' ]);
Route::get('{assetId}/restore', [
'as' => 'restore/hardware',
- 'middleware' => 'authorize:assets.delete',
'uses' => 'AssetsController@getRestore'
]);
Route::post('{assetId}/upload', [
'as' => 'upload/asset',
- 'middleware' => 'authorize:assets.edit',
'uses' => 'AssetsController@postUpload'
]);
Route::get('{assetId}/deletefile/{fileId}', [
'as' => 'delete/assetfile',
- 'middleware' => 'authorize:assets.edit',
'uses' => 'AssetsController@getDeleteFile'
]);
Route::get('{assetId}/showfile/{fileId}', [
'as' => 'show/assetfile',
- 'middleware' => 'authorize:assets.view',
'uses' => 'AssetsController@displayFile'
]);
- Route::get('import/delete-import/{filename}', [
- 'as' => 'assets/import/delete-file',
- 'middleware' => 'authorize:assets.create',
- 'uses' => 'AssetsController@getDeleteImportFile'
- ]);
-
Route::post( 'import/process/', [ 'as' => 'assets/import/process-file',
- 'middleware' => 'authorize:assets.create',
'uses' => 'AssetsController@postProcessImportFile'
]);
+
Route::get( 'import/delete/{filename}', [ 'as' => 'assets/import/delete-file',
- 'middleware' => 'authorize:assets.create', // TODO What permissions should this require?
'uses' => 'AssetsController@getDeleteImportFile'
]);
Route::get('import',[
'as' => 'assets/import',
- 'middleware' => 'authorize:assets.create',
'uses' => 'AssetsController@getImportUpload'
]);
@@ -119,7 +99,6 @@ Route::group(
'bulkedit',
[
'as' => 'hardware/bulkedit',
- 'middleware' => 'authorize:assets.edit',
'uses' => 'AssetsController@postBulkEdit'
]
);
@@ -127,7 +106,6 @@ Route::group(
'bulkdelete',
[
'as' => 'hardware/bulkdelete',
- 'middleware' => 'authorize:assets.delete',
'uses' => 'AssetsController@postBulkDelete'
]
);
@@ -135,7 +113,6 @@ Route::group(
'bulksave',
[
'as' => 'hardware/bulksave',
- 'middleware' => 'authorize:assets.edit',
'uses' => 'AssetsController@postBulkSave'
]
);
@@ -143,12 +120,10 @@ Route::group(
# Bulk checkout / checkin
Route::get( 'bulkcheckout', [
'as' => 'hardware/bulkcheckout',
- 'middleware' => 'authorize:assets.checkout',
'uses' => 'AssetsController@getBulkCheckout'
]);
Route::post( 'bulkcheckout', [
'as' => 'hardware/bulkcheckout',
- 'middleware' => 'authorize:assets.checkout',
'uses' => 'AssetsController@postBulkCheckout'
]);
});
diff --git a/routes/web/licenses.php b/routes/web/licenses.php
index 9da04b5c75..4a03dac8b1 100644
--- a/routes/web/licenses.php
+++ b/routes/web/licenses.php
@@ -2,47 +2,44 @@
# Licenses
-Route::group([ 'prefix' => 'licenses', 'middleware'=>'authorize:licenses.view' ], function () {
+Route::group([ 'prefix' => 'licenses' ], function () {
- Route::get('{licenseId}/clone', [ 'as' => 'clone/license', 'middleware' => 'authorize:licenses.create', 'uses' => 'LicensesController@getClone' ]);
- Route::post('{licenseId}/clone', [ 'as' => 'clone/license', 'middleware' => 'authorize:licenses.create', 'uses' => 'LicensesController@postCreate' ]);
+ Route::get('{licenseId}/clone', [ 'as' => 'clone/license', 'uses' => 'LicensesController@getClone' ]);
+ Route::post('{licenseId}/clone', [ 'as' => 'clone/license', 'uses' => 'LicensesController@postCreate' ]);
Route::get('{licenseId}/freecheckout', [
'as' => 'licenses.freecheckout',
- 'middleware' => 'authorize:licenses.checkout',
'uses' => 'LicensesController@getFreeLicense'
]);
- Route::get(
- '{licenseId}/checkout',
- [ 'as' => 'licenses.checkout', 'middleware' => 'authorize:licenses.checkout','uses' => 'LicensesController@getCheckout' ]
- );
+ Route::get('{licenseId}/checkout', [
+ 'as' => 'licenses.checkout',
+ 'uses' => 'LicensesController@getCheckout'
+ ]);
Route::post(
- '{licenseId}/checkout',
- [ 'as' => 'licenses.checkout', 'middleware' => 'authorize:licenses.checkout','uses' => 'LicensesController@postCheckout' ]
+ '{licenseId}/checkout',
+ [ 'as' => 'licenses.checkout', 'uses' => 'LicensesController@postCheckout' ]
);
Route::get('{licenseId}/checkin/{backto?}', [
'as' => 'licenses.checkin',
- 'middleware' => 'authorize:licenses.checkin',
'uses' => 'LicensesController@getCheckin'
]);
Route::post('{licenseId}/checkin/{backto?}', [
'as' => 'licenses.checkin',
- 'middleware' => 'authorize:licenses.checkin',
'uses' => 'LicensesController@postCheckin'
]);
Route::post(
'{licenseId}/upload',
- [ 'as' => 'upload/license', 'middleware' => 'authorize:licenses.edit','uses' => 'LicensesController@postUpload' ]
+ [ 'as' => 'upload/license', 'uses' => 'LicensesController@postUpload' ]
);
Route::get(
'{licenseId}/deletefile/{fileId}',
- [ 'as' => 'delete/licensefile', 'middleware' => 'authorize:licenses.edit', 'uses' => 'LicensesController@getDeleteFile' ]
+ [ 'as' => 'delete/licensefile', 'uses' => 'LicensesController@getDeleteFile' ]
);
Route::get(
'{licenseId}/showfile/{fileId}',
- [ 'as' => 'show/licensefile', 'middleware' => 'authorize:licenses.view','uses' => 'LicensesController@displayFile' ]
+ [ 'as' => 'show/licensefile', 'uses' => 'LicensesController@displayFile' ]
);
});
diff --git a/routes/web/users.php b/routes/web/users.php
index cd86d21f1b..574d9bfab8 100644
--- a/routes/web/users.php
+++ b/routes/web/users.php
@@ -1,17 +1,17 @@
<?php
# User Management
-Route::group([ 'prefix' => 'users', 'middleware' => ['web','auth','authorize:users.view']], function () {
+Route::group([ 'prefix' => 'users', 'middleware' => ['web','auth']], function () {
- Route::get('ldap', ['as' => 'ldap/user', 'uses' => 'UsersController@getLDAP', 'middleware' => ['authorize:users.edit'] ]);
+ Route::get('ldap', ['as' => 'ldap/user', 'uses' => 'UsersController@getLDAP' ]);
Route::post('ldap', 'UsersController@postLDAP');
- Route::get('import', [ 'as' => 'import/user', 'uses' => 'UsersController@getImport', 'middleware' => ['authorize:users.edit'] ]);
- Route::post('import', [ 'uses' => 'UsersController@postImport', 'middleware' => ['authorize:users.edit'] ]);
- Route::get('export', [ 'uses' => 'UsersController@getExportUserCsv', 'middleware' => ['authorize:users.view'] ]);
- Route::get('{userId}/clone', [ 'as' => 'clone/user', 'uses' => 'UsersController@getClone', 'middleware' => ['authorize:users.edit'] ]);
- Route::post('{userId}/clone', [ 'uses' => 'UsersController@postCreate', 'middleware' => ['authorize:users.edit'] ]);
- Route::get('{userId}/restore', [ 'as' => 'restore/user', 'uses' => 'UsersController@getRestore', 'middleware' => ['authorize:users.edit'] ]);
- Route::get('{userId}/unsuspend', [ 'as' => 'unsuspend/user', 'uses' => 'UsersController@getUnsuspend', 'middleware' => ['authorize:users.edit'] ]);
+ Route::get('import', [ 'as' => 'import/user', 'uses' => 'UsersController@getImport' ]);
+ Route::post('import', [ 'uses' => 'UsersController@postImport' ]);
+ Route::get('export', [ 'uses' => 'UsersController@getExportUserCsv' ]);
+ Route::get('{userId}/clone', [ 'as' => 'clone/user', 'uses' => 'UsersController@getClone' ]);
+ Route::post('{userId}/clone', [ 'uses' => 'UsersController@postCreate' ]);
+ Route::get('{userId}/restore', [ 'as' => 'restore/user', 'uses' => 'UsersController@getRestore' ]);
+ Route::get('{userId}/unsuspend', [ 'as' => 'unsuspend/user', 'uses' => 'UsersController@getUnsuspend' ]);
Route::get(
'{userId}/deletefile/{fileId}',
[ 'as' => 'delete/userfile', 'uses' => 'UsersController@getDeleteFile' ]
@@ -26,7 +26,6 @@ Route::group([ 'prefix' => 'users', 'middleware' => ['web','auth','authorize:use
[
'as' => 'users/bulkedit',
'uses' => 'UsersController@postBulkEdit',
- 'middleware' => ['authorize:users.edit'],
]
);
Route::post(
@@ -34,7 +33,6 @@ Route::group([ 'prefix' => 'users', 'middleware' => ['web','auth','authorize:use
[
'as' => 'users/bulksave',
'uses' => 'UsersController@postBulkSave',
- 'middleware' => ['authorize:users.edit'],
]
);
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 6f51045415..7b3c65c174 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -16,11 +16,12 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
*/
public function createApplication()
{
- $app = require_once __DIR__.'/../bootstrap/app.php';
+ $app = require __DIR__.'/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
+
public function setUp()
{
parent::setUp();
diff --git a/tests/_data/dump.sql b/tests/_data/dump.sql
index 281e520b40..d7b8702be0 100644
--- a/tests/_data/dump.sql
+++ b/tests/_data/dump.sql
@@ -1,8 +1,8 @@
--- MySQL dump 10.13 Distrib 5.7.15, for Linux (x86_64)
+-- MySQL dump 10.13 Distrib 5.7.16, for Linux (x86_64)
--
-- Host: localhost Database: snipeittests
-- ------------------------------------------------------
--- Server version 5.7.15-0ubuntu0.16.04.1
+-- Server version 5.7.16-0ubuntu0.16.04.1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
@@ -795,7 +795,7 @@ CREATE TABLE `migrations` (
LOCK TABLES `migrations` WRITE;
/*!40000 ALTER TABLE `migrations` DISABLE KEYS */;
-INSERT INTO `migrations` VALUES ('2012_12_06_225921_migration_cartalyst_sentry_install_users',1),('2012_12_06_225929_migration_cartalyst_sentry_install_groups',1),('2012_12_06_225945_migration_cartalyst_sentry_install_users_groups_pivot',1),('2012_12_06_225988_migration_cartalyst_sentry_install_throttle',1),('2013_03_23_193214_update_users_table',1),('2013_11_13_075318_create_models_table',1),('2013_11_13_075335_create_categories_table',1),('2013_11_13_075347_create_manufacturers_table',1),('2013_11_15_015858_add_user_id_to_categories',1),('2013_11_15_112701_add_user_id_to_manufacturers',1),('2013_11_15_190327_create_assets_table',1),('2013_11_15_190357_create_licenses_table',1),('2013_11_15_201848_add_license_name_to_licenses',1),('2013_11_16_040323_create_depreciations_table',1),('2013_11_16_042851_add_depreciation_id_to_models',1),('2013_11_16_084923_add_user_id_to_models',1),('2013_11_16_103258_create_locations_table',1),('2013_11_16_103336_add_location_id_to_assets',1),('2013_11_16_103407_add_checkedout_to_to_assets',1),('2013_11_16_103425_create_history_table',1),('2013_11_17_054359_drop_licenses_table',1),('2013_11_17_054526_add_physical_to_assets',1),('2013_11_17_055126_create_settings_table',1),('2013_11_17_062634_add_license_to_assets',1),('2013_11_18_134332_add_contacts_to_users',1),('2013_11_18_142847_add_info_to_locations',1),('2013_11_18_152942_remove_location_id_from_asset',1),('2013_11_18_164423_set_nullvalues_for_user',1),('2013_11_19_013337_create_asset_logs_table',1),('2013_11_19_061409_edit_added_on_asset_logs_table',1),('2013_11_19_062250_edit_location_id_asset_logs_table',1),('2013_11_20_055822_add_soft_delete_on_assets',1),('2013_11_20_121404_add_soft_delete_on_locations',1),('2013_11_20_123137_add_soft_delete_on_manufacturers',1),('2013_11_20_123725_add_soft_delete_on_categories',1),('2013_11_20_130248_create_status_labels',1),('2013_11_20_130830_add_status_id_on_assets_table',1),('2013_11_20_131544_add_status_type_on_status_labels',1),('2013_11_20_134103_add_archived_to_assets',1),('2013_11_21_002321_add_uploads_table',1),('2013_11_21_024531_remove_deployable_boolean_from_status_labels',1),('2013_11_22_075308_add_option_label_to_settings_table',1),('2013_11_22_213400_edits_to_settings_table',1),('2013_11_25_013244_create_licenses_table',1),('2013_11_25_031458_create_license_seats_table',1),('2013_11_25_032022_add_type_to_actionlog_table',1),('2013_11_25_033008_delete_bad_licenses_table',1),('2013_11_25_033131_create_new_licenses_table',1),('2013_11_25_033534_add_licensed_to_licenses_table',1),('2013_11_25_101308_add_warrantee_to_assets_table',1),('2013_11_25_104343_alter_warranty_column_on_assets',1),('2013_11_25_150450_drop_parent_from_categories',1),('2013_11_25_151920_add_depreciate_to_assets',1),('2013_11_25_152903_add_depreciate_to_licenses_table',1),('2013_11_26_211820_drop_license_from_assets_table',1),('2013_11_27_062510_add_note_to_asset_logs_table',1),('2013_12_01_113426_add_filename_to_asset_log',1),('2013_12_06_094618_add_nullable_to_licenses_table',1),('2013_12_10_084038_add_eol_on_models_table',1),('2013_12_12_055218_add_manager_to_users_table',1),('2014_01_28_031200_add_qr_code_to_settings_table',1),('2014_02_13_183016_add_qr_text_to_settings_table',1),('2014_05_24_093839_alter_default_license_depreciation_id',1),('2014_05_27_231658_alter_default_values_licenses',1),('2014_06_19_191508_add_asset_name_to_settings',1),('2014_06_20_004847_make_asset_log_checkedout_to_nullable',1),('2014_06_20_005050_make_asset_log_purchasedate_to_nullable',1),('2014_06_24_003011_add_suppliers',1),('2014_06_24_010742_add_supplier_id_to_asset',1),('2014_06_24_012839_add_zip_to_supplier',1),('2014_06_24_033908_add_url_to_supplier',1),('2014_07_08_054116_add_employee_id_to_users',1),('2014_07_09_134316_add_requestable_to_assets',1),('2014_07_17_085822_add_asset_to_software',1),('2014_07_17_161625_make_asset_id_in_logs_nullable',1),('2014_08_12_053504_alpha_0_4_2_release',1),('2014_08_17_083523_make_location_id_nullable',1),('2014_10_16_200626_add_rtd_location_to_assets',1),('2014_10_24_000417_alter_supplier_state_to_32',1),('2014_10_24_015641_add_display_checkout_date',1),('2014_10_28_222654_add_avatar_field_to_users_table',1),('2014_10_29_045924_add_image_field_to_models_table',1),('2014_11_01_214955_add_eol_display_to_settings',1),('2014_11_04_231416_update_group_field_for_reporting',1),('2014_11_05_212408_add_fields_to_licenses',1),('2014_11_07_021042_add_image_to_supplier',1),('2014_11_20_203007_add_username_to_user',1),('2014_11_20_223947_add_auto_to_settings',1),('2014_11_20_224421_add_prefix_to_settings',1),('2014_11_21_104401_change_licence_type',1),('2014_12_09_082500_add_fields_maintained_term_to_licenses',1),('2015_02_04_155757_increase_user_field_lengths',1),('2015_02_07_013537_add_soft_deleted_to_log',1),('2015_02_10_040958_fix_bad_assigned_to_ids',1),('2015_02_10_053310_migrate_data_to_new_statuses',1),('2015_02_11_044104_migrate_make_license_assigned_null',1),('2015_02_11_104406_migrate_create_requests_table',1),('2015_02_12_001312_add_mac_address_to_asset',1),('2015_02_12_024100_change_license_notes_type',1),('2015_02_17_231020_add_localonly_to_settings',1),('2015_02_19_222322_add_logo_and_colors_to_settings',1),('2015_02_24_072043_add_alerts_to_settings',1),('2015_02_25_022931_add_eula_fields',1),('2015_02_25_204513_add_accessories_table',1),('2015_02_26_091228_add_accessories_user_table',1),('2015_02_26_115128_add_deleted_at_models',1),('2015_02_26_233005_add_category_type',1),('2015_03_01_231912_update_accepted_at_to_acceptance_id',1),('2015_03_05_011929_add_qr_type_to_settings',1),('2015_03_18_055327_add_note_to_user',1),('2015_04_29_234704_add_slack_to_settings',1),('2015_05_04_085151_add_parent_id_to_locations_table',1),('2015_05_22_124421_add_reassignable_to_licenses',1),('2015_06_10_003314_fix_default_for_user_notes',1),('2015_06_10_003554_create_consumables',1),('2015_06_15_183253_move_email_to_username',1),('2015_06_23_070346_make_email_nullable',1),('2015_06_26_213716_create_asset_maintenances_table',1),('2015_07_04_212443_create_custom_fields_table',1),('2015_07_09_014359_add_currency_to_settings_and_locations',1),('2015_07_21_122022_add_expected_checkin_date_to_asset_logs',1),('2015_07_24_093845_add_checkin_email_to_category_table',1),('2015_07_25_055415_remove_email_unique_constraint',1),('2015_07_29_230054_add_thread_id_to_asset_logs_table',1),('2015_07_31_015430_add_accepted_to_assets',1),('2015_09_09_195301_add_custom_css_to_settings',1),('2015_09_21_235926_create_custom_field_custom_fieldset',1),('2015_09_22_000104_create_custom_fieldsets',1),('2015_09_22_003321_add_fieldset_id_to_assets',1),('2015_09_22_003413_migrate_mac_address',1),('2015_09_28_003314_fix_default_purchase_order',1),('2015_10_01_024551_add_accessory_consumable_price_info',1),('2015_10_12_192706_add_brand_to_settings',1),('2015_10_22_003314_fix_defaults_accessories',1),('2015_10_23_182625_add_checkout_time_and_expected_checkout_date_to_assets',1),('2015_11_05_061015_create_companies_table',1),('2015_11_05_061115_add_company_id_to_consumables_table',1),('2015_11_05_183749_image',1),('2015_11_06_092038_add_company_id_to_accessories_table',1),('2015_11_06_100045_add_company_id_to_users_table',1),('2015_11_06_134742_add_company_id_to_licenses_table',1),('2015_11_08_035832_add_company_id_to_assets_table',1),('2015_11_08_222305_add_ldap_fields_to_settings',1),('2015_11_15_151803_add_full_multiple_companies_support_to_settings_table',1),('2015_11_26_195528_import_ldap_settings',1),('2015_11_30_191504_remove_fk_company_id',1),('2015_12_21_193006_add_ldap_server_cert_ignore_to_settings_table',1),('2015_12_30_233509_add_timestamp_and_userId_to_custom_fields',1),('2015_12_30_233658_add_timestamp_and_userId_to_custom_fieldsets',1),('2016_01_28_041048_add_notes_to_models',1),('2016_02_19_070119_add_remember_token_to_users_table',1),('2016_02_19_073625_create_password_resets_table',1),('2016_03_02_193043_add_ldap_flag_to_users',1),('2016_03_02_220517_update_ldap_filter_to_longer_field',1),('2016_03_08_225351_create_components_table',1),('2016_03_09_024038_add_min_stock_to_tables',1),('2016_03_10_133849_add_locale_to_users',1),('2016_03_10_135519_add_locale_to_settings',1),('2016_03_11_185621_add_label_settings_to_settings',1),('2016_03_22_125911_fix_custom_fields_regexes',1),('2016_04_28_141554_add_show_to_users',1),('2016_05_16_164733_add_model_mfg_to_consumable',1),('2016_05_19_180351_add_alt_barcode_settings',1),('2016_05_19_191146_add_alter_interval',1),('2016_05_19_192226_add_inventory_threshold',1),('2016_05_20_024859_remove_option_keys_from_settings_table',1),('2016_05_20_143758_remove_option_value_from_settings_table',1),('2016_06_01_140218_add_email_domain_and_format_to_settings',1),('2016_06_22_160725_add_user_id_to_maintenances',1),('2016_07_13_150015_add_is_ad_to_settings',1),('2016_07_14_153609_add_ad_domain_to_settings',1),('2016_07_22_003348_fix_custom_fields_regex_stuff',1),('2016_07_22_054850_one_more_mac_addr_fix',1),('2016_07_22_143045_add_port_to_ldap_settings',1),('2016_07_22_153432_add_tls_to_ldap_settings',1),('2016_07_27_211034_add_zerofill_to_settings',1),('2016_08_02_124944_add_color_to_statuslabel',1),('2016_08_04_134500_add_disallow_ldap_pw_sync_to_settings',1),('2016_08_09_002225_add_manufacturer_to_licenses',1),('2016_08_12_121613_add_manufacturer_to_accessories_table',1),('2016_08_23_143353_add_new_fields_to_custom_fields',1),('2016_08_23_145619_add_show_in_nav_to_status_labels',1),('2016_08_30_084634_make_purchase_cost_nullable',1),('2016_09_01_141051_add_requestable_to_asset_model',1),('2016_09_02_001448_create_checkout_requests_table',1),('2016_09_04_180400_create_actionlog_table',1),('2016_09_04_182149_migrate_asset_log_to_action_log',1),('2016_09_19_235935_fix_fieldtype_for_target_type',1),('2016_09_23_140722_fix_modelno_in_consumables_to_string',1),('2016_09_28_231359_add_company_to_logs',1),('2016_10_14_130709_fix_order_number_to_varchar',1),('2016_10_19_145520_fix_order_number_in_components_to_string',1),('2016_10_27_151715_add_serial_to_components',1),('2016_10_27_213251_increase_serial_field_capacity',1),('2016_10_29_002724_enable_2fa_fields',1),('2016_10_29_082408_add_signature_to_acceptance',1),('2016_11_01_030818_fix_forgotten_filename_in_action_logs',1),('2016_10_16_015024_rename_modelno_to_model_number',2),('2016_10_16_015211_rename_consumable_modelno_to_model_number',2),('2016_10_16_143235_rename_model_note_to_notes',2),('2016_10_16_165052_rename_component_total_qty_to_qty',2),('2016_11_13_020954_rename_component_serial_number_to_serial',2),('2016_11_16_172119_increase_purchase_cost_size',3),('2016_11_17_161317_longer_state_field_in_location',3),('2016_11_17_193706_add_model_number_to_accessories',3);
+INSERT INTO `migrations` VALUES ('2012_12_06_225921_migration_cartalyst_sentry_install_users',1),('2012_12_06_225929_migration_cartalyst_sentry_install_groups',1),('2012_12_06_225945_migration_cartalyst_sentry_install_users_groups_pivot',1),('2012_12_06_225988_migration_cartalyst_sentry_install_throttle',1),('2013_03_23_193214_update_users_table',1),('2013_11_13_075318_create_models_table',1),('2013_11_13_075335_create_categories_table',1),('2013_11_13_075347_create_manufacturers_table',1),('2013_11_15_015858_add_user_id_to_categories',1),('2013_11_15_112701_add_user_id_to_manufacturers',1),('2013_11_15_190327_create_assets_table',1),('2013_11_15_190357_create_licenses_table',1),('2013_11_15_201848_add_license_name_to_licenses',1),('2013_11_16_040323_create_depreciations_table',1),('2013_11_16_042851_add_depreciation_id_to_models',1),('2013_11_16_084923_add_user_id_to_models',1),('2013_11_16_103258_create_locations_table',1),('2013_11_16_103336_add_location_id_to_assets',1),('2013_11_16_103407_add_checkedout_to_to_assets',1),('2013_11_16_103425_create_history_table',1),('2013_11_17_054359_drop_licenses_table',1),('2013_11_17_054526_add_physical_to_assets',1),('2013_11_17_055126_create_settings_table',1),('2013_11_17_062634_add_license_to_assets',1),('2013_11_18_134332_add_contacts_to_users',1),('2013_11_18_142847_add_info_to_locations',1),('2013_11_18_152942_remove_location_id_from_asset',1),('2013_11_18_164423_set_nullvalues_for_user',1),('2013_11_19_013337_create_asset_logs_table',1),('2013_11_19_061409_edit_added_on_asset_logs_table',1),('2013_11_19_062250_edit_location_id_asset_logs_table',1),('2013_11_20_055822_add_soft_delete_on_assets',1),('2013_11_20_121404_add_soft_delete_on_locations',1),('2013_11_20_123137_add_soft_delete_on_manufacturers',1),('2013_11_20_123725_add_soft_delete_on_categories',1),('2013_11_20_130248_create_status_labels',1),('2013_11_20_130830_add_status_id_on_assets_table',1),('2013_11_20_131544_add_status_type_on_status_labels',1),('2013_11_20_134103_add_archived_to_assets',1),('2013_11_21_002321_add_uploads_table',1),('2013_11_21_024531_remove_deployable_boolean_from_status_labels',1),('2013_11_22_075308_add_option_label_to_settings_table',1),('2013_11_22_213400_edits_to_settings_table',1),('2013_11_25_013244_create_licenses_table',1),('2013_11_25_031458_create_license_seats_table',1),('2013_11_25_032022_add_type_to_actionlog_table',1),('2013_11_25_033008_delete_bad_licenses_table',1),('2013_11_25_033131_create_new_licenses_table',1),('2013_11_25_033534_add_licensed_to_licenses_table',1),('2013_11_25_101308_add_warrantee_to_assets_table',1),('2013_11_25_104343_alter_warranty_column_on_assets',1),('2013_11_25_150450_drop_parent_from_categories',1),('2013_11_25_151920_add_depreciate_to_assets',1),('2013_11_25_152903_add_depreciate_to_licenses_table',1),('2013_11_26_211820_drop_license_from_assets_table',1),('2013_11_27_062510_add_note_to_asset_logs_table',1),('2013_12_01_113426_add_filename_to_asset_log',1),('2013_12_06_094618_add_nullable_to_licenses_table',1),('2013_12_10_084038_add_eol_on_models_table',1),('2013_12_12_055218_add_manager_to_users_table',1),('2014_01_28_031200_add_qr_code_to_settings_table',1),('2014_02_13_183016_add_qr_text_to_settings_table',1),('2014_05_24_093839_alter_default_license_depreciation_id',1),('2014_05_27_231658_alter_default_values_licenses',1),('2014_06_19_191508_add_asset_name_to_settings',1),('2014_06_20_004847_make_asset_log_checkedout_to_nullable',1),('2014_06_20_005050_make_asset_log_purchasedate_to_nullable',1),('2014_06_24_003011_add_suppliers',1),('2014_06_24_010742_add_supplier_id_to_asset',1),('2014_06_24_012839_add_zip_to_supplier',1),('2014_06_24_033908_add_url_to_supplier',1),('2014_07_08_054116_add_employee_id_to_users',1),('2014_07_09_134316_add_requestable_to_assets',1),('2014_07_17_085822_add_asset_to_software',1),('2014_07_17_161625_make_asset_id_in_logs_nullable',1),('2014_08_12_053504_alpha_0_4_2_release',1),('2014_08_17_083523_make_location_id_nullable',1),('2014_10_16_200626_add_rtd_location_to_assets',1),('2014_10_24_000417_alter_supplier_state_to_32',1),('2014_10_24_015641_add_display_checkout_date',1),('2014_10_28_222654_add_avatar_field_to_users_table',1),('2014_10_29_045924_add_image_field_to_models_table',1),('2014_11_01_214955_add_eol_display_to_settings',1),('2014_11_04_231416_update_group_field_for_reporting',1),('2014_11_05_212408_add_fields_to_licenses',1),('2014_11_07_021042_add_image_to_supplier',1),('2014_11_20_203007_add_username_to_user',1),('2014_11_20_223947_add_auto_to_settings',1),('2014_11_20_224421_add_prefix_to_settings',1),('2014_11_21_104401_change_licence_type',1),('2014_12_09_082500_add_fields_maintained_term_to_licenses',1),('2015_02_04_155757_increase_user_field_lengths',1),('2015_02_07_013537_add_soft_deleted_to_log',1),('2015_02_10_040958_fix_bad_assigned_to_ids',1),('2015_02_10_053310_migrate_data_to_new_statuses',1),('2015_02_11_044104_migrate_make_license_assigned_null',1),('2015_02_11_104406_migrate_create_requests_table',1),('2015_02_12_001312_add_mac_address_to_asset',1),('2015_02_12_024100_change_license_notes_type',1),('2015_02_17_231020_add_localonly_to_settings',1),('2015_02_19_222322_add_logo_and_colors_to_settings',1),('2015_02_24_072043_add_alerts_to_settings',1),('2015_02_25_022931_add_eula_fields',1),('2015_02_25_204513_add_accessories_table',1),('2015_02_26_091228_add_accessories_user_table',1),('2015_02_26_115128_add_deleted_at_models',1),('2015_02_26_233005_add_category_type',1),('2015_03_01_231912_update_accepted_at_to_acceptance_id',1),('2015_03_05_011929_add_qr_type_to_settings',1),('2015_03_18_055327_add_note_to_user',1),('2015_04_29_234704_add_slack_to_settings',1),('2015_05_04_085151_add_parent_id_to_locations_table',1),('2015_05_22_124421_add_reassignable_to_licenses',1),('2015_06_10_003314_fix_default_for_user_notes',1),('2015_06_10_003554_create_consumables',1),('2015_06_15_183253_move_email_to_username',1),('2015_06_23_070346_make_email_nullable',1),('2015_06_26_213716_create_asset_maintenances_table',1),('2015_07_04_212443_create_custom_fields_table',1),('2015_07_09_014359_add_currency_to_settings_and_locations',1),('2015_07_21_122022_add_expected_checkin_date_to_asset_logs',1),('2015_07_24_093845_add_checkin_email_to_category_table',1),('2015_07_25_055415_remove_email_unique_constraint',1),('2015_07_29_230054_add_thread_id_to_asset_logs_table',1),('2015_07_31_015430_add_accepted_to_assets',1),('2015_09_09_195301_add_custom_css_to_settings',1),('2015_09_21_235926_create_custom_field_custom_fieldset',1),('2015_09_22_000104_create_custom_fieldsets',1),('2015_09_22_003321_add_fieldset_id_to_assets',1),('2015_09_22_003413_migrate_mac_address',1),('2015_09_28_003314_fix_default_purchase_order',1),('2015_10_01_024551_add_accessory_consumable_price_info',1),('2015_10_12_192706_add_brand_to_settings',1),('2015_10_22_003314_fix_defaults_accessories',1),('2015_10_23_182625_add_checkout_time_and_expected_checkout_date_to_assets',1),('2015_11_05_061015_create_companies_table',1),('2015_11_05_061115_add_company_id_to_consumables_table',1),('2015_11_05_183749_image',1),('2015_11_06_092038_add_company_id_to_accessories_table',1),('2015_11_06_100045_add_company_id_to_users_table',1),('2015_11_06_134742_add_company_id_to_licenses_table',1),('2015_11_08_035832_add_company_id_to_assets_table',1),('2015_11_08_222305_add_ldap_fields_to_settings',1),('2015_11_15_151803_add_full_multiple_companies_support_to_settings_table',1),('2015_11_26_195528_import_ldap_settings',1),('2015_11_30_191504_remove_fk_company_id',1),('2015_12_21_193006_add_ldap_server_cert_ignore_to_settings_table',1),('2015_12_30_233509_add_timestamp_and_userId_to_custom_fields',1),('2015_12_30_233658_add_timestamp_and_userId_to_custom_fieldsets',1),('2016_01_28_041048_add_notes_to_models',1),('2016_02_19_070119_add_remember_token_to_users_table',1),('2016_02_19_073625_create_password_resets_table',1),('2016_03_02_193043_add_ldap_flag_to_users',1),('2016_03_02_220517_update_ldap_filter_to_longer_field',1),('2016_03_08_225351_create_components_table',1),('2016_03_09_024038_add_min_stock_to_tables',1),('2016_03_10_133849_add_locale_to_users',1),('2016_03_10_135519_add_locale_to_settings',1),('2016_03_11_185621_add_label_settings_to_settings',1),('2016_03_22_125911_fix_custom_fields_regexes',1),('2016_04_28_141554_add_show_to_users',1),('2016_05_16_164733_add_model_mfg_to_consumable',1),('2016_05_19_180351_add_alt_barcode_settings',1),('2016_05_19_191146_add_alter_interval',1),('2016_05_19_192226_add_inventory_threshold',1),('2016_05_20_024859_remove_option_keys_from_settings_table',1),('2016_05_20_143758_remove_option_value_from_settings_table',1),('2016_06_01_140218_add_email_domain_and_format_to_settings',1),('2016_06_22_160725_add_user_id_to_maintenances',1),('2016_07_13_150015_add_is_ad_to_settings',1),('2016_07_14_153609_add_ad_domain_to_settings',1),('2016_07_22_003348_fix_custom_fields_regex_stuff',1),('2016_07_22_054850_one_more_mac_addr_fix',1),('2016_07_22_143045_add_port_to_ldap_settings',1),('2016_07_22_153432_add_tls_to_ldap_settings',1),('2016_07_27_211034_add_zerofill_to_settings',1),('2016_08_02_124944_add_color_to_statuslabel',1),('2016_08_04_134500_add_disallow_ldap_pw_sync_to_settings',1),('2016_08_09_002225_add_manufacturer_to_licenses',1),('2016_08_12_121613_add_manufacturer_to_accessories_table',1),('2016_08_23_143353_add_new_fields_to_custom_fields',1),('2016_08_23_145619_add_show_in_nav_to_status_labels',1),('2016_08_30_084634_make_purchase_cost_nullable',1),('2016_09_01_141051_add_requestable_to_asset_model',1),('2016_09_02_001448_create_checkout_requests_table',1),('2016_09_04_180400_create_actionlog_table',1),('2016_09_04_182149_migrate_asset_log_to_action_log',1),('2016_09_19_235935_fix_fieldtype_for_target_type',1),('2016_09_23_140722_fix_modelno_in_consumables_to_string',1),('2016_09_28_231359_add_company_to_logs',1),('2016_10_14_130709_fix_order_number_to_varchar',1),('2016_10_19_145520_fix_order_number_in_components_to_string',1),('2016_10_27_151715_add_serial_to_components',1),('2016_10_27_213251_increase_serial_field_capacity',1),('2016_10_29_002724_enable_2fa_fields',1),('2016_10_29_082408_add_signature_to_acceptance',1),('2016_11_01_030818_fix_forgotten_filename_in_action_logs',1),('2016_10_16_015024_rename_modelno_to_model_number',2),('2016_10_16_015211_rename_consumable_modelno_to_model_number',2),('2016_10_16_143235_rename_model_note_to_notes',2),('2016_10_16_165052_rename_component_total_qty_to_qty',2),('2016_11_13_020954_rename_component_serial_number_to_serial',2),('2016_11_16_172119_increase_purchase_cost_size',3),('2016_11_17_161317_longer_state_field_in_location',3),('2016_11_17_193706_add_model_number_to_accessories',3),('2016_06_01_000001_create_oauth_auth_codes_table',4),('2016_06_01_000002_create_oauth_access_tokens_table',4),('2016_06_01_000003_create_oauth_refresh_tokens_table',4),('2016_06_01_000004_create_oauth_clients_table',4),('2016_06_01_000005_create_oauth_personal_access_clients_table',4),('2016_11_24_160405_add_missing_target_type_to_logs_table',4),('2016_12_07_173720_increase_size_of_state_in_suppliers',4),('2016_12_19_004212_adjust_locale_length_to_10',4);
/*!40000 ALTER TABLE `migrations` ENABLE KEYS */;
UNLOCK TABLES;
@@ -837,6 +837,148 @@ INSERT INTO `models` VALUES (1,'Organized zerotolerance strategy','41955019',3,1
/*!40000 ALTER TABLE `models` ENABLE KEYS */;
UNLOCK TABLES;
+--
+-- Table structure for table `oauth_access_tokens`
+--
+
+DROP TABLE IF EXISTS `oauth_access_tokens`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `oauth_access_tokens` (
+ `id` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `user_id` int(11) DEFAULT NULL,
+ `client_id` int(11) NOT NULL,
+ `name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `scopes` text COLLATE utf8_unicode_ci,
+ `revoked` tinyint(1) NOT NULL,
+ `created_at` timestamp NULL DEFAULT NULL,
+ `updated_at` timestamp NULL DEFAULT NULL,
+ `expires_at` datetime DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `oauth_access_tokens_user_id_index` (`user_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `oauth_access_tokens`
+--
+
+LOCK TABLES `oauth_access_tokens` WRITE;
+/*!40000 ALTER TABLE `oauth_access_tokens` DISABLE KEYS */;
+/*!40000 ALTER TABLE `oauth_access_tokens` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `oauth_auth_codes`
+--
+
+DROP TABLE IF EXISTS `oauth_auth_codes`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `oauth_auth_codes` (
+ `id` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `user_id` int(11) NOT NULL,
+ `client_id` int(11) NOT NULL,
+ `scopes` text COLLATE utf8_unicode_ci,
+ `revoked` tinyint(1) NOT NULL,
+ `expires_at` datetime DEFAULT NULL,
+ PRIMARY KEY (`id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `oauth_auth_codes`
+--
+
+LOCK TABLES `oauth_auth_codes` WRITE;
+/*!40000 ALTER TABLE `oauth_auth_codes` DISABLE KEYS */;
+/*!40000 ALTER TABLE `oauth_auth_codes` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `oauth_clients`
+--
+
+DROP TABLE IF EXISTS `oauth_clients`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `oauth_clients` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `user_id` int(11) DEFAULT NULL,
+ `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
+ `secret` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `redirect` text COLLATE utf8_unicode_ci NOT NULL,
+ `personal_access_client` tinyint(1) NOT NULL,
+ `password_client` tinyint(1) NOT NULL,
+ `revoked` tinyint(1) NOT NULL,
+ `created_at` timestamp NULL DEFAULT NULL,
+ `updated_at` timestamp NULL DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `oauth_clients_user_id_index` (`user_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `oauth_clients`
+--
+
+LOCK TABLES `oauth_clients` WRITE;
+/*!40000 ALTER TABLE `oauth_clients` DISABLE KEYS */;
+/*!40000 ALTER TABLE `oauth_clients` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `oauth_personal_access_clients`
+--
+
+DROP TABLE IF EXISTS `oauth_personal_access_clients`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `oauth_personal_access_clients` (
+ `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
+ `client_id` int(11) NOT NULL,
+ `created_at` timestamp NULL DEFAULT NULL,
+ `updated_at` timestamp NULL DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `oauth_personal_access_clients_client_id_index` (`client_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `oauth_personal_access_clients`
+--
+
+LOCK TABLES `oauth_personal_access_clients` WRITE;
+/*!40000 ALTER TABLE `oauth_personal_access_clients` DISABLE KEYS */;
+/*!40000 ALTER TABLE `oauth_personal_access_clients` ENABLE KEYS */;
+UNLOCK TABLES;
+
+--
+-- Table structure for table `oauth_refresh_tokens`
+--
+
+DROP TABLE IF EXISTS `oauth_refresh_tokens`;
+/*!40101 SET @saved_cs_client = @@character_set_client */;
+/*!40101 SET character_set_client = utf8 */;
+CREATE TABLE `oauth_refresh_tokens` (
+ `id` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `access_token_id` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
+ `revoked` tinyint(1) NOT NULL,
+ `expires_at` datetime DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `oauth_refresh_tokens_access_token_id_index` (`access_token_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
+--
+-- Dumping data for table `oauth_refresh_tokens`
+--
+
+LOCK TABLES `oauth_refresh_tokens` WRITE;
+/*!40000 ALTER TABLE `oauth_refresh_tokens` DISABLE KEYS */;
+/*!40000 ALTER TABLE `oauth_refresh_tokens` ENABLE KEYS */;
+UNLOCK TABLES;
+
--
-- Table structure for table `password_resets`
--
@@ -1061,7 +1203,7 @@ CREATE TABLE `suppliers` (
`address` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`address2` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`city` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- `state` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL,
+ `state` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
`country` varchar(2) COLLATE utf8_unicode_ci DEFAULT NULL,
`phone` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
`fax` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
@@ -1157,7 +1299,7 @@ CREATE TABLE `users` (
`company_id` int(10) unsigned DEFAULT NULL,
`remember_token` text COLLATE utf8_unicode_ci,
`ldap_import` tinyint(1) NOT NULL DEFAULT '0',
- `locale` varchar(5) COLLATE utf8_unicode_ci DEFAULT 'en',
+ `locale` varchar(10) COLLATE utf8_unicode_ci DEFAULT 'en',
`show_in_list` tinyint(1) NOT NULL DEFAULT '1',
`two_factor_secret` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
`two_factor_enrolled` tinyint(1) NOT NULL DEFAULT '0',
@@ -1210,4 +1352,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2016-11-20 12:36:32
+-- Dump completed on 2016-12-18 18:48:52
diff --git a/tests/_envs/functional-travis.yml b/tests/_envs/functional-travis.yml
new file mode 100644
index 0000000000..937a3cb7b1
--- /dev/null
+++ b/tests/_envs/functional-travis.yml
@@ -0,0 +1,11 @@
+# `functional-travis` enviromodules:
+class_name: FunctionalTester
+modules:
+ config:
+ # add framework module here
+ Laravel5:
+ environment_file: .env.testing-ci
+ Db:
+ dsn: 'mysql:host=localhost;dbname=snipeit_unit'
+ user: 'travis'
+ password: ''
\ No newline at end of file
diff --git a/tests/_envs/testing-ci.yml b/tests/_envs/testing-ci.yml
index 9a5e4db410..c40d8e595e 100644
--- a/tests/_envs/testing-ci.yml
+++ b/tests/_envs/testing-ci.yml
@@ -16,3 +16,4 @@ modules:
- \Helper\Acceptance
- Laravel5:
part: ORM
+ environment_file: .env
diff --git a/tests/functional.suite.yml b/tests/functional.suite.yml
index 553fa9d2b5..ef803ede44 100644
--- a/tests/functional.suite.yml
+++ b/tests/functional.suite.yml
@@ -19,3 +19,5 @@ modules:
dump: tests/_data/dump.sql
populate: true
cleanup: false
+ - REST:
+ depends: Laravel5
diff --git a/tests/functional/AccessoriesCest.php b/tests/functional/AccessoriesCest.php
index e0d5c5d828..bdbd66154d 100644
--- a/tests/functional/AccessoriesCest.php
+++ b/tests/functional/AccessoriesCest.php
@@ -76,7 +76,7 @@ class AccessoriesCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete an accessory');
- $I->amOnPage( route('accessories.destroy', $I->getAccessoryId() ) );
- $I->seeElement('.alert-success');
+ $I->sendDelete( route('accessories.destroy', $I->getAccessoryId() ), ['_token' => csrf_token()] );
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/AssetModelsCest.php b/tests/functional/AssetModelsCest.php
index 3b33003cb1..7823bfef2c 100644
--- a/tests/functional/AssetModelsCest.php
+++ b/tests/functional/AssetModelsCest.php
@@ -56,9 +56,8 @@ class AssetModelsCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete an asset model');
- // 6 is the only one without an assigned asset. This is fragile.
- $I->amOnPage(route('models.destroy', $I->getEmptyModelId()));
- $I->seeElement('.alert-success');
+ $I->sendDelete(route('models.destroy', $I->getEmptyModelId()), ['_token' => csrf_token()]);
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/AssetsCest.php b/tests/functional/AssetsCest.php
index 59bf2aaf3a..18ca5edf87 100644
--- a/tests/functional/AssetsCest.php
+++ b/tests/functional/AssetsCest.php
@@ -62,7 +62,7 @@ class AssetsCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete an asset');
- $I->amOnPage(route('hardware.destroy', $I->getAssetId()));
- $I->seeElement('.alert-success');
+ $I->sendDelete(route('hardware.destroy', $I->getAssetId()), ['_token' => csrf_token()]);
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/CategoriesCest.php b/tests/functional/CategoriesCest.php
index 8e222cc2dd..994c191518 100644
--- a/tests/functional/CategoriesCest.php
+++ b/tests/functional/CategoriesCest.php
@@ -55,7 +55,7 @@ class CategoryCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete a category');
- $I->amOnPage(route('delete/category', $I->getEmptyCategoryId()));
- $I->seeElement('.alert-success');
+ $I->sendDelete(route('categories.destroy', $I->getEmptyCategoryId()), ['_token' => csrf_token()]);
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/ComponentsCest.php b/tests/functional/ComponentsCest.php
index 1c3f347e25..63e37a330b 100644
--- a/tests/functional/ComponentsCest.php
+++ b/tests/functional/ComponentsCest.php
@@ -71,7 +71,7 @@ class ComponentsCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete a component');
- $I->amOnPage(route('components.destroy', $I->getComponentId()));
- $I->seeElement('.alert-success');
+ $I->sendDelete(route('components.destroy', $I->getComponentId()), ['_token' => csrf_token()]);
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/ConsumablesCest.php b/tests/functional/ConsumablesCest.php
index f865fce9d4..85f94fd737 100644
--- a/tests/functional/ConsumablesCest.php
+++ b/tests/functional/ConsumablesCest.php
@@ -71,7 +71,7 @@ class ConsumablesCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete a consumable');
- $I->amOnPage(route('consumables.destroy', $I->getConsumableId()));
- $I->seeElement('.alert-success');
+ $I->sendDelete(route('consumables.destroy', $I->getConsumableId()), ['_token' => csrf_token()]);
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/DepreciationsCest.php b/tests/functional/DepreciationsCest.php
index 21567348ce..db0114518d 100644
--- a/tests/functional/DepreciationsCest.php
+++ b/tests/functional/DepreciationsCest.php
@@ -59,7 +59,7 @@ class DepreciationCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete a depreciation');
- $I->amOnPage(route('depreciations.destroy', $I->getDepreciationId()));
- $I->seeElement('.alert-success');
+ $I->sendDelete(route('depreciations.destroy', $I->getDepreciationId()), ['_token' => csrf_token()]);
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/GroupsCest.php b/tests/functional/GroupsCest.php
index e820ca0bd8..b8bc85d523 100644
--- a/tests/functional/GroupsCest.php
+++ b/tests/functional/GroupsCest.php
@@ -57,6 +57,8 @@ class GroupsCest
$I->wantTo('Ensure I can delete a group');
$I->amOnPage(route('delete/group', Group::doesntHave('users')->first()->id));
$I->seeElement('.alert-success');
+ // $I->sendDelete(route('delete/group', Group::doesntHave('users')->first()->id), ['_token' => csrf_token()]);
+ // $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/LicensesCest.php b/tests/functional/LicensesCest.php
index 7a049ae154..15bca2d13d 100644
--- a/tests/functional/LicensesCest.php
+++ b/tests/functional/LicensesCest.php
@@ -79,8 +79,8 @@ class licensesCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete a license');
- $I->amOnPage(route('licenses.destroy', License::doesntHave('assignedUsers')->first()->id));
- $I->seeElement('.alert-success');
+ $I->sendDelete(route('licenses.destroy', License::doesntHave('assignedUsers')->first()->id), ['_token' => csrf_token()]);
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/LocationsCest.php b/tests/functional/LocationsCest.php
index cc38af639a..75be76bc6f 100644
--- a/tests/functional/LocationsCest.php
+++ b/tests/functional/LocationsCest.php
@@ -67,7 +67,8 @@ class LocationsCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete a location');
- $I->amOnPage(route('locations.destroy', Location::doesntHave('assets')->doesntHave('assignedAssets')->first()->id));
- $I->seeElement('.alert-success');
+ $location = factory(App\Models\Location::class, 'location')->create();
+ $I->sendDelete(route('locations.destroy', $location->id), ['_token' => csrf_token()]);
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/ManufacturersCest.php b/tests/functional/ManufacturersCest.php
index 131ba59970..cf34539185 100644
--- a/tests/functional/ManufacturersCest.php
+++ b/tests/functional/ManufacturersCest.php
@@ -57,11 +57,11 @@ class ManufacturersCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete a manufacturer');
- $I->amOnPage(route('manufacturers.destroy', Manufacturer::doesntHave('models')
- ->doesntHave('accessories')
- ->doesntHave('consumables')
- ->doesntHave('licenses')->first()->id
- ));
- $I->seeElement('.alert-success');
+ $manufacturerId = Manufacturer::doesntHave('models')
+ ->doesntHave('accessories')
+ ->doesntHave('consumables')
+ ->doesntHave('licenses')->first()->id;
+ $I->sendDelete(route('manufacturers.destroy', $manufacturerId), ['_token' => csrf_token()]);
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/StatusLabelsCest.php b/tests/functional/StatusLabelsCest.php
index a00eb00217..391f58f0ee 100644
--- a/tests/functional/StatusLabelsCest.php
+++ b/tests/functional/StatusLabelsCest.php
@@ -62,7 +62,7 @@ class StatusLabelsCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete a Status Label');
- $I->amOnPage(route('statuslabels.destroy', Statuslabel::doesntHave('assets')->first()->id));
- $I->seeElement('.alert-success');
+ $I->sendDelete(route('statuslabels.destroy', Statuslabel::doesntHave('assets')->first()->id), ['_token' => csrf_token()]);
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/SuppliersCest.php b/tests/functional/SuppliersCest.php
index 1461595efe..be04e993b9 100644
--- a/tests/functional/SuppliersCest.php
+++ b/tests/functional/SuppliersCest.php
@@ -69,7 +69,7 @@ class SuppliersCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete a supplier');
- $I->amOnPage(route('suppliers.destroy', Supplier::doesntHave('assets')->doesntHave('licenses')->first()->id));
- $I->seeElement('.alert-success');
+ $I->sendDelete(route('suppliers.destroy', Supplier::doesntHave('assets')->doesntHave('licenses')->first()->id), ['_token' => csrf_token()]);
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/functional/UsersCest.php b/tests/functional/UsersCest.php
index aaaee36482..3eee506825 100644
--- a/tests/functional/UsersCest.php
+++ b/tests/functional/UsersCest.php
@@ -92,13 +92,13 @@ class UsersCest
public function allowsDelete(FunctionalTester $I)
{
$I->wantTo('Ensure I can delete a user');
- $I->amOnPage(route('users.destroy', User::doesntHave('assets')
- ->doesntHave('accessories')
- ->doesntHave('consumables')
- ->doesntHave('licenses')
- ->where('username', '!=', 'snipeit')
- ->first()->id
- ));
- $I->seeElement('.alert-success');
+ $userId = User::doesntHave('assets')
+ ->doesntHave('accessories')
+ ->doesntHave('consumables')
+ ->doesntHave('licenses')
+ ->where('username', '!=', 'snipeit')
+ ->first()->id;
+ $I->sendDelete(route('users.destroy', $userId), ['_token' => csrf_token()]);
+ $I->seeResponseCodeIs(200);
}
}
diff --git a/tests/unit/PermissionsTest.php b/tests/unit/PermissionsTest.php
new file mode 100644
index 0000000000..511f6cda1a
--- /dev/null
+++ b/tests/unit/PermissionsTest.php
@@ -0,0 +1,437 @@
+<?php
+
+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 Illuminate\Foundation\Testing\DatabaseMigrations;
+use Illuminate\Foundation\Testing\DatabaseTransactions;
+use Illuminate\Foundation\Testing\WithoutMiddleware;
+
+class PermissionsTest extends TestCase
+{
+ // use DatabaseMigrations;
+ use DatabaseTransactions;
+ public function setUp()
+ {
+ parent::setUp();
+ $this->hardwareId = Asset::first()->id;
+ $this->noHardware = [
+ route('hardware.index') => 403,
+ route('hardware.create') => 403,
+ route('hardware.edit', $this->hardwareId) => 403,
+ route('hardware.show', $this->hardwareId) => 403,
+ ];
+
+ $this->licenseId = License::first()->id;
+ $this->noLicenses = [
+ route('licenses.index') => 403,
+ route('licenses.create') => 403,
+ route('licenses.edit', $this->licenseId) => 403,
+ route('licenses.show', $this->licenseId) => 403,
+ ];
+
+ $this->accessoryId = Accessory::first()->id;
+ $this->noAccessories = [
+ route('accessories.index') => 403,
+ route('accessories.create') => 403,
+ route('accessories.edit', $this->accessoryId) => 403,
+ route('accessories.show', $this->accessoryId) => 403,
+ ];
+
+ $this->consumableId = Consumable::first()->id;
+ $this->noConsumables = [
+ route('consumables.index') => 403,
+ route('consumables.create') => 403,
+ route('consumables.edit', $this->consumableId) => 403,
+ route('consumables.show', $this->consumableId) => 403,
+ ];
+
+ $this->componentId = Component::first()->id;
+ $this->noComponents = [
+ route('components.index') => 403,
+ route('components.create') => 403,
+ route('components.edit', $this->componentId) => 403,
+ route('components.show', $this->componentId) => 403,
+ ];
+
+ $this->userId = User::first()->id;
+ $this->noUsers = [
+ route('users.index') => 403,
+ route('users.create') => 403,
+ route('users.edit', $this->userId) => 403,
+ route('users.show', $this->userId) => 403,
+ ];
+
+ }
+
+ public function tearDown()
+ {
+ }
+ private $noHardware;
+ private $noLicenses;
+ private $noAccessories;
+ private $noConsumables;
+ private $noComponents;
+ private $noUsers;
+
+ // An existing id for each type;
+ private $hardwareId;
+ private $licenseId;
+ private $accessoryId;
+ private $consumableId;
+ private $componentId;
+ private $userId;
+ // tests
+ /**
+ * @test
+ */
+ public function a_user_with_no_permissions_sees_nothing()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->create();
+ $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
+ // $permissions = $this->noHardware;
+ $this->hitRoutes($permissions, $u);
+
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_view_asset_permissions_can_view_assets()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('view-assets')->create();
+ $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('hardware.index') => 200,
+ route('hardware.create') => 403,
+ route('hardware.edit', $this->hardwareId) => 403,
+ route('hardware.show', $this->hardwareId) => 200,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_create_asset_permissions_can_create_assets()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('create-assets')->create();
+ $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('hardware.index') => 403,
+ route('hardware.create') => 200,
+ route('hardware.edit', $this->hardwareId) => 403,
+ route('hardware.show', $this->hardwareId) => 403,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_edit_assets_permissions_can_edit_assets()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('edit-assets')->create();
+
+ $permissions = $this->noLicenses + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('hardware.index') => 403,
+ route('hardware.create') => 403,
+ route('hardware.edit', $this->hardwareId) => 200,
+ route('hardware.show', $this->hardwareId) => 403,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_view_licenses_permissions_can_view_licenses()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('view-licenses')->create();
+ $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('licenses.index') => 200,
+ route('licenses.create') => 403,
+ route('licenses.edit', $this->licenseId) => 403,
+ route('licenses.show', $this->licenseId) => 200,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_create_licenses_permissions_can_create_licenses()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('create-licenses')->create();
+ $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('licenses.index') => 403,
+ route('licenses.create') => 200,
+ route('licenses.edit', $this->licenseId) => 403,
+ route('licenses.show', $this->licenseId) => 403,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_edit_licenses_permissions_can_edit_licenses()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('edit-licenses')->create();
+ $permissions = $this->noHardware + $this->noAccessories + $this->noConsumables + $this->noComponents + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('licenses.index') => 403,
+ route('licenses.create') => 403,
+ route('licenses.edit', $this->licenseId) => 200,
+ route('licenses.show', $this->licenseId) => 403,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_view_accessories_permissions_can_view_accessories()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('view-accessories')->create();
+
+ $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('accessories.index') => 200,
+ route('accessories.create') => 403,
+ route('accessories.edit', $this->accessoryId) => 403,
+ route('accessories.show', $this->accessoryId) => 200,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_create_accessories_permissions_can_create_accessories()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('create-accessories')->create();
+
+ $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('accessories.index') => 403,
+ route('accessories.create') => 200,
+ route('accessories.edit', $this->accessoryId) => 403,
+ route('accessories.show', $this->accessoryId) => 403,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_edit_accessories_permissions_can_edit_accessories()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('edit-accessories')->create();
+
+ $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('accessories.index') => 403,
+ route('accessories.create') => 403,
+ route('accessories.edit', $this->accessoryId) => 200,
+ route('accessories.show', $this->accessoryId) => 403,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_view_consumables_permissions_can_view_consumables()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('view-consumables')->create();
+
+ $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('consumables.index') => 200,
+ route('consumables.create') => 403,
+ route('consumables.edit', $this->consumableId) => 403,
+ route('consumables.show', $this->consumableId) => 200,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_create_consumables_permissions_can_create_consumables()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('create-consumables')->create();
+
+ $permissions = $this->noHardware + $this->noLicenses + $this->noConsumables + $this->noComponents + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('consumables.index') => 403,
+ route('consumables.create') => 200,
+ route('consumables.edit', $this->consumableId) => 403,
+ route('consumables.show', $this->consumableId) => 403,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_edit_consumables_permissions_can_edit_consumables()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('edit-consumables')->create();
+
+ $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories + $this->noComponents + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('consumables.index') => 403,
+ route('consumables.create') => 403,
+ route('consumables.edit', $this->consumableId) => 200,
+ route('consumables.show', $this->consumableId) => 403,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_view_users_permissions_can_view_users()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('view-users')->create();
+
+ $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noComponents;
+
+ $permissions = array_merge($permissions, [
+ route('users.index') => 200,
+ route('users.create') => 403,
+ route('users.edit', $this->userId) => 403,
+ route('users.show', $this->userId) => 200,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_create_users_permissions_can_create_users()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('create-users')->create();
+
+ $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noComponents;
+
+ $permissions = array_merge($permissions, [
+ route('users.index') => 403,
+ route('users.create') => 200,
+ route('users.edit', $this->userId) => 403,
+ route('users.show', $this->userId) => 403,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_edit_users_permissions_can_edit_users()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('edit-users')->create();
+
+ $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noComponents;
+
+ $permissions = array_merge($permissions, [
+ route('users.index') => 403,
+ route('users.create') => 403,
+ route('users.edit', $this->userId) => 200,
+ route('users.show', $this->userId) => 403,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_view_components_permissions_can_view_components()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('view-components')->create();
+
+ $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('components.index') => 200,
+ route('components.create') => 403,
+ route('components.edit', $this->componentId) => 403,
+ route('components.show', $this->componentId) => 200,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_create_components_permissions_can_create_components()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('create-components')->create();
+ $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('components.index') => 403,
+ route('components.create') => 200,
+ route('components.edit', $this->componentId) => 403,
+ route('components.show', $this->componentId) => 403,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ /**
+ * @test
+ */
+ public function a_user_with_edit_components_permissions_can_edit_components()
+ {
+ $u = factory(App\Models\User::class, 'valid-user')->states('edit-components')->create();
+
+ $permissions = $this->noHardware + $this->noLicenses + $this->noAccessories +$this->noConsumables + $this->noUsers;
+
+ $permissions = array_merge($permissions, [
+ route('components.index') => 403,
+ route('components.create') => 403,
+ route('components.edit', $this->componentId) => 200,
+ route('components.show', $this->componentId) => 403,
+ ]);
+ $this->hitRoutes($permissions, $u);
+ }
+
+ private function hitRoutes(array $routes, User $user)
+ {
+ $this->actingAs($user);
+ // dd($user);
+ foreach ($routes as $route => $response) {
+ // $this->log($route);
+// if (strpos($route, 'edit') || strpos($route, 'show') || strpos($route, 'destroy')) {
+// // ($this->get(route($route,2))->dump());
+// $this->get(route($route, 1))
+// ->assertResponseStatus($response);
+// } else {
+ // dd($this->get(route($route)));
+ // echo($this->get(route($route))->dump());
+ $this->get($route)
+ ->assertResponseStatus($response);
+// }
+ }
+ }
+
+}