From 60cb5ea6a9c73cf0a5a65d10c69fcb48fbd7d9cb Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 18 Jun 2014 17:39:12 -0400 Subject: [PATCH] FIX: If a user is deleted, don't break embedded comments for admins. --- app/controllers/embed_controller.rb | 8 +++++++- lib/topic_view.rb | 1 + spec/controllers/embed_controller_spec.rb | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/embed_controller.rb b/app/controllers/embed_controller.rb index 9100ce06b..8a6ee04b9 100644 --- a/app/controllers/embed_controller.rb +++ b/app/controllers/embed_controller.rb @@ -13,7 +13,13 @@ class EmbedController < ApplicationController topic_id = TopicEmbed.topic_id_for_embed(embed_url) if topic_id - @topic_view = TopicView.new(topic_id, current_user, limit: SiteSetting.embed_post_limit, exclude_first: true) + @topic_view = TopicView.new(topic_id, + current_user, + limit: SiteSetting.embed_post_limit, + exclude_first: true, + exclude_deleted_users: true) + @topic_view.posts.reject! {|p| p.user.blank?} + @second_post_url = "#{@topic_view.topic.url}/2" if @topic_view @posts_left = 0 if @topic_view && @topic_view.posts.size == SiteSetting.embed_post_limit diff --git a/lib/topic_view.rb b/lib/topic_view.rb index 65d01bddb..07f215c12 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -307,6 +307,7 @@ class TopicView def unfiltered_posts result = @topic.posts result = result.with_deleted if @user.try(:staff?) + result = @topic.posts.where("user_id IS NOT NULL") if @exclude_deleted_users result end diff --git a/spec/controllers/embed_controller_spec.rb b/spec/controllers/embed_controller_spec.rb index 5fc1d4f22..02448a1b5 100644 --- a/spec/controllers/embed_controller_spec.rb +++ b/spec/controllers/embed_controller_spec.rb @@ -47,7 +47,7 @@ describe EmbedController do it "creates a topic view when a topic_id is found" do TopicEmbed.expects(:topic_id_for_embed).returns(123) - TopicView.expects(:new).with(123, nil, {limit: 100, exclude_first: true}) + TopicView.expects(:new).with(123, nil, {limit: 100, exclude_first: true, exclude_deleted_users: true}) get :comments, embed_url: embed_url end end