File tree Expand file tree Collapse file tree 3 files changed +41
-24
lines changed Expand file tree Collapse file tree 3 files changed +41
-24
lines changed Original file line number Diff line number Diff 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 /**
Original file line number Diff line number Diff 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 /**
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments