diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 28481b569..b790977e2 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -56,7 +56,7 @@ class CommentsController < ApplicationController def destroy @comment = Comment.find(params[:id]) check_privilege(@comment) - @comment.destroy + @comment.delete! respond_with(@comment) do |format| format.js end diff --git a/app/models/comment.rb b/app/models/comment.rb index fae80c47a..16fec1a72 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -171,6 +171,10 @@ class Comment < ActiveRecord::Base def hidden_attributes super + [:body_index] end + + def delete! + update_attribute(:is_deleted, true) + end end Comment.connection.extend(PostgresExtensions) diff --git a/app/views/comments/destroy.js.erb b/app/views/comments/destroy.js.erb index 59cc3d88e..679b8ccc2 100644 --- a/app/views/comments/destroy.js.erb +++ b/app/views/comments/destroy.js.erb @@ -1 +1 @@ -$(".comment[data-comment-id=<%= @comment.id %>]").remove(); +$(".comment[data-comment-id=<%= @comment.id %>] div.author h1").append(" (deleted)"); diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index 94a69dd16..0856a738d 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -1,36 +1,43 @@ -
-
-

<%= link_to_user comment.creator %>

-

- <%= time_ago_in_words_tagged(comment.created_at) %> -

-
-
-
- <%= format_text(comment.body) %> +<% if CurrentUser.is_moderator? || !comment.is_deleted? %> +
+
+

+ <%= link_to_user comment.creator %> + <% if comment.is_deleted? %> + (deleted) + <% end %> +

+

+ <%= time_ago_in_words_tagged(comment.created_at) %> +

+
+
+
+ <%= format_text(comment.body) %> - <% if comment.updated_at - comment.created_at > 5.minutes %> -

Updated by <%= link_to_user comment.updater %> <%= time_ago_in_words_tagged(comment.updated_at) %>

+ <% if comment.updated_at - comment.created_at > 5.minutes %> +

Updated by <%= link_to_user comment.updater %> <%= time_ago_in_words_tagged(comment.updated_at) %>

+ <% end %> +
+ + <% if CurrentUser.is_member? %> + + <% if @post || @posts %> +
  • <%= link_to "Reply", new_comment_path(:post_id => comment.post_id), :class => "reply-link", "data-comment-id" => comment.id %>
  • + <% if comment.editable_by?(CurrentUser.user) %> +
  • <%= link_to "Delete", comment_path(comment.id), :data => {:confirm => "Are you sure you want to delete this comment?"}, :method => :delete, :remote => true %>
  • +
  • <%= link_to "Edit", edit_comment_path(comment.id), :id => "edit_comment_link_#{comment.id}", :class => "edit_comment_link" %>
  • + <% end %> + + + + <% end %> +
    + <% if comment.editable_by?(CurrentUser.user) %> + <%= render "comments/form", :comment => comment %> + <% end %> <% end %>
    - - <% if CurrentUser.is_member? %> - - <% if @post || @posts %> -
  • <%= link_to "Reply", new_comment_path(:post_id => comment.post_id), :class => "reply-link", "data-comment-id" => comment.id %>
  • - <% if comment.editable_by?(CurrentUser.user) %> -
  • <%= link_to "Delete", comment_path(comment.id), :data => {:confirm => "Are you sure you want to delete this comment?"}, :method => :delete, :remote => true %>
  • -
  • <%= link_to "Edit", edit_comment_path(comment.id), :id => "edit_comment_link_#{comment.id}", :class => "edit_comment_link" %>
  • - <% end %> - - - - <% end %> -
    - <% if comment.editable_by?(CurrentUser.user) %> - <%= render "comments/form", :comment => comment %> - <% end %> - <% end %> -
    -
    -
    +
    + +<% end %> diff --git a/db/migrate/20150705014135_add_is_deleted_to_comments.rb b/db/migrate/20150705014135_add_is_deleted_to_comments.rb new file mode 100644 index 000000000..dd0b2f86b --- /dev/null +++ b/db/migrate/20150705014135_add_is_deleted_to_comments.rb @@ -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