flags: raise flag limits.

The old flag limits were:

* 1 flag per day for regular members.
* 10 flags per day for Gold users.
* Unlimited flags for approvers.

The new flag limits are:

* 10 flags in the modqueue at once for regular users.
* Unlimited flags for approvers.
* Unlimited flags for users with a high enough flag success rate. If you
  have at least 30 flags in the last 3 months, and you have at least a
  70% flag success rate, then you get unlimited flags.

10 flags at once means you can have up to 10 flagged posts in the
modqueue at the same time. Because flags stay in the modqueue for 3
days, this means you can flag on average 10 posts every 3 days, or just
over 3 posts per day.
This commit is contained in:
evazion
2020-08-08 12:17:16 -05:00
parent e8dcc9c56e
commit 3210da1a23
4 changed files with 79 additions and 117 deletions

View File

@@ -3,64 +3,36 @@ require 'test_helper'
class PostApprovalTest < ActiveSupport::TestCase
context "a pending post" do
setup do
@user = FactoryBot.create(:user, created_at: 2.weeks.ago)
CurrentUser.user = @user
CurrentUser.ip_addr = "127.0.0.1"
@post = FactoryBot.create(:post, uploader_id: @user.id, tag_string: "touhou", is_pending: true)
@approver = FactoryBot.create(:user)
@approver.can_approve_posts = true
@approver.save
CurrentUser.user = @approver
CurrentUser.stubs(:can_approve_posts?).returns(true)
end
teardown do
CurrentUser.user = nil
CurrentUser.ip_addr = nil
@user = create(:user, created_at: 2.weeks.ago)
@post = create(:post, uploader: @user, is_pending: true)
@approver = create(:user, can_approve_posts: true)
end
context "That is approved" do
should "create a postapproval record" do
assert_difference("PostApproval.count") do
@post.approve!
@post.approve!(@approver)
end
end
context "that is then flagged" do
setup do
@user2 = create(:user, created_at: 2.weeks.ago)
@user3 = create(:user, created_at: 2.weeks.ago)
@approver2 = FactoryBot.create(:user)
@approver2.can_approve_posts = true
@approver2.save
end
should "prevent an approver from approving the same post twice" do
@approval1 = create(:post_approval, post: @post, user: @approver)
@approval2 = build(:post_approval, post: @post, user: @approver)
should "prevent the first approver from approving again" do
@post.approve!(@approver)
CurrentUser.user = @user2
@post.flag!("blah")
@post.approve!(@approver2)
assert_not_equal(@approver.id, @post.approver_id)
CurrentUser.user = @user3
travel(PostFlag::COOLDOWN_PERIOD + 1.minute) do
@post.flag!("blah blah")
end
approval = @post.approve!(@approver)
assert_includes(approval.errors.full_messages, "You have previously approved this post and cannot approve it again")
end
assert_equal(false, @approval2.valid?)
assert_equal(["You have previously approved this post and cannot approve it again"], @approval2.errors[:base])
end
end
context "#search method" do
should "work" do
@approval = @post.approve!(@approver)
@approvals = PostApproval.search(user_name: @approver.name, post_tags_match: "touhou", post_id: @post.id)
CurrentUser.scoped(@approver) do
@post.update!(tag_string: "touhou")
@approval = @post.approve!(@approver)
@approvals = PostApproval.search(user_name: @approver.name, post_tags_match: "touhou", post_id: @post.id)
assert_equal([@approval.id], @approvals.map(&:id))
assert_equal([@approval.id], @approvals.map(&:id))
end
end
end
end