tweak upload limit
This commit is contained in:
@@ -435,12 +435,12 @@ class User < ActiveRecord::Base
|
|||||||
def upload_limit
|
def upload_limit
|
||||||
deleted_count = Post.for_user(id).deleted.where("created_at >= ?", 3.months.ago).count
|
deleted_count = Post.for_user(id).deleted.where("created_at >= ?", 3.months.ago).count
|
||||||
pending_count = Post.for_user(id).pending.where("created_at >= ?", 3.days.ago).count
|
pending_count = Post.for_user(id).pending.where("created_at >= ?", 3.days.ago).count
|
||||||
approved_count = Post.where("is_flagged = false and is_pending = false and is_deleted = false and uploader_id = ? and created_at >= ?", id, 1.year.ago).count
|
approved_count = Post.where("is_flagged = false and is_pending = false and is_deleted = false and uploader_id = ? and created_at >= ?", id, 3.months.ago).count
|
||||||
|
|
||||||
if base_upload_limit.to_i != 0
|
if base_upload_limit.to_i != 0
|
||||||
limit = [base_upload_limit - (deleted_count / 2), 4].max - pending_count
|
limit = [base_upload_limit - (deleted_count / 4), 4].max - pending_count
|
||||||
else
|
else
|
||||||
limit = [10 + [approved_count / 2, 90].min - ([deleted_count / 10, 90].min), 4].max - pending_count
|
limit = [10 + (approved_count / 2) - (deleted_count / 4), 4].max - pending_count
|
||||||
end
|
end
|
||||||
|
|
||||||
if limit < 0
|
if limit < 0
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ class UserPresenter
|
|||||||
approved_count = Post.where("is_flagged = false and is_pending = false and is_deleted = false and uploader_id = ? and created_at >= ?", user.id, 1.year.ago).count
|
approved_count = Post.where("is_flagged = false and is_pending = false and is_deleted = false and uploader_id = ? and created_at >= ?", user.id, 1.year.ago).count
|
||||||
|
|
||||||
if user.base_upload_limit.to_i != 0
|
if user.base_upload_limit.to_i != 0
|
||||||
string = "max(base_upload_limit:#{user.base_upload_limit} - (deleted_count:#{deleted_count} / 2), 4) - pending_count:#{pending_count}"
|
string = "max(base_upload_limit:#{user.base_upload_limit} - (deleted_count:#{deleted_count} / 4), 4) - pending_count:#{pending_count}"
|
||||||
else
|
else
|
||||||
string = "max(10 + min(approved_count:#{approved_count} / 2, 90) - (min(deleted_count:#{deleted_count} / 10), 90), 4) - pending_count:#{pending_count}"
|
string = "max(10 + (approved_count:#{approved_count} / 2) - (deleted_count:#{deleted_count} / 4), 4) - pending_count:#{pending_count}"
|
||||||
end
|
end
|
||||||
|
|
||||||
"#{string} = #{user.upload_limit} (deletions and approvals within past month)"
|
"#{string} = #{user.upload_limit} (deletions + approved within past 3 months)"
|
||||||
end
|
end
|
||||||
|
|
||||||
def uploads
|
def uploads
|
||||||
|
|||||||
@@ -764,20 +764,6 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Paginating:" do
|
|
||||||
setup do
|
|
||||||
CurrentUser.user.stubs(:per_page).returns(3)
|
|
||||||
4.times do
|
|
||||||
FactoryGirl.create(:post)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
should "delegate the default limit to the user" do
|
|
||||||
posts = Post.tag_match("").paginate(1).all
|
|
||||||
assert_equal(3, posts.size)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "Searching:" do
|
context "Searching:" do
|
||||||
should "return posts for the ' tag" do
|
should "return posts for the ' tag" do
|
||||||
|
|||||||
Reference in New Issue
Block a user