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

Prevent user from reacting to own post #17

Merged
merged 3 commits into from Feb 4, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions js/src/forum/components/PostReactAction.js
Expand Up @@ -128,15 +128,15 @@ export default class PostReactAction extends Component {
return [
<span
className="Button-label Button-emoji-parent"
onclick={el => this.react(this.reaction ? identifier : el)}
onclick={this.post.user() !== app.session.user ? (el => this.react(this.reaction ? identifier : el)) : ''}
dsevillamartin marked this conversation as resolved.
Show resolved Hide resolved
data-reaction={identifier}
>
{icon}
{count > 1 ? count : ''}
</span>,
];
})}
{!this.reaction ? (
{!this.reaction && this.post.user() !== app.session.user ? (
<div className="CommentPost--Reactions" style={this.post.number() === 1 ? '' : 'left: -28%;'}>
<ul className="Reactions--Ul">{listItems(this.getReactions().toArray())}</ul>
</div>
Expand All @@ -146,6 +146,9 @@ export default class PostReactAction extends Component {
}

reactButton() {
if (this.post.user() === app.session.user) {
return;
}
return (
<button className="Button Button--link Reactions--ShowReactions" type="Button" title="React">
<span className="Button-label" style={this.reaction ? 'display: none' : 'display:'}>
Expand Down
1 change: 1 addition & 0 deletions resources/locale/en.yml
Expand Up @@ -5,6 +5,7 @@ fof-reactions:
notification: '{username} reacted with {reaction} to your post'
settings:
notify_post_reacted_label: Someone reacts to one of my posts
reacting-own-post: You cannot react to your own post

admin:
permissions:
Expand Down
7 changes: 7 additions & 0 deletions src/Listener/SaveReactionsToDatabase.php
Expand Up @@ -59,6 +59,7 @@ public function subscribe(Dispatcher $events)
* @param Saving $event
*
* @throws \Flarum\User\Exception\PermissionDeniedException
* @throws \Flarum\Foundation\ValidationException
*/
public function whenSaving(Saving $event)
{
Expand All @@ -71,6 +72,12 @@ public function whenSaving(Saving $event)

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

if ($actor->id === $post->user_id) {
throw new ValidationException([
'message' => $this->translator->trans('fof-reactions.forum.reacting-own-post'),
]);
}

$this->validateReaction($reactionType);

if (class_exists('FoF\Gamification\Listeners\SaveVotesToDatabase') && $reactionType == $this->settings->get('fof-reactions.convertToUpvote')) {
Expand Down