Skip to content

A free open source IT asset/license management system

Removed closures from routes files so that we can allow people to cache routes for performance optimization

snipeb019e6e95001
diff --git a/app/Http/Controllers/Api/StatuslabelsController.php b/app/Http/Controllers/Api/StatuslabelsController.php
index ceeea44c4f..46159d053d 100644
--- a/app/Http/Controllers/Api/StatuslabelsController.php
+++ b/app/Http/Controllers/Api/StatuslabelsController.php
@@ -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] [<[email protected]>]
+ * @since [v4.0]
+ * @return Bool
+ */
+ public function checkIfDeployable($id) {
+ $statuslabel = Statuslabel::findOrFail($id);
+ if ($statuslabel->getStatuslabelType()=='deployable') {
+ return '1';
+ }
+
+ return '0';
+ }
}
diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php
index 8b71b1c01c..5a7ecbf6c4 100755
--- a/app/Http/Controllers/ProfileController.php
+++ b/app/Http/Controllers/ProfileController.php
@@ -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] [<[email protected]>]
+ * @since [v4.0]
+ * @return View
+ */
+ public function api() {
+ return view('account/api');
+ }
}
diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php
index d8344d5e6c..c478a633b2 100755
--- a/app/Http/Controllers/SettingsController.php
+++ b/app/Http/Controllers/SettingsController.php
@@ -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] [<[email protected]>]
+ * @since [v4.0]
+ * @return View
+ */
+ public function api() {
+ return view('settings/api');
+ }
}
diff --git a/app/Models/Statuslabel.php b/app/Models/Statuslabel.php
index 20c67558d0..f82072d320 100755
--- a/app/Models/Statuslabel.php
+++ b/app/Models/Statuslabel.php
@@ -63,6 +63,7 @@ class Statuslabel extends SnipeModel
}
}
+
public static function getStatuslabelTypesForDB($type)
{
if ($type == 'pending') {
diff --git a/routes/api.php b/routes/api.php
index 5e3a5675e4..ff72ae9fec 100644
--- a/routes/api.php
+++ b/routes/api.php
@@ -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 () {
diff --git a/routes/web.php b/routes/web.php
index 93240d297e..4c9c0dadf3 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -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('/');
-});