A free open source IT asset/license management system
Small refactor for better selectlist permissions
snipe259595fd50de
diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.phpindex e76b89bb77..167ed056d5 100644--- a/app/Providers/AuthServiceProvider.php+++ b/app/Providers/AuthServiceProvider.php@@ -271,27 +271,63 @@ class AuthServiceProvider extends ServiceProvider|| $user->can('view', Depreciation::class);});- // This determines whether or not an API user should be able to get the selectlists.+ // This determines whether or not a 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+ // to the logged in user, but creating assets, licenses, etc won't work// if the user can't view and interact with the select lists.+ // Selectlists back form dropdowns across the app. A caller who+ // can update, create, or check out any resource needs the+ // dropdowns those forms depend on. A pure view-only caller+ // does not: they browse tables via the index endpoints, not+ // the selectlist endpoints. The pre-existing gate covered+ // Asset / License / Component / Consumable / Accessory / User+ // but silently 403'd anyone whose only permission was on one+ // of the other admin resources (locations.edit ran into this on+ // the parent + manager pickers). Extending the same+ // update-or-create shape to every listable resource fixes+ // that without granting view-only callers dropdowns they'd+ // never have to use.Gate::define('view.selectlists', function ($user) {- return $user->can('update', Asset::class)- || $user->can('create', Asset::class)- || $user->can('checkout', Asset::class)- || $user->can('checkin', Asset::class)- || $user->can('audit', Asset::class)- || $user->can('update', License::class)- || $user->can('create', License::class)- || $user->can('update', Component::class)- || $user->can('create', Component::class)- || $user->can('update', Consumable::class)- || $user->can('create', Consumable::class)- || $user->can('update', Accessory::class)- || $user->can('create', Accessory::class)- || $user->can('update', User::class)- || $user->can('create', User::class)- || ($user->hasAccess('reports.view'));+ $resources = [+ Asset::class,+ License::class,+ Component::class,+ Consumable::class,+ Accessory::class,+ User::class,+ Location::class,+ Category::class,+ Manufacturer::class,+ Supplier::class,+ Company::class,+ Department::class,+ Statuslabel::class,+ Depreciation::class,+ AssetModel::class,+ ];++ foreach ($resources as $resource) {+ if ($user->can('update', $resource) || $user->can('create', $resource)) {+ return true;+ }+ }++ $checkoutables = [+ Asset::class,+ Accessory::class,+ Consumable::class,+ Component::class,+ License::class,+ ];++ foreach ($checkoutables as $checkoutable) {+ if ($user->can('checkout', $checkoutable) || $user->can('checkin', $checkoutable)) {+ return true;+ }+ }++ return $user->can('audit', Asset::class)+ || $user->hasAccess('reports.view');});// This determines whether the user can edit their profile based on the setting in Admin > General