diff --git a/js/src/admin/components/SettingsPage.js b/js/src/admin/components/SettingsPage.js index 79c1886..1c3957f 100644 --- a/js/src/admin/components/SettingsPage.js +++ b/js/src/admin/components/SettingsPage.js @@ -305,7 +305,9 @@ export default class SettingsPage extends ExtensionPage { method: 'PATCH', url: `${app.forum.attribute('apiUrl')}/reactions/${reaction.id()}`, body: { - [key]: value, + attributes: { + [key]: value, + }, }, }); diff --git a/src/Api/Controller/UpdateReactionController.php b/src/Api/Controller/UpdateReactionController.php index 9c52ef3..5b38f5c 100644 --- a/src/Api/Controller/UpdateReactionController.php +++ b/src/Api/Controller/UpdateReactionController.php @@ -47,7 +47,7 @@ protected function data(ServerRequestInterface $request, Document $document) { $id = Arr::get($request->getQueryParams(), 'id'); $actor = RequestUtil::getActor($request); - $data = $request->getParsedBody(); + $data = Arr::get($request->getParsedBody(), 'attributes', []); return $this->bus->dispatch( new EditReaction($id, $actor, $data) diff --git a/src/Command/EditReactionHandler.php b/src/Command/EditReactionHandler.php index d5f612b..ac9498f 100644 --- a/src/Command/EditReactionHandler.php +++ b/src/Command/EditReactionHandler.php @@ -62,7 +62,7 @@ public function handle(EditReaction $command) $reaction->enabled = $data['enabled']; } - $this->validator->assertValid($reaction->getAttributes()); + $this->validator->assertValid($reaction->getDirty()); if ($reaction->isDirty()) { $reaction->save(); diff --git a/tests/integration/api/EditReactionTest.php b/tests/integration/api/EditReactionTest.php index 5f83ae5..fc6d03a 100644 --- a/tests/integration/api/EditReactionTest.php +++ b/tests/integration/api/EditReactionTest.php @@ -68,10 +68,12 @@ public function admin_can_edit_reaction() $this->request('PATCH', '/api/reactions/'.$id, [ 'authenticatedAs' => 1, 'json' => [ - 'identifier' => 'test2', - 'type' => 'icon', - 'enabled' => true, - 'display' => 'Test 2', + 'attributes' => [ + 'identifier' => 'test2', + 'type' => 'icon', + 'enabled' => true, + 'display' => 'Test 2', + ], ], ]) ); @@ -105,11 +107,9 @@ public function normal_user_cannot_edit_reaction() $this->request('PATCH', '/api/reactions/'.$id, [ 'authenticatedAs' => 2, 'json' => [ - 'data' => [ - 'attributes' => [ - 'identifier' => 'test2', - 'type' => 'emoji', - ], + 'attributes' => [ + 'identifier' => 'test2', + 'type' => 'emoji', ], ], ]) @@ -129,10 +129,8 @@ public function cannot_edit_reaction_with_invalid_type() $this->request('PATCH', '/api/reactions/'.$id, [ 'authenticatedAs' => 1, 'json' => [ - 'data' => [ - 'attributes' => [ - 'type' => 'invalid', - ], + 'attributes' => [ + 'type' => 'invalid', ], ], ]) @@ -150,11 +148,9 @@ public function cannot_edit_non_existent_reaction() $this->request('PATCH', '/api/reactions/110', [ 'authenticatedAs' => 1, 'json' => [ - 'data' => [ - 'attributes' => [ - 'identifier' => 'test2', - 'type' => 'emoji', - ], + 'attributes' => [ + 'identifier' => 'test2', + 'type' => 'emoji', ], ], ])