Skip to content

Commit 473ead9

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents cf28509 + 4f72505 commit 473ead9

File tree

3 files changed

+41
-24
lines changed

3 files changed

+41
-24
lines changed

app/Models/Group.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,32 @@ public function adminuser()
7676
*
7777
* @author A. Gianotto <[email protected]>
7878
* @since [v1.0]
79-
* @return array
79+
* @return array | \stdClass
8080
*/
8181
public function decodePermissions()
8282
{
83-
// Set default to empty JSON if the value is null
83+
// If the permissions are an array, convert it to JSON
8484
if (is_array($this->permissions)) {
8585
$this->permissions = json_encode($this->permissions);
8686
}
87-
$permissions = json_decode($this->permissions ?? '{}', JSON_OBJECT_AS_ARRAY);
8887

89-
// If there are no permissions, return an empty array
90-
if (!$permissions) {
91-
return [];
92-
}
88+
$permissions = json_decode($this->permissions ?? '{}', JSON_OBJECT_AS_ARRAY);
9389

9490
// Otherwise, loop through the permissions and cast the values as integers
95-
foreach ($permissions as $permission => $value) {
96-
$permissions[$permission] = (int) $value;
91+
if ((is_array($permissions)) && ($permissions)) {
92+
foreach ($permissions as $permission => $value) {
93+
94+
if (!is_integer($permission)) {
95+
$permissions[$permission] = (int) $value;
96+
} else {
97+
\Log::info('Weird data here - skipping it');
98+
unset($permissions[$permission]);
99+
}
100+
}
101+
return $permissions ?: new \stdClass;
97102
}
103+
return new \stdClass;
98104

99-
100-
return $permissions;
101105
}
102106

103107
/**

app/Models/User.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -746,24 +746,36 @@ public function createdBy()
746746
}
747747

748748

749-
749+
/**
750+
* Decode JSON permissions into array
751+
*
752+
* @author A. Gianotto <[email protected]>
753+
* @since [v1.0]
754+
* @return array | \stdClass
755+
*/
750756
public function decodePermissions()
751757
{
752-
// Set default to empty JSON if the value is null
753-
$permissions = json_decode($this->permissions ?? '{}', JSON_OBJECT_AS_ARRAY);
754-
755-
// If there are no permissions, return an empty array
756-
if (!$permissions) {
757-
return [];
758+
// If the permissions are an array, convert it to JSON
759+
if (is_array($this->permissions)) {
760+
$this->permissions = json_encode($this->permissions);
758761
}
759762

763+
$permissions = json_decode($this->permissions ?? '{}', JSON_OBJECT_AS_ARRAY);
764+
760765
// Otherwise, loop through the permissions and cast the values as integers
761-
foreach ($permissions as $permission => $value) {
762-
$permissions[$permission] = (int) $value;
766+
if ((is_array($permissions)) && ($permissions)) {
767+
foreach ($permissions as $permission => $value) {
768+
769+
if (!is_integer($permission)) {
770+
$permissions[$permission] = (int) $value;
771+
} else {
772+
\Log::info('Weird data here - skipping it');
773+
unset($permissions[$permission]);
774+
}
775+
}
776+
return $permissions ?: new \stdClass;
763777
}
764-
765-
766-
return $permissions;
778+
return new \stdClass;
767779
}
768780

769781
/**

resources/views/groups/index.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class="table table-striped snipe-table"
4444
<th data-switchable="true" data-sortable="true" data-field="id" data-visible="false">{{ trans('general.id') }}</th>
4545
<th data-switchable="true" data-sortable="true" data-field="name" data-formatter="groupsAdminLinkFormatter" data-visible="true">{{ trans('admin/groups/table.name') }}</th>
4646
<th data-switchable="true" data-sortable="true" data-field="users_count" data-visible="true"><x-icon type="user" /><span class="sr-only">{{ trans('admin/groups/table.users') }}</span></th>
47-
<th data-switchable="true" data-sortable="true" data-field="created_at" data-visible="true" data-formatter="dateDisplayFormatter">{{ trans('general.created_at') }}</th>
47+
<th data-switchable="true" data-sortable="true" data-field="notes" data-visible="true">{{ trans('general.notes') }}</th>
48+
<th data-switchable="true" data-sortable="true" data-field="created_at" data-visible="true" data-formatter="dateDisplayFormatter">{{ trans('general.created_at') }}</th>
4849
<th data-switchable="false" data-searchable="false" data-sortable="true" data-field="created_by" data-formatter="usersLinkObjFormatter">{{ trans('general.created_by') }}</th>
4950
<th data-switchable="false" data-searchable="false" data-sortable="false" data-field="actions" data-formatter="groupsActionsFormatter">{{ trans('table.actions') }}</th>
5051

0 commit comments

Comments
 (0)