From 66b2cc2e28bd16a057b24d60b0e75dab90413d78 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 19 Apr 2025 15:17:55 +0100 Subject: [PATCH] Set empty array if permissions are null Signed-off-by: snipe --- app/Models/User.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Models/User.php b/app/Models/User.php index 793f073cc..bd03367d1 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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; }