From fe7f3d8204011b4ed8e2c913b2f6d4e14a9a87cc Mon Sep 17 00:00:00 2001 From: Toks Date: Sat, 11 Jul 2015 13:20:47 -0400 Subject: [PATCH] Keep track of who deletes forum post/topic/comment Previously it would look like the creator of it was the one who deleted/undeleted it, even if it was someone else. --- app/controllers/forum_topics_controller.rb | 4 ++-- app/models/comment.rb | 2 +- app/models/forum_post.rb | 4 ++-- app/models/forum_topic.rb | 8 ++++++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index 2caae332d..b9d241a05 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -51,7 +51,7 @@ class ForumTopicsController < ApplicationController def destroy @forum_topic = ForumTopic.find(params[:id]) check_privilege(@forum_topic) - @forum_topic.update_column(:is_deleted, true) + @forum_topic.delete! flash[:notice] = "Topic deleted" respond_with(@forum_topic) end @@ -59,7 +59,7 @@ class ForumTopicsController < ApplicationController def undelete @forum_topic = ForumTopic.find(params[:id]) check_privilege(@forum_topic) - @forum_topic.update_column(:is_deleted, false) + @forum_topic.undelete! flash[:notice] = "Topic undeleted" respond_with(@forum_topic) end diff --git a/app/models/comment.rb b/app/models/comment.rb index 16fec1a72..0521ba47c 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -173,7 +173,7 @@ class Comment < ActiveRecord::Base end def delete! - update_attribute(:is_deleted, true) + update_attributes(:is_deleted => true) end end diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 994fe9623..d8bfde6e0 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -128,12 +128,12 @@ class ForumPost < ActiveRecord::Base end def delete! - update_attribute(:is_deleted, true) + update_attributes(:is_deleted => true) update_topic_updated_at_on_delete end def undelete! - update_attribute(:is_deleted, false) + update_attributes(:is_deleted => false) update_topic_updated_at_on_undelete end diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index ed23fdb83..24323e357 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -151,4 +151,12 @@ class ForumTopic < ActiveRecord::Base topic.update_attribute(:response_count, topic.response_count + self.posts.length) self.update_columns(:response_count => 0, :is_deleted => true) end + + def delete! + update_attributes(:is_deleted => true) + end + + def undelete! + update_attributes(:is_deleted => false) + end end