Int values for group permissions on API
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
f2c2fefd99
commit
e2a1be9762
2 changed files with 16 additions and 2 deletions
|
@ -24,7 +24,7 @@ class GroupsTransformer
|
|||
$array = [
|
||||
'id' => (int) $group->id,
|
||||
'name' => e($group->name),
|
||||
'permissions' => json_decode($group->permissions),
|
||||
'permissions' => $group->decodePermissions(),
|
||||
'users_count' => (int) $group->users_count,
|
||||
'notes' => Helper::parseEscapedMarkedownInline($group->notes),
|
||||
'created_by' => ($group->adminuser) ? [
|
||||
|
|
|
@ -80,7 +80,21 @@ class Group extends SnipeModel
|
|||
*/
|
||||
public function decodePermissions()
|
||||
{
|
||||
return json_decode($this->permissions, true);
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue