snipe / snipe-it

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

Unable to save edits to user #2894

Closed steveelwood closed 7 years ago

steveelwood commented 7 years ago

Expected Behavior (or desired behavior if a feature request)

As superuser, edit an ldap-synced user to assign to company, groups, etc. Expect to save and have settings correctly applied.


Actual Behavior

When trying to save edits to a newly created ldap user (as a superuser), I get an error "Whoops, looks like something went wrong." in the browser.

In debug or laravel.log I see the following, followed by the stack trace (included below). production.ERROR: exception 'ErrorException' with message 'array_key_exists() expects parameter 2 to be array, null given' in /var/www/snipe-it/app/Http/Controllers/UsersController.php:318

I checked the database, and it appears that for this new user the permissions field is set to NULL, with no array defined as is the case with previously created users.


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


Please provide answers to these questions before posting your bug report:

snipe commented 7 years ago

Can you tell me if you've got any groups created/assigned to that user?

steveelwood commented 7 years ago

No groups assigned, that was actually what I was trying to do when I first encountered the error. I just attached a screenshot from phpmyadmin showing the user db fields in question. I've also verified I can edit other users, just not the latest user with ID 16. snipe-db-user

Incidentally, I noticed that last_login isn't populating for either of the user IDs created since upgrading to v3. Probably not relevant to this discussion.

snipe commented 7 years ago

If you pull the latest from dev, does this still happen?

steveelwood commented 7 years ago

TL;DR Yup

Pulled dev, still got the same error. I deleted the user and purged them from the database, then tried with a different user account. The first attempt to log in just returned me to the login screen, and the second one generated the following set of stack traces.

2/2 ErrorException in 0e431713045aaabe0511f2088a4c6532778cc954.php line 282: Trying to get property of non-object (View: /var/www/snipe-it/resources/views/account/view-assets.blade.php)

