fixes #2428
This commit is contained in:
@@ -56,7 +56,7 @@ class CommentsController < ApplicationController
|
|||||||
def destroy
|
def destroy
|
||||||
@comment = Comment.find(params[:id])
|
@comment = Comment.find(params[:id])
|
||||||
check_privilege(@comment)
|
check_privilege(@comment)
|
||||||
@comment.destroy
|
@comment.delete!
|
||||||
respond_with(@comment) do |format|
|
respond_with(@comment) do |format|
|
||||||
format.js
|
format.js
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -171,6 +171,10 @@ class Comment < ActiveRecord::Base
|
|||||||
def hidden_attributes
|
def hidden_attributes
|
||||||
super + [:body_index]
|
super + [:body_index]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def delete!
|
||||||
|
update_attribute(:is_deleted, true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Comment.connection.extend(PostgresExtensions)
|
Comment.connection.extend(PostgresExtensions)
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
$(".comment[data-comment-id=<%= @comment.id %>]").remove();
|
$(".comment[data-comment-id=<%= @comment.id %>] div.author h1").append(" (deleted)");
|
||||||
|
|||||||
@@ -1,36 +1,43 @@
|
|||||||
<article class="comment" data-post-id="<%= comment.post_id %>" data-comment-id="<%= comment.id %>" data-score="<%= comment.score %>" data-creator="<%= comment.creator.name %>">
|
<% if CurrentUser.is_moderator? || !comment.is_deleted? %>
|
||||||
<div class="author">
|
<article class="comment" data-post-id="<%= comment.post_id %>" data-comment-id="<%= comment.id %>" data-score="<%= comment.score %>" data-creator="<%= comment.creator.name %>">
|
||||||
<h1><%= link_to_user comment.creator %></h1>
|
<div class="author">
|
||||||
<p>
|
<h1>
|
||||||
<%= time_ago_in_words_tagged(comment.created_at) %>
|
<%= link_to_user comment.creator %>
|
||||||
</p>
|
<% if comment.is_deleted? %>
|
||||||
</div>
|
(deleted)
|
||||||
<div class="content">
|
<% end %>
|
||||||
<div class="body prose">
|
</h1>
|
||||||
<%= format_text(comment.body) %>
|
<p>
|
||||||
|
<%= time_ago_in_words_tagged(comment.created_at) %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="content">
|
||||||
|
<div class="body prose">
|
||||||
|
<%= format_text(comment.body) %>
|
||||||
|
|
||||||
<% if comment.updated_at - comment.created_at > 5.minutes %>
|
<% if comment.updated_at - comment.created_at > 5.minutes %>
|
||||||
<p class="info">Updated by <%= link_to_user comment.updater %> <%= time_ago_in_words_tagged(comment.updated_at) %></p>
|
<p class="info">Updated by <%= link_to_user comment.updater %> <%= time_ago_in_words_tagged(comment.updated_at) %></p>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<% if CurrentUser.is_member? %>
|
||||||
|
<menu>
|
||||||
|
<% if @post || @posts %>
|
||||||
|
<li><%= link_to "Reply", new_comment_path(:post_id => comment.post_id), :class => "reply-link", "data-comment-id" => comment.id %></li>
|
||||||
|
<% if comment.editable_by?(CurrentUser.user) %>
|
||||||
|
<li><%= link_to "Delete", comment_path(comment.id), :data => {:confirm => "Are you sure you want to delete this comment?"}, :method => :delete, :remote => true %></li>
|
||||||
|
<li><%= link_to "Edit", edit_comment_path(comment.id), :id => "edit_comment_link_#{comment.id}", :class => "edit_comment_link" %></li>
|
||||||
|
<% end %>
|
||||||
|
<li id="comment-vote-up-link-for-<%= comment.id %>"><%= link_to "Vote up", comment_votes_path(:comment_id => comment.id, :score => "up"), :method => :post, :remote => true %></li>
|
||||||
|
<li id="comment-vote-down-link-for-<%= comment.id %>"><%= link_to "Vote down", comment_votes_path(:comment_id => comment.id, :score => "down"), :method => :post, :remote => true %></li>
|
||||||
|
<li id="comment-unvote-link-for-<%= comment.id %>" class="unvote-comment-link"><%= link_to "Unvote", unvote_comment_path(comment.id), :method => :put, :remote => true %></li>
|
||||||
|
<% end %>
|
||||||
|
</menu>
|
||||||
|
<% if comment.editable_by?(CurrentUser.user) %>
|
||||||
|
<%= render "comments/form", :comment => comment %>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="clearfix"></div>
|
||||||
<% if CurrentUser.is_member? %>
|
</article>
|
||||||
<menu>
|
<% end %>
|
||||||
<% if @post || @posts %>
|
|
||||||
<li><%= link_to "Reply", new_comment_path(:post_id => comment.post_id), :class => "reply-link", "data-comment-id" => comment.id %></li>
|
|
||||||
<% if comment.editable_by?(CurrentUser.user) %>
|
|
||||||
<li><%= link_to "Delete", comment_path(comment.id), :data => {:confirm => "Are you sure you want to delete this comment?"}, :method => :delete, :remote => true %></li>
|
|
||||||
<li><%= link_to "Edit", edit_comment_path(comment.id), :id => "edit_comment_link_#{comment.id}", :class => "edit_comment_link" %></li>
|
|
||||||
<% end %>
|
|
||||||
<li id="comment-vote-up-link-for-<%= comment.id %>"><%= link_to "Vote up", comment_votes_path(:comment_id => comment.id, :score => "up"), :method => :post, :remote => true %></li>
|
|
||||||
<li id="comment-vote-down-link-for-<%= comment.id %>"><%= link_to "Vote down", comment_votes_path(:comment_id => comment.id, :score => "down"), :method => :post, :remote => true %></li>
|
|
||||||
<li id="comment-unvote-link-for-<%= comment.id %>" class="unvote-comment-link"><%= link_to "Unvote", unvote_comment_path(comment.id), :method => :put, :remote => true %></li>
|
|
||||||
<% end %>
|
|
||||||
</menu>
|
|
||||||
<% if comment.editable_by?(CurrentUser.user) %>
|
|
||||||
<%= render "comments/form", :comment => comment %>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<div class="clearfix"></div>
|
|
||||||
</article>
|
|
||||||
|
|||||||
6
db/migrate/20150705014135_add_is_deleted_to_comments.rb
Normal file
6
db/migrate/20150705014135_add_is_deleted_to_comments.rb
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class AddIsDeletedToComments < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
execute "set statement_timeout = 0"
|
||||||
|
add_column :comments, :is_deleted, :boolean, :null => false, :default => false
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user