FIX: Staff was getting 500 when editing post in deleted topic

This commit is contained in:
Robin Ward
2015-11-13 11:35:23 -05:00
parent 6b1cc8d486
commit 3939331dec
4 changed files with 45 additions and 14 deletions
+10 -4
View File
@@ -130,6 +130,9 @@ class PostsController < ApplicationController
post = Post.where(id: params[:id])
post = post.with_deleted if guardian.is_staff?
post = post.first
raise Discourse::NotFound if post.blank?
post.image_sizes = params[:image_sizes] if params[:image_sizes].present?
if too_late_to(:edit, post)
@@ -155,15 +158,18 @@ class PostsController < ApplicationController
opts[:skip_validations] = true
end
revisor = PostRevisor.new(post)
topic = post.topic
topic = Topic.with_deleted.find(post.topic_id) if guardian.is_staff?
revisor = PostRevisor.new(post, topic)
revisor.revise!(current_user, changes, opts)
return render_json_error(post) if post.errors.present?
return render_json_error(post.topic) if post.topic.errors.present?
return render_json_error(topic) if topic.errors.present?
post_serializer = PostSerializer.new(post, scope: guardian, root: false)
post_serializer.draft_sequence = DraftSequence.current(current_user, post.topic.draft_key)
link_counts = TopicLink.counts_for(guardian,post.topic, [post])
post_serializer.draft_sequence = DraftSequence.current(current_user, topic.draft_key)
link_counts = TopicLink.counts_for(guardian, topic, [post])
post_serializer.single_post_link_counts = link_counts[post.id] if link_counts.present?
result = { post: post_serializer.as_json }
+1
View File
@@ -46,6 +46,7 @@ class UserActionObserver < ActiveRecord::Observer
def self.log_post(model)
# first post gets nada
return if model.is_first_post?
return if model.topic.blank?
row = {
action_type: UserAction::REPLY,
+1 -1
View File
@@ -200,7 +200,7 @@ class PostAlerter
def notify_users(users, type, post)
users = [users] unless users.is_a?(Array)
if post.topic.private_message?
if post.topic.try(:private_message?)
whitelist = allowed_users(post)
users.reject! {|u| !whitelist.include?(u)}
end