snipe / snipe-it

A free open source IT asset/license management system
https://snipeitapp.com
GNU Affero General Public License v3.0
11.09k stars 3.18k forks source link

Unable to view assets from standard user #9224

Open auxilioit opened 3 years ago

auxilioit commented 3 years ago

Expected Behavior (or desired behavior if a feature request)

For non-super user to be able to view assets assigned to their company.


Actual Behavior

No assets appear on load.

I have made changes to App\Models\Company Line 84; return $query->where($table.$column, '=', $company_id); > return $query->where($column, '=', $company_id);

Removing $table resolves the issue.


Please confirm you have done the following before posting your bug report:


Provide answers to these questions:

Received via API:

{ "message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'snipe_snipe_assets.company_id' in 'where clause' (SQL: select count(*) as aggregate from snipe_assets where snipe_snipe_assets.company_id = 3 and snipe_assets.deleted_at is null)", "exception": "Illuminate\Database\QueryException", "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php", "line": 669, "trace": [ { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php", "line": 629, "function": "runQueryCallback", "class": "Illuminate\Database\Connection", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Database/Connection.php", "line": 338, "function": "run", "class": "Illuminate\Database\Connection", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php", "line": 2159, "function": "select", "class": "Illuminate\Database\Connection", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php", "line": 2147, "function": "runSelect", "class": "Illuminate\Database\Query\Builder", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php", "line": 2619, "function": "Illuminate\Database\Query\{closure}", "class": "Illuminate\Database\Query\Builder", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php", "line": 2148, "function": "onceWithColumns", "class": "Illuminate\Database\Query\Builder", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php", "line": 2546, "function": "get", "class": "Illuminate\Database\Query\Builder", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php", "line": 2474, "function": "aggregate", "class": "Illuminate\Database\Query\Builder", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php", "line": 1385, "function": "count", "class": "Illuminate\Database\Query\Builder", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/app/Http/Controllers/Api/AssetsController.php", "line": 147, "function": "__call", "class": "Illuminate\Database\Eloquent\Builder", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Routing/Controller.php", "line": 54, "function": "index", "class": "App\Http\Controllers\Api\AssetsController", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php", "line": 45, "function": "callAction", "class": "Illuminate\Routing\Controller", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Routing/Route.php", "line": 219, "function": "dispatch", "class": "Illuminate\Routing\ControllerDispatcher", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Routing/Route.php", "line": 176, "function": "runController", "class": "Illuminate\Routing\Route", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 681, "function": "run", "class": "Illuminate\Routing\Route", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 130, "function": "Illuminate\Routing\{closure}", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php", "line": 43, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Auth\Middleware\Authenticate", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 105, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 683, "function": "then", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 658, "function": "runRouteWithinStack", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 624, "function": "runRoute", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Routing/Router.php", "line": 613, "function": "dispatchToRoute", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 170, "function": "dispatch", "class": "Illuminate\Routing\Router", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 130, "function": "Illuminate\Foundation\Http\{closure}", "class": "Illuminate\Foundation\Http\Kernel", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php", "line": 67, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 171, "function": "handle", "class": "Barryvdh\Debugbar\Middleware\InjectDebugbar", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/app/Http/Middleware/SecurityHeaders.php", "line": 26, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 171, "function": "handle", "class": "App\Http\Middleware\SecurityHeaders", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php", "line": 21, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\TransformsRequest", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/app/Http/Middleware/CheckForDebug.php", "line": 25, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 171, "function": "handle", "class": "App\Http\Middleware\CheckForDebug", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/app/Http/Middleware/CheckForSetup.php", "line": 26, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 171, "function": "handle", "class": "App\Http\Middleware\CheckForSetup", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/fideloper/proxy/src/TrustProxies.php", "line": 57, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 171, "function": "handle", "class": "Fideloper\Proxy\TrustProxies", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php", "line": 49, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\View\Middleware\ShareErrorsFromSession", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php", "line": 56, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Session\Middleware\StartSession", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php", "line": 63, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 171, "function": "handle", "class": "Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/app/Http/Middleware/NoSessionStore.php", "line": 27, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 171, "function": "handle", "class": "App\Http\Middleware\NoSessionStore", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/barryvdh/laravel-cors/src/HandlePreflight.php", "line": 29, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 171, "function": "handle", "class": "Barryvdh\Cors\HandlePreflight", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php", "line": 105, "function": "Illuminate\Pipeline\{closure}", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 145, "function": "then", "class": "Illuminate\Pipeline\Pipeline", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php", "line": 110, "function": "sendRequestThroughRouter", "class": "Illuminate\Foundation\Http\Kernel", "type": "->" }, { "file": "/var/www/ams.iprsapps.com/public/index.php", "line": 58, "function": "handle", "class": "Illuminate\Foundation\Http\Kernel", "type": "->" } ] }

Please do not post an issue without answering the related questions above. If you have opened a different issue and already answered these questions, answer them again, once for every ticket. It will be next to impossible for us to help you.

https://snipe-it.readme.io/docs/getting-help

welcome[bot] commented 3 years ago

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

drexljo commented 3 years ago

Can confirm.

Versions: snipeit 5.0.10; 5.1.3 OS: Debian 9 PHP version: 7.3.23

The above mentioned fix did fix it with v5.1.3.

auxilioit commented 3 years ago

Hi,

I am getting another issue that seems to be relating to this, when attempting to load Requestable assets from a Company assigned account.

Error: [2021-04-08 11:24:45] production.ERROR: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'company_id' in where clause is ambiguous

Seems to be related to scopeCompanyable function.

Line I think maybe causing error in where:

and snipe_assets.assigned_type = App\Models\Asset where company_id = 2