Skip to content

Commit

Permalink
fix: unable to set custom display name
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Dec 20, 2023
1 parent 71e580a commit ea21c39
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 24 deletions.
4 changes: 3 additions & 1 deletion js/src/admin/components/SettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/Api/Controller/UpdateReactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Command/EditReactionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
38 changes: 17 additions & 21 deletions tests/integration/api/EditReactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ public function admin_can_edit_reaction()
$id = $this->addNewReaction();

$response = $this->send(
$this->request('PATCH', '/api/reactions/'.$id, [
$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',
]
],
])
);
Expand Down Expand Up @@ -102,14 +104,12 @@ public function normal_user_cannot_edit_reaction()
$id = $this->addNewReaction();

$response = $this->send(
$this->request('PATCH', '/api/reactions/'.$id, [
$this->request('PATCH', '/api/reactions/' . $id, [
'authenticatedAs' => 2,
'json' => [
'data' => [
'attributes' => [
'identifier' => 'test2',
'type' => 'emoji',
],
'attributes' => [
'identifier' => 'test2',
'type' => 'emoji',
],
],
])
Expand All @@ -126,13 +126,11 @@ public function cannot_edit_reaction_with_invalid_type()
$id = $this->addNewReaction();

$response = $this->send(
$this->request('PATCH', '/api/reactions/'.$id, [
$this->request('PATCH', '/api/reactions/' . $id, [
'authenticatedAs' => 1,
'json' => [
'data' => [
'attributes' => [
'type' => 'invalid',
],
'attributes' => [
'type' => 'invalid',
],
],
])
Expand All @@ -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',
],
],
])
Expand Down

0 comments on commit ea21c39

Please sign in to comment.