Set empty array if permissions are null
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
47246a3fdf
commit
66b2cc2e28
1 changed files with 11 additions and 1 deletions
|
@ -744,10 +744,20 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||||
|
|
||||||
public function decodePermissions()
|
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) {
|
foreach ($permissions as $permission => $value) {
|
||||||
$permissions[$permission] = (int) $value;
|
$permissions[$permission] = (int) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return $permissions;
|
return $permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue