Skip to content

Commit

Permalink
Fix delete reaction post name
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Jan 13, 2024
1 parent e9c82ca commit e5c1e01
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion js/src/admin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ app.initializers.add('fof/reactions', () => {
{
icon: 'fas fa-trash',
label: app.translator.trans('fof-reactions.admin.permissions.delete_post_reactions_label'),
permission: 'discussion.deletePostReactions',
permission: 'discussion.deleteReactionsPosts',
},
'moderate'
)
Expand Down
13 changes: 8 additions & 5 deletions src/Api/Controller/DeletePostReactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ protected function delete(ServerRequestInterface $request): EmptyResponse

$post = Post::whereVisibleTo($actor)->findOrFail($postId);

$actor->assertCan('react', $post);

if ($reactionId) {
// Delete all post_reactions of a specific type (i.e. `reaction_id`)
$actor->assertCan('deletePostReactions', $post);
$actor->assertCan('deleteReactions', $post);

PostReaction::query()->where('post_id', $postId)->where('reaction_id', $reactionId)->delete();
PostAnonymousReaction::query()->where('post_id', $postId)->where('reaction_id', $reactionId)->delete();
} elseif ($postReactionId) {
// Delete a specific post_reaction for the post
/**
* @var PostReaction $reaction
*/
$reaction = PostReaction::query()->where('post_id', $postId)->where('id', $postReactionId)->firstOrFail();

// If the post is not the actor's, they must have permission to delete reactions
if ($reaction->user_id !== $actor->id) {
$actor->assertCan('deletePostReactions', $post);
if ($reaction->user_id != $actor->id) {
$actor->assertCan('deleteReactions', $post);
} else {
$actor->assertCan('react', $post);
}

$reaction->delete();
Expand Down
2 changes: 1 addition & 1 deletion src/PostAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __invoke(PostSerializer $serializer, Post $post, array $attribut
$actor = $serializer->getActor();

$attributes['canReact'] = (bool) $actor->can('react', $post);
$attributes['canDeletePostReactions'] = (bool) $actor->can('deletePostReactions', $post);
$attributes['canDeletePostReactions'] = (bool) $actor->can('deleteReactions', $post);

// Get reaction counts for the post.
$reactionCounts = $this->getReactionCountsForPost($post);
Expand Down

0 comments on commit e5c1e01

Please sign in to comment.