mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 14:27:33 -08:00
Removed closures from routes files so that we can allow people to cache routes for performance optimization
This commit is contained in:
parent
eea779c16d
commit
b019e6e950
|
@ -9,6 +9,7 @@ use App\Models\Statuslabel;
|
|||
use App\Models\Asset;
|
||||
use App\Http\Transformers\DatatablesTransformer;
|
||||
use App\Http\Transformers\AssetsTransformer;
|
||||
use PhpParser\Node\Expr\Cast\Bool_;
|
||||
|
||||
class StatuslabelsController extends Controller
|
||||
{
|
||||
|
@ -194,4 +195,24 @@ class StatuslabelsController extends Controller
|
|||
return (new AssetsTransformer)->transformAssets($assets, $total);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a boolean response based on whether the status label
|
||||
* is one that is deployable.
|
||||
*
|
||||
* This is used by the hardware create/edit view to determine whether
|
||||
* we should provide a dropdown of users for them to check the asset out to.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @return Bool
|
||||
*/
|
||||
public function checkIfDeployable($id) {
|
||||
$statuslabel = Statuslabel::findOrFail($id);
|
||||
if ($statuslabel->getStatuslabelType()=='deployable') {
|
||||
return '1';
|
||||
}
|
||||
|
||||
return '0';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ class ProfileController extends Controller
|
|||
*/
|
||||
public function getIndex()
|
||||
{
|
||||
// Get the user information
|
||||
$user = Auth::user();
|
||||
$location_list = Helper::locationsList();
|
||||
return View::make('account/profile', compact('user'))->with('location_list', $location_list);
|
||||
|
@ -44,10 +43,7 @@ class ProfileController extends Controller
|
|||
public function postIndex()
|
||||
{
|
||||
|
||||
// Grab the user
|
||||
$user = Auth::user();
|
||||
|
||||
// Update the user information
|
||||
$user->first_name = Input::get('first_name');
|
||||
$user->last_name = Input::get('last_name');
|
||||
$user->website = Input::get('website');
|
||||
|
@ -55,7 +51,6 @@ class ProfileController extends Controller
|
|||
$user->gravatar = Input::get('gravatar');
|
||||
$user->locale = Input::get('locale');
|
||||
|
||||
|
||||
if ((Gate::allows('self.two_factor')) && ((Setting::getSettings()->two_factor_enabled=='1') && (!config('app.lock_passwords')))) {
|
||||
$user->two_factor_optin = Input::get('two_factor_optin', '0');
|
||||
}
|
||||
|
@ -77,4 +72,19 @@ class ProfileController extends Controller
|
|||
}
|
||||
return redirect()->back()->withInput()->withErrors($user->getErrors());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a page with the API token generation interface.
|
||||
*
|
||||
* We created a controller method for this because closures aren't allowed
|
||||
* in the routes file if you want to be able to cache the routes.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @return View
|
||||
*/
|
||||
public function api() {
|
||||
return view('account/api');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -598,4 +598,18 @@ class SettingsController extends Controller
|
|||
return redirect()->back()->with('error', trans('general.feature_disabled'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a page with the API token generation interface.
|
||||
*
|
||||
* We created a controller method for this because closures aren't allowed
|
||||
* in the routes file if you want to be able to cache the routes.
|
||||
*
|
||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||
* @since [v4.0]
|
||||
* @return View
|
||||
*/
|
||||
public function api() {
|
||||
return view('settings/api');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ class Statuslabel extends SnipeModel
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static function getStatuslabelTypesForDB($type)
|
||||
{
|
||||
if ($type == 'pending') {
|
||||
|
|
|
@ -150,21 +150,12 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
|||
Route::get('{id}/assetlist',
|
||||
[ 'as' => 'api.statuslabels.assets', 'uses' => 'StatuslabelsController@assets' ]);
|
||||
|
||||
Route::get('{id}/deployable', function ($statuslabelId) {
|
||||
Route::get('{id}/deployable',
|
||||
[ 'as' => 'api.statuslabels.deployable', 'uses' => 'StatuslabelsController@checkIfDeployable' ]);
|
||||
|
||||
$statuslabel = Statuslabel::find($statuslabelId);
|
||||
if (( $statuslabel->deployable == '1' ) && ( $statuslabel->pending != '1' )
|
||||
&& ( $statuslabel->archived != '1' )
|
||||
) {
|
||||
return '1';
|
||||
} else {
|
||||
return '0';
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Pie chart for dashboard
|
||||
|
||||
Route::get('assets', [ 'as' => 'api.statuslabels.assets.bytype', 'uses' => 'StatuslabelsController@getAssetCountByStatuslabel' ]);
|
||||
|
||||
});
|
||||
|
@ -263,6 +254,11 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
|||
|
||||
Route::get('{locationID}/users', array('as'=>'api.locations.viewusers', 'uses'=>'LocationsController@getDataViewUsers'));
|
||||
Route::get('{locationID}/assets', array('as'=>'api.locations.viewassets', 'uses'=>'LocationsController@getDataViewAssets'));
|
||||
|
||||
// Do we actually still need this, now that we have an API?
|
||||
Route::get('{id}/check',
|
||||
[ 'as' => 'api.locations.check', 'uses' => 'LocationsController@show' ]);
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
@ -290,16 +286,6 @@ Route::group(['prefix' => 'v1','namespace' => 'Api'], function () {
|
|||
Route::get('list', [ 'as' => 'api.licenses.list', 'uses' => 'LicensesController@getDatatable' ]);
|
||||
});
|
||||
|
||||
/*---Locations API---*/
|
||||
Route::group([ 'prefix' => 'locations' ], function () {
|
||||
|
||||
Route::get('{locationID}/check', function ($locationID) {
|
||||
|
||||
$location = Location::find($locationID);
|
||||
|
||||
return $location;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Route::group([ 'prefix' => 'fields' ], function () {
|
||||
|
|
|
@ -110,16 +110,7 @@ Route::group([ 'prefix' => 'admin','middleware' => ['web','auth']], function ()
|
|||
# Settings
|
||||
Route::group([ 'prefix' => 'app' ], function () {
|
||||
|
||||
Route::get(
|
||||
'api',
|
||||
array('as' => 'settings.api',
|
||||
function () {
|
||||
return view('settings/api');
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
Route::get('api', [ 'as' => 'settings.api', 'uses' => 'SettingsController@api' ]);
|
||||
Route::post('purge', ['as' => 'purge', 'uses' => 'SettingsController@postPurge']);
|
||||
Route::get('edit', [ 'as' => 'edit/settings', 'uses' => 'SettingsController@getEdit' ]);
|
||||
Route::post('edit', 'SettingsController@postEdit');
|
||||
|
@ -188,15 +179,7 @@ Route::group([ 'prefix' => 'account', 'middleware' => ['web', 'auth']], function
|
|||
# Profile
|
||||
Route::get('profile', [ 'as' => 'profile', 'uses' => 'ProfileController@getIndex' ]);
|
||||
Route::post('profile', 'ProfileController@postIndex');
|
||||
|
||||
Route::get(
|
||||
'api',
|
||||
array('as' => 'user.api',
|
||||
function () {
|
||||
return view('account/api');
|
||||
}
|
||||
)
|
||||
);
|
||||
Route::get('api', [ 'as' => 'user.api', 'uses' => 'ProfileController@api' ]);
|
||||
|
||||
# View Assets
|
||||
Route::get('view-assets', [ 'as' => 'view-assets', 'uses' => 'ViewAssetsController@getIndex' ]);
|
||||
|
@ -411,6 +394,3 @@ Route::group(['middleware' => 'web'], function () {
|
|||
|
||||
});
|
||||
|
||||
Route::get('home', function () {
|
||||
return redirect('/');
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue