mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-10 07:34:06 -08:00
c0c02eebd2
* Toggles the disabled state of auto_increment_prefix To insert a prefix you had to toggle the checkbox, save the settings and reload. With this script it is immediate. Fixes #1390 * Delete asset image: made checkbox more visible Related to #3153 * Added personal-access-token component * Created basic API testing configuration * First version of /components endpoind cest * On-the-fly bearer token generation * Completed testing of PATCH and PUT methods * Added /components/{id}/assets route with tests * Updated route and dataTable in view * Completed test assertion * Added links to assets in ComponentsAssets view * Linked Company in AssetView page * Fixed purchase_cost format expectation in ApiComponentsCest * Refactored api routes file Sorted all prefixes in alphabetical order, removed duplicate routes. For every prefix I placed first Route::resource and then any additional route in a Route::group. Expanded arrays for readability and consistency. Removed useless calls as create and edit everywhere. * Refactored and added one more test to ApiComponentsAssetsCest * Marked one test as incomplete, 404 response should return json * Fixed value expectation * Refactored getToken() * Added API debugging routes * Added more information to ValidationException reporting Now the payload contains the validation errors for each invalid attribute. * /apitests: refactored expectations in component assertions * Created ApiAssetsCest * /apitests: Cleanup in Exceptions/Handler * Reverted change to use * Marked two tests as incomplete, looking for solutions
505 lines
15 KiB
PHP
505 lines
15 KiB
PHP
<?php
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| API Routes
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| Here is where you can register API routes for your application. These
|
|
| routes are loaded by the RouteServiceProvider within a group which
|
|
| is assigned the "api" middleware group. Enjoy building your API!
|
|
|
|
|
*/
|
|
|
|
|
|
Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
|
|
|
/*--- Accessories API ---*/
|
|
|
|
Route::resource('accessories', 'AccessoriesController',
|
|
['names' =>
|
|
[
|
|
'index' => 'api.accessories.index',
|
|
'show' => 'api.accessories.show',
|
|
'update' => 'api.accessories.update',
|
|
'store' => 'api.accessories.store',
|
|
'destroy' => 'api.accessories.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['accessory' => 'accessory_id']
|
|
]
|
|
); // Accessories resource
|
|
|
|
Route::group(['prefix' => 'accessories'], function () {
|
|
|
|
Route::get('{accessory}/checkedout',
|
|
[
|
|
'as' => 'api.accessories.checkedout',
|
|
'uses' => 'AccessoriesController@checkedout'
|
|
]
|
|
);
|
|
}); // Accessories group
|
|
|
|
|
|
/*--- Categories API ---*/
|
|
|
|
Route::resource('categories', 'CategoriesController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.categories.index',
|
|
'show' => 'api.categories.show',
|
|
'store' => 'api.categories.store',
|
|
'update' => 'api.categories.update',
|
|
'destroy' => 'api.categories.destroy'
|
|
],
|
|
'except' => ['edit', 'create'],
|
|
'parameters' => ['category' => 'category_id']
|
|
]
|
|
); // Categories resource
|
|
|
|
|
|
/*--- Companies API ---*/
|
|
|
|
Route::resource('companies', 'CompaniesController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.companies.index',
|
|
'show' => 'api.companies.show',
|
|
'store' => 'api.companies.store',
|
|
'update' => 'api.companies.update',
|
|
'destroy' => 'api.companies.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['component' => 'component_id']
|
|
]
|
|
); // Companies resource
|
|
|
|
|
|
/*--- Components API ---*/
|
|
|
|
Route::resource('components', 'ComponentsController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.components.index',
|
|
'show' => 'api.components.show',
|
|
'store' => 'api.components.store',
|
|
'update' => 'api.components.update',
|
|
'destroy' => 'api.components.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['component' => 'component_id']
|
|
]
|
|
); // Components resource
|
|
|
|
Route::group(['prefix' => 'components'], function () {
|
|
|
|
Route::get('{component}/assets',
|
|
[
|
|
'as' =>'api.components.assets',
|
|
'uses' => 'ComponentsController@getAssets',
|
|
]
|
|
);
|
|
}); // Components group
|
|
|
|
|
|
/*--- Consumables API ---*/
|
|
|
|
Route::resource('consumables', 'ConsumablesController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.consumables.index',
|
|
'show' => 'api.consumables.show',
|
|
'store' => 'api.consumables.store',
|
|
'update' => 'api.consumables.update',
|
|
'destroy' => 'api.consumables.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['consumable' => 'consumable_id']
|
|
]
|
|
); // Consumables resource
|
|
|
|
|
|
/*--- Depreciations API ---*/
|
|
|
|
Route::resource('depreciations', 'DepreciationsController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.depreciations.index',
|
|
'show' => 'api.depreciations.show',
|
|
'store' => 'api.depreciations.store',
|
|
'update' => 'api.depreciations.update',
|
|
'destroy' => 'api.depreciations.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['depreciation' => 'depreciation_id']
|
|
]
|
|
); // Depreciations resource
|
|
|
|
|
|
/*--- Fields API ---*/
|
|
|
|
Route::group(['prefix' => 'fields'], function () {
|
|
Route::post('fieldsets/{id}/order',
|
|
[
|
|
'as' => 'api.customfields.order',
|
|
'uses' => 'CustomFieldsController@postReorder'
|
|
]
|
|
);
|
|
}); // Fields group
|
|
|
|
|
|
/*--- Groups API ---*/
|
|
|
|
Route::resource('groups', 'GroupsController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.groups.index',
|
|
'show' => 'api.groups.show',
|
|
'store' => 'api.groups.store',
|
|
'update' => 'api.groups.update',
|
|
'destroy' => 'api.groups.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['group' => 'group_id']
|
|
]
|
|
); // Groups resource
|
|
|
|
|
|
/*--- Hardware API ---*/
|
|
|
|
Route::resource('hardware', 'AssetsController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.assets.index',
|
|
'show' => 'api.assets.show',
|
|
'store' => 'api.assets.store',
|
|
'update' => 'api.assets.update',
|
|
'destroy' => 'api.assets.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['asset' => 'asset_id']
|
|
]
|
|
); // Hardware resource
|
|
|
|
|
|
/*--- Imports API ---*/
|
|
|
|
Route::resource('imports', 'ImportController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.imports.index',
|
|
'show' => 'api.imports.show',
|
|
'store' => 'api.imports.store',
|
|
'update' => 'api.imports.update',
|
|
'destroy' => 'api.imports.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['import' => 'import_id']
|
|
]
|
|
); // Imports resource
|
|
|
|
Route::group(['prefix' => 'imports'], function () {
|
|
|
|
Route::post('process/{import}',
|
|
[
|
|
'as' => 'api.imports.importFile',
|
|
'uses'=> 'ImportController@process'
|
|
]
|
|
);
|
|
}); // Imports group
|
|
|
|
|
|
|
|
|
|
/*--- Licenses API ---*/
|
|
|
|
Route::resource('licenses', 'LicensesController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.licenses.index',
|
|
'show' => 'api.licenses.show',
|
|
'store' => 'api.licenses.store',
|
|
'update' => 'api.licenses.update',
|
|
'destroy' => 'api.licenses.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['license' => 'license_id']
|
|
]
|
|
); // Licenses resource
|
|
|
|
|
|
/*--- Locations API ---*/
|
|
|
|
Route::resource('locations', 'LocationsController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.locations.index',
|
|
'show' => 'api.locations.show',
|
|
'store' => 'api.locations.store',
|
|
'update' => 'api.locations.update',
|
|
'destroy' => 'api.locations.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['location' => 'location_id']
|
|
]
|
|
); // Locations resource
|
|
|
|
Route::group(['prefix' => 'locations'], function () {
|
|
|
|
Route::get('{location}/users',
|
|
[
|
|
'as'=>'api.locations.viewusers',
|
|
'uses'=>'LocationsController@getDataViewUsers'
|
|
]
|
|
);
|
|
|
|
Route::get('{location}/assets',
|
|
[
|
|
'as'=>'api.locations.viewassets',
|
|
'uses'=>'LocationsController@getDataViewAssets'
|
|
]
|
|
);
|
|
|
|
// Do we actually still need this, now that we have an API?
|
|
Route::get('{location}/check',
|
|
[
|
|
'as' => 'api.locations.check',
|
|
'uses' => 'LocationsController@show'
|
|
]
|
|
);
|
|
}); // Locations group
|
|
|
|
|
|
/*--- Manufacturers API ---*/
|
|
|
|
Route::resource('manufacturers', 'ManufacturersController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.manufacturers.index',
|
|
'show' => 'api.manufacturers.show',
|
|
'store' => 'api.manufacturers.store',
|
|
'update' => 'api.manufacturers.update',
|
|
'destroy' => 'api.manufacturers.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['manufacturer' => 'manufacturer_id']
|
|
]
|
|
); // Manufacturers resource
|
|
|
|
|
|
/*--- Models API ---*/
|
|
|
|
Route::resource('models', 'AssetModelsController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.models.index',
|
|
'show' => 'api.models.show',
|
|
'store' => 'api.models.store',
|
|
'update' => 'api.models.update',
|
|
'destroy' => 'api.models.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['model' => 'model_id']
|
|
]
|
|
); // Models resource
|
|
|
|
Route::group(['prefix' => 'models'], function () {
|
|
|
|
Route::get('assets',
|
|
[
|
|
'as' => 'api.models.assets',
|
|
'uses'=> 'AssetModelsController@assets'
|
|
]
|
|
);
|
|
}); // Models group
|
|
|
|
|
|
/*--- Settings API ---*/
|
|
|
|
Route::resource('settings', 'SettingsController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.settings.index',
|
|
'store' => 'api.settings.store',
|
|
'show' => 'api.settings.show',
|
|
'update' => 'api.settings.update'
|
|
],
|
|
'except' => ['create', 'edit', 'destroy'],
|
|
'parameters' => ['setting' => 'setting_id']
|
|
]
|
|
); // Settings resource
|
|
|
|
|
|
/*--- Status Labels API ---*/
|
|
|
|
Route::resource('statuslabels', 'StatuslabelsController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.statuslabels.index',
|
|
'store' => 'api.statuslabels.store',
|
|
'show' => 'api.statuslabels.show',
|
|
'update' => 'api.statuslabels.update',
|
|
'destroy' => 'api.statuslabels.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['statuslabel' => 'statuslabel_id']
|
|
]
|
|
);
|
|
|
|
Route::group(['prefix' => 'statuslabels'], function () {
|
|
|
|
Route::get('{statuslabel}/assetlist',
|
|
[
|
|
'as' => 'api.statuslabels.assets',
|
|
'uses' => 'StatuslabelsController@assets'
|
|
]
|
|
);
|
|
|
|
Route::get('{statuslabel}/deployable',
|
|
[
|
|
'as' => 'api.statuslabels.deployable',
|
|
'uses' => 'StatuslabelsController@checkIfDeployable'
|
|
]
|
|
);
|
|
|
|
// Pie chart for dashboard
|
|
Route::get('assets',
|
|
[
|
|
'as' => 'api.statuslabels.assets.bytype',
|
|
'uses' => 'StatuslabelsController@getAssetCountByStatuslabel'
|
|
]
|
|
);
|
|
}); // Status labels group
|
|
|
|
|
|
/*--- Suppliers API ---*/
|
|
|
|
Route::resource('suppliers', 'SuppliersController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.suppliers.index',
|
|
'show' => 'api.suppliers.show',
|
|
'store' => 'api.suppliers.store',
|
|
'update' => 'api.suppliers.update',
|
|
'destroy' => 'api.suppliers.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['supplier' => 'supplier_id']
|
|
]
|
|
); // Suppliers resource
|
|
|
|
Route::group(['prefix' => 'suppliers'], function () {
|
|
|
|
Route::get('list',
|
|
[
|
|
'as'=>'api.suppliers.list',
|
|
'uses'=>'SuppliersController@getDatatable'
|
|
]
|
|
);
|
|
}); // Suppliers group
|
|
|
|
|
|
/*--- Users API ---*/
|
|
|
|
Route::resource('users', 'UsersController',
|
|
[
|
|
'names' =>
|
|
[
|
|
'index' => 'api.users.index',
|
|
'show' => 'api.users.show',
|
|
'store' => 'api.users.store',
|
|
'update' => 'api.users.update',
|
|
'destroy' => 'api.users.destroy'
|
|
],
|
|
'except' => ['create', 'edit'],
|
|
'parameters' => ['user' => 'user_id']
|
|
]
|
|
); // Users resource
|
|
|
|
Route::group([ 'prefix' => 'users' ], function () {
|
|
|
|
Route::post('two_factor_reset',
|
|
[
|
|
'as' => 'api.users.two_factor_reset',
|
|
'uses' => 'UsersController@postTwoFactorReset'
|
|
]
|
|
);
|
|
|
|
Route::get('list/{status?}',
|
|
[
|
|
'as' => 'api.users.list',
|
|
'uses' => 'UsersController@getDatatable'
|
|
]
|
|
);
|
|
|
|
Route::get('{user}/assets',
|
|
[
|
|
'as' => 'api.users.assetlist',
|
|
'uses' => 'UsersController@getAssetList'
|
|
]
|
|
);
|
|
|
|
Route::post('{user}/upload',
|
|
[
|
|
'as' => 'api.users.uploads',
|
|
'uses' => 'UsersController@postUpload'
|
|
]
|
|
);
|
|
}); // Users group
|
|
|
|
|
|
### DEBUG ROUTES ###
|
|
|
|
Route::group(['prefix' => 'me'], function () {
|
|
|
|
if (env('APP_ENV') == 'production') {
|
|
abort(404);
|
|
}
|
|
|
|
Route::get('/profile', function () {
|
|
return json_encode([
|
|
'name' => \Auth::user()->first_name . ' ' . \Auth::user()->last_name,
|
|
'email' => \Auth::user()->email,
|
|
]);
|
|
});
|
|
|
|
Route::get('/authenticated', function () {
|
|
return json_encode([
|
|
'authenticated' => \Auth::check()
|
|
]);
|
|
});
|
|
|
|
Route::get('/permissions/{scope}/{action}', function ($scope, $action) {
|
|
return json_encode([
|
|
'permission' => $scope . '.' . $action,
|
|
'authorized' => \Auth::user()->hasAccess($scope . '.' . $action),
|
|
]);
|
|
});
|
|
|
|
Route::get('/permissions', function () {
|
|
return json_encode([
|
|
'permissions' => Auth::user()->permissions
|
|
]);
|
|
});
|
|
|
|
|
|
});
|
|
});
|