Merge pull request #14779 from marcusmoore/fixes/fix-group-create-endpoint

Fixed Array to string conversion exception in group create api endpoint
This commit is contained in:
snipe 2024-05-28 23:26:34 +01:00 committed by GitHub
commit 29454f7288
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View file

@ -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')));

View file

@ -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()