mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Hide deleted posts by default for staff
This commit is contained in:
@@ -326,6 +326,15 @@ describe Guardian do
|
||||
Guardian.new(user).can_see?(topic).should be_true
|
||||
end
|
||||
|
||||
it "restricts deleted topics" do
|
||||
topic = Fabricate(:topic)
|
||||
topic.trash!(moderator)
|
||||
|
||||
Guardian.new(build(:user)).can_see?(topic).should be_false
|
||||
Guardian.new(moderator).can_see?(topic).should be_true
|
||||
Guardian.new(admin).can_see?(topic).should be_true
|
||||
end
|
||||
|
||||
it "restricts private topics" do
|
||||
user.save!
|
||||
private_topic = Fabricate(:private_message_topic, user: user)
|
||||
@@ -334,6 +343,17 @@ describe Guardian do
|
||||
Guardian.new(moderator).can_see?(private_topic).should be_false
|
||||
Guardian.new(admin).can_see?(private_topic).should be_true
|
||||
end
|
||||
|
||||
it "restricts private deleted topics" do
|
||||
user.save!
|
||||
private_topic = Fabricate(:private_message_topic, user: user)
|
||||
private_topic.trash!(admin)
|
||||
|
||||
Guardian.new(private_topic.user).can_see?(private_topic).should be_false
|
||||
Guardian.new(build(:user)).can_see?(private_topic).should be_false
|
||||
Guardian.new(moderator).can_see?(private_topic).should be_false
|
||||
Guardian.new(admin).can_see?(private_topic).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
describe 'a Post' do
|
||||
|
@@ -218,13 +218,14 @@ describe TopicView do
|
||||
let!(:p6) { Fabricate(:post, topic: topic, user: Fabricate(:user), deleted_at: Time.now)}
|
||||
let!(:p4) { Fabricate(:post, topic: topic, user: coding_horror, deleted_at: Time.now)}
|
||||
let!(:p1) { Fabricate(:post, topic: topic, user: first_poster)}
|
||||
let!(:p7) { Fabricate(:post, topic: topic, user: coding_horror, deleted_at: Time.now)}
|
||||
let!(:p3) { Fabricate(:post, topic: topic, user: first_poster)}
|
||||
|
||||
before do
|
||||
SiteSetting.posts_per_page = 3
|
||||
|
||||
# Update them to the sort order we're checking for
|
||||
[p1, p2, p3, p4, p5, p6].each_with_index do |p, idx|
|
||||
[p1, p2, p3, p4, p5, p6, p7].each_with_index do |p, idx|
|
||||
p.sort_order = idx + 1
|
||||
p.save
|
||||
end
|
||||
@@ -277,40 +278,64 @@ describe TopicView do
|
||||
|
||||
describe "filter_posts_near" do
|
||||
|
||||
def topic_view_near(post)
|
||||
TopicView.new(topic.id, coding_horror, post_number: post.post_number)
|
||||
def topic_view_near(post, show_deleted=false)
|
||||
TopicView.new(topic.id, coding_horror, post_number: post.post_number, show_deleted: show_deleted)
|
||||
end
|
||||
|
||||
it "snaps to the lower boundary" do
|
||||
near_view = topic_view_near(p1)
|
||||
near_view.desired_post.should == p1
|
||||
near_view.posts.should == [p1, p2, p3]
|
||||
near_view.contains_gaps?.should be_false
|
||||
end
|
||||
|
||||
it "snaps to the upper boundary" do
|
||||
near_view = topic_view_near(p5)
|
||||
near_view.desired_post.should == p5
|
||||
near_view.posts.should == [p2, p3, p5]
|
||||
near_view.contains_gaps?.should be_false
|
||||
end
|
||||
|
||||
it "returns the posts in the middle" do
|
||||
near_view = topic_view_near(p2)
|
||||
near_view.desired_post.should == p2
|
||||
near_view.posts.should == [p1, p2, p3]
|
||||
near_view.contains_gaps?.should be_false
|
||||
end
|
||||
|
||||
it "returns deleted posts to an admin" do
|
||||
it "gaps deleted posts to an admin" do
|
||||
coding_horror.admin = true
|
||||
near_view = topic_view_near(p3)
|
||||
near_view.desired_post.should == p3
|
||||
near_view.posts.should == [p2, p3, p4]
|
||||
near_view.posts.should == [p2, p3, p5]
|
||||
near_view.gaps.before.should == {p5.id => [p4.id]}
|
||||
near_view.gaps.after.should == {p5.id => [p6.id, p7.id]}
|
||||
end
|
||||
|
||||
it "returns deleted posts by nuked users to an admin" do
|
||||
it "returns deleted posts to an admin with show_deleted" do
|
||||
coding_horror.admin = true
|
||||
near_view = topic_view_near(p3, true)
|
||||
near_view.desired_post.should == p3
|
||||
near_view.posts.should == [p2, p3, p4]
|
||||
near_view.contains_gaps?.should be_false
|
||||
end
|
||||
|
||||
it "gaps deleted posts by nuked users to an admin" do
|
||||
coding_horror.admin = true
|
||||
near_view = topic_view_near(p5)
|
||||
near_view.desired_post.should == p5
|
||||
# note: both p4 and p6 get skipped
|
||||
near_view.posts.should == [p2, p3, p5]
|
||||
near_view.gaps.before.should == {p5.id => [p4.id]}
|
||||
near_view.gaps.after.should == {p5.id => [p6.id, p7.id]}
|
||||
end
|
||||
|
||||
it "returns deleted posts by nuked users to an admin with show_deleted" do
|
||||
coding_horror.admin = true
|
||||
near_view = topic_view_near(p5, true)
|
||||
near_view.desired_post.should == p5
|
||||
near_view.posts.should == [p4, p5, p6]
|
||||
near_view.contains_gaps?.should be_false
|
||||
end
|
||||
|
||||
context "when 'posts per page' exceeds the number of posts" do
|
||||
@@ -319,12 +344,22 @@ describe TopicView do
|
||||
it 'returns all the posts' do
|
||||
near_view = topic_view_near(p5)
|
||||
near_view.posts.should == [p1, p2, p3, p5]
|
||||
near_view.contains_gaps?.should be_false
|
||||
end
|
||||
|
||||
it 'gaps deleted posts to admins' do
|
||||
coding_horror.admin = true
|
||||
near_view = topic_view_near(p5)
|
||||
near_view.posts.should == [p1, p2, p3, p5]
|
||||
near_view.gaps.before.should == {p5.id => [p4.id]}
|
||||
near_view.gaps.after.should == {p5.id => [p6.id, p7.id]}
|
||||
end
|
||||
|
||||
it 'returns deleted posts to admins' do
|
||||
coding_horror.admin = true
|
||||
near_view = topic_view_near(p5)
|
||||
near_view.posts.should == [p1, p2, p3, p4, p5, p6]
|
||||
near_view = topic_view_near(p5, true)
|
||||
near_view.posts.should == [p1, p2, p3, p4, p5, p6, p7]
|
||||
near_view.contains_gaps?.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user