Delete all posts is allowed for the same amount of time as delete user

This commit is contained in:
Neil Lalonde 2013-08-13 11:10:50 -04:00
parent 9782d3777e
commit b8a1e21dbd
2 changed files with 7 additions and 5 deletions

View File

@ -203,7 +203,7 @@ class Guardian
end
def can_delete_all_posts?(user)
is_staff? && user && !user.admin? && user.created_at >= 7.days.ago && user.post_count <= SiteSetting.delete_all_posts_max.to_i
is_staff? && user && !user.admin? && user.created_at >= SiteSetting.delete_user_max_age.days.ago && user.post_count <= SiteSetting.delete_all_posts_max.to_i
end
def can_remove_allowed_users?(topic)

View File

@ -1045,12 +1045,14 @@ describe Guardian do
end
shared_examples "can_delete_all_posts examples" do
it "is true if user is newer than 7 days old" do
Guardian.new(actor).can_delete_all_posts?(Fabricate.build(:user, created_at: 6.days.ago)).should be_true
it "is true if user is newer than delete_user_max_age days old" do
SiteSetting.expects(:delete_user_max_age).returns(10)
Guardian.new(actor).can_delete_all_posts?(Fabricate.build(:user, created_at: 9.days.ago)).should be_true
end
it "is false if user is older than 7 days old" do
Guardian.new(actor).can_delete_all_posts?(Fabricate.build(:user, created_at: 8.days.ago)).should be_false
it "is false if user is older than delete_user_max_age days old" do
SiteSetting.expects(:delete_user_max_age).returns(10)
Guardian.new(actor).can_delete_all_posts?(Fabricate.build(:user, created_at: 11.days.ago)).should be_false
end
it "is false if user is an admin" do