add additional constraints on upload limit

This commit is contained in:
albert
2013-03-21 15:23:38 -07:00
parent 5ba535efd3
commit 8caf7fd796
2 changed files with 7 additions and 26 deletions

View File

@@ -433,14 +433,14 @@ class User < ActiveRecord::Base
end
def upload_limit
deleted_count = Post.for_user(id).deleted.count
pending_count = Post.for_user(id).pending.count
approved_count = Post.where("is_flagged = false and is_pending = false and is_deleted = false and uploader_id = ?", id).count
deleted_count = Post.for_user(id).deleted.where("created_at >= ?", 1.month.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.month.ago).count
if base_upload_limit
limit = base_upload_limit - pending_count
limit = base_upload_limit - (deleted_count / 5) - pending_count
else
limit = 10 + (approved_count / 10) - (deleted_count / 4) - pending_count
limit = 10 + (approved_count / 10) - (deleted_count / 5) - pending_count
end
if limit < 0

View File

@@ -37,27 +37,8 @@ class UserPresenter
if user.is_contributor?
return "none"
end
deleted_count = Post.for_user(user.id).deleted.count
pending_count = Post.for_user(user.id).pending.count
approved_count = Post.where("is_flagged = false and is_pending = false and is_deleted = false and uploader_id = ?", user.id).count
if user.base_upload_limit
limit = user.base_upload_limit - pending_count
string = "base:#{user.base_upload_limit} - pending:#{pending_count}"
else
limit = 10 + (approved_count / 10) - (deleted_count / 4) - pending_count
string = "base:10 + approved:(#{approved_count} / 10) - deleted:(#{deleted_count}) / 4 - pending:#{pending_count}"
end
if limit < 0
limit = 0
string += " = 0"
else
string += " = #{limit}"
end
return string
return user.upload_limit.to_s
end
def uploads