diff --git a/app/models/discussion_topic.rb b/app/models/discussion_topic.rb index 4f24967990f..c476d25e008 100644 --- a/app/models/discussion_topic.rb +++ b/app/models/discussion_topic.rb @@ -423,7 +423,7 @@ class DiscussionTopic < ActiveRecord::Base def user_ids_who_have_posted_and_admins ids = DiscussionEntry.active.scoped(:select => "distinct user_id").find_all_by_discussion_topic_id(self.id).map(&:user_id) - ids += self.context.admin_enrollments.scoped(:select => 'user_id').map(&:user_id) if self.context.respond_to?(:admin_enrollments) + ids += self.context.admin_enrollments.active.scoped(:select => 'user_id').map(&:user_id) if self.context.respond_to?(:admin_enrollments) ids end memoize :user_ids_who_have_posted_and_admins diff --git a/spec/models/discussion_topic_spec.rb b/spec/models/discussion_topic_spec.rb index 504d08d76f5..2e7f735ccc4 100644 --- a/spec/models/discussion_topic_spec.rb +++ b/spec/models/discussion_topic_spec.rb @@ -414,6 +414,18 @@ describe DiscussionTopic do @topic.user_can_see_posts?(@teacher).should == true end + it "should only allow active admins to see posts without posting" do + @ta_enrollment = course_with_ta(:course => @course, :active_enrollment => true) + # TA should be able to see + @topic.user_can_see_posts?(@ta).should == true + # Remove user as TA and enroll as student, should not be able to see + @ta_enrollment.destroy + # enroll as a student. + course_with_student(:course => @course, :user => @ta, :active_enrollment => true) + @topic.reload + @topic.user_can_see_posts?(@ta).should == false + end + it "shouldn't allow student (and observer) who hasn't posted to see" do @topic.user_can_see_posts?(@student).should == false end