in 0e431713045aaabe0511f2088a4c6532778cc954.php line 282
at CompilerEngine->handleViewException(object(ErrorException), '1') in PhpEngine.php line 44
at PhpEngine->evaluatePath('/var/www/snipe-it/storage/framework/views/0e431713045aaabe0511f2088a4c6532778cc954.php', array('__env' => object(Factory), 'app' => object(Application), 'MaintenanceModeEnabled' => false, 'MaintenanceModeTimestamp' => object(Carbon), 'MaintenanceModeMessage' => 'We're currently working on the site, please try again later!', 'errors' => object(ViewErrorBag), 'signedIn' => true, 'user' => object(User), 'userlog' => object(Collection))) in CompilerEngine.php line 59
at CompilerEngine->get('/var/www/snipe-it/resources/views/account/view-assets.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'MaintenanceModeEnabled' => false, 'MaintenanceModeTimestamp' => object(Carbon), 'MaintenanceModeMessage' => 'We're currently working on the site, please try again later!', 'errors' => object(ViewErrorBag), 'signedIn' => true, 'user' => object(User), 'userlog' => object(Collection))) in View.php line 149
at View->getContents() in View.php line 120
at View->renderContents() in View.php line 85
at View->render() in Response.php line 53
at Response->setContent(object(View)) in Response.php line 201
at Response->__construct(object(View)) in Router.php line 1085
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 95
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(ViewAssetsController), object(Route), object(Request), 'getIndex') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\ViewAssetsController', 'getIndex') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Authenticate.php line 45
at Authenticate->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Authenticate), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForTwoFactor.php line 38
at CheckForTwoFactor->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForTwoFactor), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckLocale.php line 40
at CheckLocale->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckLocale), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Debugbar.php line 49
at Debugbar->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TrustProxies.php line 46
at TrustProxies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(TrustProxies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForSetup.php line 22
at CheckForSetup->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForSetup), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in NosniffGuard.php line 17
at NosniffGuard->handle(object(Request), object(Closure))
at call_user_func_array(array(object(NosniffGuard), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in XssProtectHeader.php line 17
at XssProtectHeader->handle(object(Request), object(Closure))
at call_user_func_array(array(object(XssProtectHeader), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in FrameGuard.php line 17
at FrameGuard->handle(object(Request), object(Closure))
at call_user_func_array(array(object(FrameGuard), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 145
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 60

1/2 ErrorException in 0e431713045aaabe0511f2088a4c6532778cc954.php line 282: Trying to get property of non-object

in 0e431713045aaabe0511f2088a4c6532778cc954.php line 282
at HandleExceptions->handleError('8', 'Trying to get property of non-object', '/var/www/snipe-it/storage/framework/views/0e431713045aaabe0511f2088a4c6532778cc954.php', '282', array('__path' => '/var/www/snipe-it/storage/framework/views/0e431713045aaabe0511f2088a4c6532778cc954.php', '__data' => array('__env' => object(Factory), 'app' => object(Application), 'MaintenanceModeEnabled' => false, 'MaintenanceModeTimestamp' => object(Carbon), 'MaintenanceModeMessage' => 'We're currently working on the site, please try again later!', 'errors' => object(ViewErrorBag), 'signedIn' => true, 'user' => object(User), 'userlog' => object(Collection)), 'obLevel' => '1', '__env' => object(Factory), 'app' => object(Application), 'MaintenanceModeEnabled' => false, 'MaintenanceModeTimestamp' => object(Carbon), 'MaintenanceModeMessage' => 'We're currently working on the site, please try again later!', 'errors' => object(ViewErrorBag), 'signedIn' => true, 'user' => object(User), 'userlog' => object(Collection), 'log' => object(Actionlog))) in 0e431713045aaabe0511f2088a4c6532778cc954.php line 282
at include('/var/www/snipe-it/storage/framework/views/0e431713045aaabe0511f2088a4c6532778cc954.php') in PhpEngine.php line 42
at PhpEngine->evaluatePath('/var/www/snipe-it/storage/framework/views/0e431713045aaabe0511f2088a4c6532778cc954.php', array('__env' => object(Factory), 'app' => object(Application), 'MaintenanceModeEnabled' => false, 'MaintenanceModeTimestamp' => object(Carbon), 'MaintenanceModeMessage' => 'We're currently working on the site, please try again later!', 'errors' => object(ViewErrorBag), 'signedIn' => true, 'user' => object(User), 'userlog' => object(Collection))) in CompilerEngine.php line 59
at CompilerEngine->get('/var/www/snipe-it/resources/views/account/view-assets.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'MaintenanceModeEnabled' => false, 'MaintenanceModeTimestamp' => object(Carbon), 'MaintenanceModeMessage' => 'We're currently working on the site, please try again later!', 'errors' => object(ViewErrorBag), 'signedIn' => true, 'user' => object(User), 'userlog' => object(Collection))) in View.php line 149
at View->getContents() in View.php line 120
at View->renderContents() in View.php line 85
at View->render() in Response.php line 53
at Response->setContent(object(View)) in Response.php line 201
at Response->__construct(object(View)) in Router.php line 1085
at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 95
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(ViewAssetsController), object(Route), object(Request), 'getIndex') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\ViewAssetsController', 'getIndex') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Authenticate.php line 45
at Authenticate->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Authenticate), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForTwoFactor.php line 38
at CheckForTwoFactor->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForTwoFactor), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckLocale.php line 40
at CheckLocale->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckLocale), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Debugbar.php line 49
at Debugbar->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in TrustProxies.php line 46
at TrustProxies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(TrustProxies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForSetup.php line 22
at CheckForSetup->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForSetup), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in NosniffGuard.php line 17
at NosniffGuard->handle(object(Request), object(Closure))
at call_user_func_array(array(object(NosniffGuard), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in XssProtectHeader.php line 17
at XssProtectHeader->handle(object(Request), object(Closure))
at call_user_func_array(array(object(XssProtectHeader), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in FrameGuard.php line 17
at FrameGuard->handle(object(Request), object(Closure))
at call_user_func_array(array(object(FrameGuard), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 145
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 60

However, the user account was created, and when I attempted to edit it using my superadmin account, I received the original error. I verified that this second user account also has NULL listed in the permissions field in the DB.

snipe commented 7 years ago

That second one MAY be a different error though. It looks like the error is being triggered at /var/www/snipe-it/resources/views/account/view-assets.blade.php, which is the default overview of what's checked out to a user. Can you tell me what's on line 282 or /var/www/snipe-it/storage/framework/views/0e431713045aaabe0511f2088a4c6532778cc954.php?

steveelwood commented 7 years ago

281: <?php elseif(!is_null($log->itemType())): ?> 282: <?php if($log->item->deleted_at==''): ?> 283: <?php echo e($log->item->name); ?>

snipe commented 7 years ago

I'm having a hard time reproducing this on my end, which of course makes it a real pain in the ass to troubleshoot. It looks like it doesn't think that $log->item is a valid item. Is it possible that user is associated with an asset that was purged?

steveelwood commented 7 years ago

Sorry about that. Neither of the two users I've tested with have been in the system prior to today, so no assets assigned.

snipe commented 7 years ago

Can you check in the action_logs table and tell me if that new user ID shows up anywhere?

steveelwood commented 7 years ago

This may help... when I create a user manually (not synced from LDAP), it populates the permissions field correctly and is editable.

steveelwood commented 7 years ago

I sorted the action_logs table by user_id, and the only IDs listed are 1 and 7, the initial admin account, and my LDAP account. Other members of my team have been logged in and edited assets, so that's a little confusing.

For context, we don't use snipe-it to check out assets to users, we use it to track infrastructure inventory, budget values, replacement cycles, etc. The only people accessing the system are my team and a few other I.T. managers.

snipe commented 7 years ago

This may help... when I create a user manually (not synced from LDAP), it populates the permissions field correctly and is editable.

Huh. Okay, that definitely does help.

snipe commented 7 years ago

When you look at the difference in the permissions fields for users created manually vs users created with LDAP, can you tell me what they look like?

steveelwood commented 7 years ago

This is the permissions field of a user created manually:

{"superuser":"0","admin":"0","reports.view":"0","assets.view":"0","assets.create":"0","assets.edit":"0","assets.delete":"0","assets.checkin":"0","assets.checkout":"0","assets.view.requestable":"0","accessories.view":"0","accessories.create":"0","accessories.edit":"0","accessories.delete":"0","accessories.checkout":"0","accessories.checkin":"0","consumables.view":"0","consumables.create":"0","consumables.edit":"0","consumables.delete":"0","consumables.checkout":"0","licenses.view":"0","licenses.create":"0","licenses.edit":"0","licenses.delete":"0","licenses.checkout":"0","licenses.keys":"0","components.view":"0","components.create":"0","components.edit":"0","components.delete":"0","components.checkout":"0","components.checkin":"0","users.view":"0","users.create":"0","users.edit":"0","users.delete":"0","self.two_factor":"0"}

This is the permissions field of a user created via LDAP:

(Nothing)

snipe commented 7 years ago

Aha. I mean, that's confusing, but aha. It should be converting the null string to an array, to avoid those weird errors.

snipe commented 7 years ago

The users done via LDAP are done using the LDAP sync UI, or the command line tool?

steveelwood commented 7 years ago

LDAP sync UI.

steveelwood commented 7 years ago

More background: looking through server logs, it appears php was updated on this server yesterday to 5.6.27-1, including the php-ldap package. Probably a red herring.

snipe commented 7 years ago

Okay, try this:

In app/Http/Controllers/UsersController.php, lines 316-322, change:

// Figure out of this user was an admin before this edit
$orig_permissions_array = $user->decodePermissions();
if (array_key_exists('superuser', $orig_permissions_array)) {
    $orig_superuser = $orig_permissions_array['superuser'];
} else {
    $orig_superuser = '0';
}

to

// Figure out of this user was an admin before this edit
$orig_permissions_array = $user->decodePermissions();

if (is_array($orig_permissions_array)) {
    if (array_key_exists('superuser', $orig_permissions_array)) {
        $orig_superuser = $orig_permissions_array['superuser'];
    } else {
        $orig_superuser = '0';
    }
} else {
    $orig_permissions_array = array();
}
snipe commented 7 years ago

(If this works for you, I'll merge it into develop and master)

steveelwood commented 7 years ago

Sorry, that code didn't change the outcome.

Looking through the app/Http/Controllers directory, is it an issue that some of the Controller files aren't set to 755? Just checking.

-rwxr-xr-x 1 apache apache 25291 Nov 8 13:37 AccessoriesController.php -rw-r--r-- 1 apache apache 437 Nov 8 13:37 ActionlogController.php -rw-r--r-- 1 apache apache 17838 Nov 8 13:37 AssetMaintenancesController.php -rwxr-xr-x 1 apache apache 18570 Nov 8 13:37 AssetModelsController.php -rwxr-xr-x 1 apache apache 73255 Nov 8 13:37 AssetsController.php drwxr-xr-x 2 apache apache 4096 Oct 4 15:23 Auth -rwxr-xr-x 1 apache apache 20632 Nov 8 13:37 CategoriesController.php -rw-r--r-- 1 apache apache 4155 Nov 8 13:37 CompaniesController.php -rw-r--r-- 1 apache apache 19428 Nov 8 13:37 ComponentsController.php -rw-r--r-- 1 apache apache 20713 Nov 8 13:37 ConsumablesController.php -rw-r--r-- 1 apache apache 1483 Nov 8 13:37 Controller.php -rw-r--r-- 1 apache apache 9105 Nov 8 13:37 CustomFieldsController.php -rwxr-xr-x 1 apache apache 2816 Nov 8 13:37 DashboardController.php -rwxr-xr-x 1 apache apache 7375 Nov 8 13:37 DepreciationsController.php -rwxr-xr-x 1 apache apache 7529 Nov 8 13:37 GroupsController.php -rwxr-xr-x 1 apache apache 39162 Nov 8 13:37 LicensesController.php -rwxr-xr-x 1 apache apache 15564 Nov 8 13:37 LocationsController.php -rwxr-xr-x 1 apache apache 22688 Nov 8 13:37 ManufacturersController.php -rwxr-xr-x 1 apache apache 2403 Nov 8 13:37 ProfileController.php -rw-r--r-- 1 apache apache 34344 Nov 8 13:37 ReportsController.php -rwxr-xr-x 1 apache apache 19964 Nov 8 13:37 SettingsController.php -rwxr-xr-x 1 apache apache 11595 Nov 8 13:37 StatuslabelsController.php -rwxr-xr-x 1 apache apache 10566 Nov 8 13:37 SuppliersController.php -rwxr-xr-x 1 apache apache 53151 Nov 8 15:39 UsersController.php -rwxr-xr-x 1 apache apache 52991 Nov 8 13:37 UsersController.php.OLD -rwxr-xr-x 1 apache apache 14966 Nov 8 13:37 ViewAssetsController.php

snipe commented 7 years ago

What's the specific error you're getting with that change?

All of the Controller files should be the same permission, but as long as they're readable by the group/user, it should be fine.

snipe commented 7 years ago

Also, can you show me an example screenshot of what the permissions tab looks like on one of the problem users?

snipe commented 7 years ago

The part that doesn't make sense here is that the permissions tab defaults to "inherit" for everything, so the permissions array should never be null on save.

steveelwood commented 7 years ago

Oh! I am so sorry. The user still showed NULL in the database after first attempt to log in, but when I edited it using my superuser in Snipe it saved successfully, and now has the permissions field populated with an array.

snipe commented 7 years ago

Logging in won't change the permissions, only editing the user will. But that shouldn't trigger an error when they login.

steveelwood commented 7 years ago

Yeah, that's what I was just typing out. :-)

The first LDAP-linked login kicks you back to the login screen, but second login brings you into the View Assets screen. Which is weird, because the permissions are still set to NULL in the DB.

snipe commented 7 years ago

Now I'm more confused lol. When you tail the laravel log (tail -f storage/laravel/log what do you see when you try to login for the first time with an LDAP imported user?

And where are you getting the Whoops error in this process?

steveelwood commented 7 years ago

No more whoops errors, it just doesn't log in a new LDAP user in the first time they try. The second time it logs them in fine, although without permissions they won't really be doing anything until an admin sets their group membership(s).

Do you still want the log tail?

snipe commented 7 years ago

No more whoops failures with the new code? Or without it?

although without permissions they won't really be doing anything until an admin sets their group membership(s).

That's true, but that's a pretty common use case. Most admins need to import users so they can assign assets to them, but the users either don't login, or when they do, they can only see their own stuff that's already been assigned.

Do you still want the log tail?

Yeah, since it should log them in fine the first time. (In fact, if you have LDAP login set up, it shouldn't require you to import them at all. It should check to see if they exist in your LDAP server, and if they do and the passwords match, it should create them if they don't exist locally.)

steveelwood commented 7 years ago

No more whoops failures once we moved to the new code. I had made a dumb assumption that since the user had no permissions array in the DB, that the problem still existed.

I agree with you on the lack of permissions being a common use case. It's a security feature, not a bug.

Tail of laravel.log during LDAP user initial login:

[2016-11-08 16:09:55] production.DEBUG: LDAP is enabled. [2016-11-08 16:09:55] production.DEBUG: Binding user to LDAP. [2016-11-08 16:09:55] production.DEBUG: LDAP user testuser successfully bound to LDAP [2016-11-08 16:09:55] production.DEBUG: Local auth lookup complete [2016-11-08 16:09:55] production.DEBUG: Local user testuser does not exist [2016-11-08 16:09:55] production.DEBUG: Creating local user testuser [2016-11-08 16:09:55] production.DEBUG: Local user created.

snipe commented 7 years ago

I agree with you on the lack of permissions being a common use case. It's a security feature, not a bug.

:)

Hmm... that should still create AND login, not one or the other.

I'm out of the country until the weekend, but will take a look when I get back home.

steveelwood commented 7 years ago

Yeah, I thought so too!

Thank you so much for looking into this while you were traveling! Hope you get to see some cool stuff and not have to spend all day dealing with weird user permission bugs.

ghost commented 7 years ago

I was about to post an issue about this - I have the exact same problem with one particular user here. I'll try the suggested code edit and let you know if it works !

ghost commented 7 years ago

That change in UsersController.php worked.

steveelwood commented 7 years ago

Glad that worked! Just curious, do you also see the issue where LDAP-synced users have to log in twice the first time they access the system?

ghost commented 7 years ago

No, can't say I've noticed that.

steveelwood commented 7 years ago

Ok, guess that's an unrelated issue.

thien154 commented 6 years ago

this is solution work for me.

replace

$orig_permissions_array = $user->decodePermissions(); if (array_key_exists('superuser', $orig_permissions_array)) { $orig_superuser = $orig_permissions_array['superuser']; } else { $orig_superuser = '0'; }

with

if (!empty($orig_permissions_array)) { if (array_key_exists('superuser', $orig_permissions_array)) { $orig_superuser = $orig_permissions_array['superuser']; } else { $orig_superuser = '0'; } } else { $orig_permissions_array = array(); }

snipe commented 6 years ago

@thien154 this issue was fixed in 2016. Please don't resurrect old threads.