Allow users to delete their own comments

This commit is contained in:
Julian Herrero
2020-09-24 11:53:48 +07:00
committed by Javi Martín
parent fa14976cfd
commit 0698c0ff4f
12 changed files with 100 additions and 8 deletions

View File

@@ -1940,6 +1940,20 @@ table {
}
}
.delete-comment {
@include has-fa-icon(trash-alt, regular);
color: $delete;
&:hover,
&:active {
color: $link-hover;
}
&::before {
transform: translateY(-1px);
}
}
.comment-user {
margin-top: $line-height / 4;
padding: $line-height / 4 0;

View File

@@ -1,5 +1,5 @@
class CommentsController < ApplicationController
before_action :authenticate_user!, only: :create
before_action :authenticate_user!, only: [:create, :hide]
before_action :load_commentable, only: :create
before_action :verify_resident_for_commentable!, only: :create
before_action :verify_comments_open!, only: [:create, :vote]
@@ -46,6 +46,11 @@ class CommentsController < ApplicationController
render "shared/_refresh_flag_actions", locals: { flaggable: @comment, divider: true }
end
def hide
@comment.hide
set_comment_flags(@comment.subtree)
end
private
def comment_params

View File

@@ -49,6 +49,8 @@ module Abilities
can [:create, :created], Proposal
can :create, Legislation::Proposal
can :hide, Comment, user_id: user.id
can :suggest, Debate
can :suggest, Proposal
can :suggest, Legislation::Proposal

View File

@@ -12,7 +12,6 @@ module Abilities
can :read, Comment
can :hide, Comment, hidden_at: nil
cannot :hide, Comment, user_id: user.id
can :ignore_flag, Comment, ignored_flag_at: nil, hidden_at: nil
cannot :ignore_flag, Comment, user_id: user.id

View File

@@ -5,8 +5,15 @@
<span class="js-moderation-actions">
<% if can? :hide, comment %>
<span class="divider">&nbsp;&bull;&nbsp;</span>
<%= link_to t("admin.actions.hide").capitalize, hide_moderation_comment_path(comment),
method: :put, remote: true, data: { confirm: t("admin.actions.confirm") } %>
<% if comment.author == current_user %>
<%= link_to t("comments.actions.delete"),
hide_comment_path(comment),
method: :put, remote: true, class: "delete-comment",
data: { confirm: t("comments.actions.confirm_delete") } %>
<% else %>
<%= link_to t("admin.actions.hide").capitalize, hide_moderation_comment_path(comment),
method: :put, remote: true, data: { confirm: t("admin.actions.confirm") } %>
<% end %>
<% end %>
<% if can? :hide, comment.user %>

View File

@@ -0,0 +1 @@
$("#<%= dom_id(@comment) %>").replaceWith("<%= j render("comment", comment: @comment) %>");