Allow users to delete their own comments
This commit is contained in:
committed by
Javi Martín
parent
fa14976cfd
commit
0698c0ff4f
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -5,8 +5,15 @@
|
||||
<span class="js-moderation-actions">
|
||||
<% if can? :hide, comment %>
|
||||
<span class="divider"> • </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 %>
|
||||
|
||||
1
app/views/comments/hide.js.erb
Normal file
1
app/views/comments/hide.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$("#<%= dom_id(@comment) %>").replaceWith("<%= j render("comment", comment: @comment) %>");
|
||||
Reference in New Issue
Block a user