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