Merge pull request #10662 from snipe/fixes/tighter_security_on_select_lists

Added additional gate for selectlists
This commit is contained in:
snipe 2022-02-11 12:48:55 -08:00 committed by GitHub
commit 10c26f38c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 26 additions and 3 deletions

View file

@ -234,6 +234,7 @@ class AssetModelsController extends Controller
public function selectlist(Request $request) public function selectlist(Request $request)
{ {
$this->authorize('view.selectlists');
$assetmodels = AssetModel::select([ $assetmodels = AssetModel::select([
'models.id', 'models.id',
'models.name', 'models.name',

View file

@ -148,7 +148,7 @@ class CategoriesController extends Controller
*/ */
public function selectlist(Request $request, $category_type = 'asset') public function selectlist(Request $request, $category_type = 'asset')
{ {
$this->authorize('view.selectlists');
$categories = Category::select([ $categories = Category::select([
'id', 'id',
'name', 'name',

View file

@ -159,7 +159,7 @@ class CompaniesController extends Controller
*/ */
public function selectlist(Request $request) public function selectlist(Request $request)
{ {
$this->authorize('view.selectlists');
$companies = Company::select([ $companies = Company::select([
'companies.id', 'companies.id',
'companies.name', 'companies.name',

View file

@ -168,6 +168,7 @@ class DepartmentsController extends Controller
public function selectlist(Request $request) public function selectlist(Request $request)
{ {
$this->authorize('view.selectlists');
$departments = Department::select([ $departments = Department::select([
'id', 'id',
'name', 'name',

View file

@ -223,6 +223,8 @@ class LocationsController extends Controller
public function selectlist(Request $request) public function selectlist(Request $request)
{ {
$this->authorize('view.selectlists');
$locations = Location::select([ $locations = Location::select([
'locations.id', 'locations.id',
'locations.name', 'locations.name',

View file

@ -155,6 +155,7 @@ class ManufacturersController extends Controller
public function selectlist(Request $request) public function selectlist(Request $request)
{ {
$this->authorize('view.selectlists');
$manufacturers = Manufacturer::select([ $manufacturers = Manufacturer::select([
'id', 'id',
'name', 'name',

View file

@ -155,6 +155,8 @@ class SuppliersController extends Controller
public function selectlist(Request $request) public function selectlist(Request $request)
{ {
$this->authorize('view.selectlists');
$suppliers = Supplier::select([ $suppliers = Supplier::select([
'id', 'id',
'name', 'name',

View file

@ -156,6 +156,8 @@ class AuthServiceProvider extends ServiceProvider
return $user->hasAccess('self.checkout_assets'); return $user->hasAccess('self.checkout_assets');
}); });
// This is largely used to determine whether to display the gear icon sidenav
// in the left-side navigation
Gate::define('backend.interact', function ($user) { Gate::define('backend.interact', function ($user) {
return $user->can('view', Statuslabel::class) return $user->can('view', Statuslabel::class)
|| $user->can('view', AssetModel::class) || $user->can('view', AssetModel::class)
@ -170,5 +172,19 @@ class AuthServiceProvider extends ServiceProvider
|| $user->can('view', CustomFieldset::class) || $user->can('view', CustomFieldset::class)
|| $user->can('view', Depreciation::class); || $user->can('view', Depreciation::class);
}); });
// This determines whether or not an API user should be able to get the selectlists.
// This can seem a little confusing, since view properties may not have been granted
// to the logged in API user, but creating assets, licenses, etc won't work
// if the user can't view and interact with the select lists.
Gate::define('view.selectlists', function ($user) {
return $user->can(['create','update'], Asset::class)
|| $user->can(['create','update'], License::class)
|| $user->can(['create','update'], Component::class)
|| $user->can(['create','update'], Consumable::class)
|| $user->can(['create','update'], Accessory::class)
|| $user->can(['create','update'], User::class);
});
} }
} }