Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unable to set custom display name #80

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 14 additions & 18 deletions tests/integration/api/EditReactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
],
])
);
Expand Down Expand Up @@ -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',
],
],
])
Expand All @@ -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',
],
],
])
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
Loading