diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index b790977e2..1c8745dae 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -62,6 +62,15 @@ class CommentsController < ApplicationController end end + def undelete + @comment = Comment.find(params[:id]) + check_privilege(@comment) + @comment.undelete! + respond_with(@comment) do |format| + format.js + end + end + def unvote @comment = Comment.find(params[:id]) @comment.unvote! diff --git a/app/models/comment.rb b/app/models/comment.rb index 0521ba47c..1b0b08660 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -9,7 +9,7 @@ class Comment < ActiveRecord::Base before_validation :initialize_updater after_create :update_last_commented_at_on_create after_destroy :update_last_commented_at_on_destroy - attr_accessible :body, :post_id, :do_not_bump_post + attr_accessible :body, :post_id, :do_not_bump_post, :is_deleted module SearchMethods def recent @@ -175,6 +175,10 @@ class Comment < ActiveRecord::Base def delete! update_attributes(:is_deleted => true) end + + def undelete! + update_attributes(:is_deleted => false) + end end Comment.connection.extend(PostgresExtensions) diff --git a/app/views/comments/partials/show/_comment.html.erb b/app/views/comments/partials/show/_comment.html.erb index 0856a738d..e63efed59 100644 --- a/app/views/comments/partials/show/_comment.html.erb +++ b/app/views/comments/partials/show/_comment.html.erb @@ -25,7 +25,11 @@ <% 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 %>
  • + <% if comment.is_deleted? %> +
  • <%= link_to "Undelete", undelete_comment_path(comment.id), :method => :post, :remote => true %>
  • + <% else %> +
  • <%= link_to "Delete", comment_path(comment.id), :data => {:confirm => "Are you sure you want to delete this comment?"}, :method => :delete, :remote => true %>
  • + <% end %>
  • <%= link_to "Edit", edit_comment_path(comment.id), :id => "edit_comment_link_#{comment.id}", :class => "edit_comment_link" %>
  • <% end %> diff --git a/app/views/comments/undelete.js.erb b/app/views/comments/undelete.js.erb new file mode 100644 index 000000000..345366b9b --- /dev/null +++ b/app/views/comments/undelete.js.erb @@ -0,0 +1 @@ +location.reload(); diff --git a/config/routes.rb b/config/routes.rb index 9a7f03ad3..669399f74 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -96,6 +96,7 @@ Rails.application.routes.draw do end member do put :unvote + post :undelete end end resources :counts do