fixes #920
This commit is contained in:
@@ -47,7 +47,7 @@ class ForumPostsController < ApplicationController
|
||||
|
||||
def destroy
|
||||
@forum_post = ForumPost.find(params[:id])
|
||||
raise User::PrivilegeError unless CurrentUser.is_janitor?
|
||||
raise User::PrivilegeError unless @forum_post.editable_by?(CurrentUser.user)
|
||||
@forum_post.update_attribute(:is_deleted, true)
|
||||
respond_with(@forum_post)
|
||||
end
|
||||
|
||||
@@ -10,6 +10,7 @@ class ForumPost < ActiveRecord::Base
|
||||
validates_presence_of :body, :creator_id
|
||||
validate :validate_topic_is_unlocked
|
||||
before_destroy :validate_topic_is_unlocked
|
||||
after_save :delete_topic_if_original_post
|
||||
|
||||
module SearchMethods
|
||||
def body_matches(body)
|
||||
@@ -122,6 +123,14 @@ class ForumPost < ActiveRecord::Base
|
||||
ForumPost.exists?(["id = ? and id = (select _.id from forum_posts _ where _.topic_id = ? order by _.id asc limit 1)", id, topic_id])
|
||||
end
|
||||
|
||||
def delete_topic_if_original_post
|
||||
if is_deleted? && is_original_post?
|
||||
topic.update_attribute(:is_deleted, true)
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def build_response
|
||||
dup.tap do |x|
|
||||
x.body = x.quoted_response
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<%= f.input :title %>
|
||||
|
||||
<%= f.simple_fields_for :original_post do |pf| %>
|
||||
<% unless @forum_topic.new_record? %>
|
||||
<% if !@forum_topic.new_record? %>
|
||||
<%= hidden_field_tag "forum_topic[original_post_attributes][topic_id]", @forum_topic.id %>
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -69,6 +69,18 @@ class ForumPostTest < ActiveSupport::TestCase
|
||||
assert_equal(@user.id, post.creator_id)
|
||||
end
|
||||
|
||||
context "that is deleted" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
|
||||
@post.update_attribute(:is_deleted, true)
|
||||
@topic.reload
|
||||
end
|
||||
|
||||
should "also delete the topic" do
|
||||
assert(@topic.is_deleted)
|
||||
end
|
||||
end
|
||||
|
||||
context "updated by a second user" do
|
||||
setup do
|
||||
@post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
|
||||
|
||||
Reference in New Issue
Block a user