diff --git a/app/Http/Controllers/Api/GroupsController.php b/app/Http/Controllers/Api/GroupsController.php index f76d23b3ae..3fa7ca48f0 100644 --- a/app/Http/Controllers/Api/GroupsController.php +++ b/app/Http/Controllers/Api/GroupsController.php @@ -68,7 +68,7 @@ class GroupsController extends Controller $group->name = $request->input('name'); $group->created_by = Auth::user()->id; - $group->permissions = $request->input('permissions', $groupPermissions); + $group->permissions = json_encode($request->input('permissions', $groupPermissions)); if ($group->save()) { return response()->json(Helper::formatStandardApiResponse('success', (new GroupsTransformer)->transformGroup($group), trans('admin/groups/message.success.create'))); diff --git a/tests/Feature/Api/Groups/GroupStoreTest.php b/tests/Feature/Api/Groups/GroupStoreTest.php index 65d673e7b0..afa7a747d8 100644 --- a/tests/Feature/Api/Groups/GroupStoreTest.php +++ b/tests/Feature/Api/Groups/GroupStoreTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature\Api\Groups; +use App\Helpers\Helper; use App\Models\Group; use App\Models\User; use Tests\TestCase; @@ -49,10 +50,15 @@ class GroupStoreTest extends TestCase $this->assertNotNull($group); + $this->assertEquals( + Helper::selectedPermissionsArray(config('permissions'), config('permissions')), + $group->decodePermissions(), + 'Default group permissions were not set as expected', + ); + $this->actingAsForApi($superuser) ->getJson(route('api.groups.show', ['group' => $group])) ->assertOk(); - } public function testStoringGroupWithInvalidPermissionDropsBadPermission()