Set empty array if permissions are null

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2025-04-19 15:17:55 +01:00
parent 47246a3fdf
commit 66b2cc2e28

View file

@ -744,10 +744,20 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
public function decodePermissions()
{
$permissions = json_decode($this->permissions, JSON_OBJECT_AS_ARRAY);
// Set default to empty JSON if the value is null
$permissions = json_decode($this->permissions ?? '{}', JSON_OBJECT_AS_ARRAY);
// If there are no permissions, return an empty array
if (!$permissions) {
return [];
}
// Otherwise, loop through the permissions and cast the values as integers
foreach ($permissions as $permission => $value) {
$permissions[$permission] = (int) $value;
}
return $permissions;
}