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 {
|
.comment-user {
|
||||||
margin-top: $line-height / 4;
|
margin-top: $line-height / 4;
|
||||||
padding: $line-height / 4 0;
|
padding: $line-height / 4 0;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class CommentsController < ApplicationController
|
class CommentsController < ApplicationController
|
||||||
before_action :authenticate_user!, only: :create
|
before_action :authenticate_user!, only: [:create, :hide]
|
||||||
before_action :load_commentable, only: :create
|
before_action :load_commentable, only: :create
|
||||||
before_action :verify_resident_for_commentable!, only: :create
|
before_action :verify_resident_for_commentable!, only: :create
|
||||||
before_action :verify_comments_open!, only: [:create, :vote]
|
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 }
|
render "shared/_refresh_flag_actions", locals: { flaggable: @comment, divider: true }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hide
|
||||||
|
@comment.hide
|
||||||
|
set_comment_flags(@comment.subtree)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def comment_params
|
def comment_params
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ module Abilities
|
|||||||
can [:create, :created], Proposal
|
can [:create, :created], Proposal
|
||||||
can :create, Legislation::Proposal
|
can :create, Legislation::Proposal
|
||||||
|
|
||||||
|
can :hide, Comment, user_id: user.id
|
||||||
|
|
||||||
can :suggest, Debate
|
can :suggest, Debate
|
||||||
can :suggest, Proposal
|
can :suggest, Proposal
|
||||||
can :suggest, Legislation::Proposal
|
can :suggest, Legislation::Proposal
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ module Abilities
|
|||||||
can :read, Comment
|
can :read, Comment
|
||||||
|
|
||||||
can :hide, Comment, hidden_at: nil
|
can :hide, Comment, hidden_at: nil
|
||||||
cannot :hide, Comment, user_id: user.id
|
|
||||||
|
|
||||||
can :ignore_flag, Comment, ignored_flag_at: nil, hidden_at: nil
|
can :ignore_flag, Comment, ignored_flag_at: nil, hidden_at: nil
|
||||||
cannot :ignore_flag, Comment, user_id: user.id
|
cannot :ignore_flag, Comment, user_id: user.id
|
||||||
|
|||||||
@@ -5,8 +5,15 @@
|
|||||||
<span class="js-moderation-actions">
|
<span class="js-moderation-actions">
|
||||||
<% if can? :hide, comment %>
|
<% if can? :hide, comment %>
|
||||||
<span class="divider"> • </span>
|
<span class="divider"> • </span>
|
||||||
<%= link_to t("admin.actions.hide").capitalize, hide_moderation_comment_path(comment),
|
<% if comment.author == current_user %>
|
||||||
method: :put, remote: true, data: { confirm: t("admin.actions.confirm") } %>
|
<%= 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 %>
|
<% end %>
|
||||||
|
|
||||||
<% if can? :hide, comment.user %>
|
<% 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) %>");
|
||||||
@@ -29,6 +29,9 @@ en:
|
|||||||
close: Close
|
close: Close
|
||||||
menu: Menu
|
menu: Menu
|
||||||
comments:
|
comments:
|
||||||
|
actions:
|
||||||
|
confirm_delete: "Are you sure? This action will delete this comment. You can't undo this action."
|
||||||
|
delete: "Delete comment"
|
||||||
comments_closed: Comments are closed
|
comments_closed: Comments are closed
|
||||||
verified_only: To participate %{verify_account}
|
verified_only: To participate %{verify_account}
|
||||||
comment:
|
comment:
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ es:
|
|||||||
close: Cerrar
|
close: Cerrar
|
||||||
menu: Menú
|
menu: Menú
|
||||||
comments:
|
comments:
|
||||||
|
actions:
|
||||||
|
confirm_delete: "¿Estás seguro/a? Esta acción borrará este comentario. No puedes deshacer esta acción."
|
||||||
|
delete: "Borrar comentario"
|
||||||
comments_closed: Los comentarios están cerrados
|
comments_closed: Los comentarios están cerrados
|
||||||
verified_only: Para participar %{verify_account}
|
verified_only: Para participar %{verify_account}
|
||||||
comment:
|
comment:
|
||||||
|
|||||||
@@ -3,5 +3,6 @@ resources :comments, only: [:create, :show], shallow: true do
|
|||||||
post :vote
|
post :vote
|
||||||
put :flag
|
put :flag
|
||||||
put :unflag
|
put :unflag
|
||||||
|
put :hide
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -65,9 +65,6 @@ describe Abilities::Common do
|
|||||||
it { should be_able_to(:show, user) }
|
it { should be_able_to(:show, user) }
|
||||||
it { should be_able_to(:edit, user) }
|
it { should be_able_to(:edit, user) }
|
||||||
|
|
||||||
it { should be_able_to(:create, Comment) }
|
|
||||||
it { should be_able_to(:vote, Comment) }
|
|
||||||
|
|
||||||
it { should be_able_to(:index, Proposal) }
|
it { should be_able_to(:index, Proposal) }
|
||||||
it { should be_able_to(:show, proposal) }
|
it { should be_able_to(:show, proposal) }
|
||||||
it { should_not be_able_to(:vote, Proposal) }
|
it { should_not be_able_to(:vote, Proposal) }
|
||||||
@@ -97,6 +94,14 @@ describe Abilities::Common do
|
|||||||
|
|
||||||
it { should_not be_able_to(:manage, LocalCensusRecord) }
|
it { should_not be_able_to(:manage, LocalCensusRecord) }
|
||||||
|
|
||||||
|
describe "Comment" do
|
||||||
|
it { should be_able_to(:create, Comment) }
|
||||||
|
it { should be_able_to(:vote, Comment) }
|
||||||
|
|
||||||
|
it { should be_able_to(:hide, own_comment) }
|
||||||
|
it { should_not be_able_to(:hide, comment) }
|
||||||
|
end
|
||||||
|
|
||||||
describe "flagging content" do
|
describe "flagging content" do
|
||||||
it { should be_able_to(:flag, debate) }
|
it { should be_able_to(:flag, debate) }
|
||||||
it { should be_able_to(:unflag, debate) }
|
it { should be_able_to(:unflag, debate) }
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ describe Abilities::Moderator do
|
|||||||
it { should be_able_to(:hide, comment) }
|
it { should be_able_to(:hide, comment) }
|
||||||
it { should be_able_to(:hide_in_moderation_screen, comment) }
|
it { should be_able_to(:hide_in_moderation_screen, comment) }
|
||||||
it { should_not be_able_to(:hide, hidden_comment) }
|
it { should_not be_able_to(:hide, hidden_comment) }
|
||||||
it { should_not be_able_to(:hide, own_comment) }
|
it { should be_able_to(:hide, own_comment) }
|
||||||
|
|
||||||
it { should be_able_to(:moderate, comment) }
|
it { should be_able_to(:moderate, comment) }
|
||||||
it { should_not be_able_to(:moderate, own_comment) }
|
it { should_not be_able_to(:moderate, own_comment) }
|
||||||
|
|||||||
@@ -235,6 +235,58 @@ describe "Commenting debates" do
|
|||||||
expect(page).to have_content "Can't be blank"
|
expect(page).to have_content "Can't be blank"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "Hide" do
|
||||||
|
scenario "Without replies" do
|
||||||
|
create(:comment, commentable: debate, user: user, body: "This was a mistake")
|
||||||
|
|
||||||
|
login_as(user)
|
||||||
|
visit debate_path(debate)
|
||||||
|
|
||||||
|
accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do
|
||||||
|
within(".comment-body", text: "This was a mistake") { click_link "Delete comment" }
|
||||||
|
end
|
||||||
|
|
||||||
|
expect(page).not_to have_content "This was a mistake"
|
||||||
|
expect(page).not_to have_link "Delete comment"
|
||||||
|
|
||||||
|
visit debate_path(debate)
|
||||||
|
|
||||||
|
expect(page).not_to have_content "This was a mistake"
|
||||||
|
expect(page).not_to have_link "Delete comment"
|
||||||
|
|
||||||
|
logout
|
||||||
|
login_as(create(:administrator).user)
|
||||||
|
|
||||||
|
visit admin_hidden_comments_path
|
||||||
|
|
||||||
|
expect(page).to have_content "This was a mistake"
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario "With replies" do
|
||||||
|
comment = create(:comment, commentable: debate, user: user, body: "Wrong comment")
|
||||||
|
create(:comment, commentable: debate, parent: comment, body: "Right reply")
|
||||||
|
|
||||||
|
login_as(user)
|
||||||
|
visit debate_path(debate)
|
||||||
|
|
||||||
|
accept_confirm("Are you sure? This action will delete this comment. You can't undo this action.") do
|
||||||
|
within(".comment-body", text: "Wrong comment") { click_link "Delete comment" }
|
||||||
|
end
|
||||||
|
|
||||||
|
within "#comments > .comment-list > li", text: "Right reply" do
|
||||||
|
expect(page).to have_content "This comment has been deleted"
|
||||||
|
expect(page).not_to have_content "Wrong comment"
|
||||||
|
end
|
||||||
|
|
||||||
|
visit debate_path(debate)
|
||||||
|
|
||||||
|
within "#comments > .comment-list > li", text: "Right reply" do
|
||||||
|
expect(page).to have_content "This comment has been deleted"
|
||||||
|
expect(page).not_to have_content "Wrong comment"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scenario "Reply" do
|
scenario "Reply" do
|
||||||
citizen = create(:user, username: "Ana")
|
citizen = create(:user, username: "Ana")
|
||||||
manuela = create(:user, username: "Manuela")
|
manuela = create(:user, username: "Manuela")
|
||||||
|
|||||||
Reference in New Issue
Block a user