change privileged accounts to gold accounts, add platinum accounts, add favorite and tag query limiting based on level

This commit is contained in:
albert
2013-02-20 00:02:43 -05:00
parent 8fb20c6b3a
commit 66fc05e30b
9 changed files with 63 additions and 12 deletions

View File

@@ -10,7 +10,11 @@ class FavoritesController < ApplicationController
end
def create
Post.find(params[:post_id]).add_favorite!(CurrentUser.user)
if CurrentUser.favorite_limit.nil? || CurrentUser.favorite_count < CurrentUser.favorite_limit
Post.find(params[:post_id]).add_favorite!(CurrentUser.user)
else
@error_msg = "You can only keep up to #{CurrentUser.favorite_limit} favorites. Upgrade your account to save more."
end
end
def destroy

View File

@@ -2,7 +2,9 @@ module Admin::UsersHelper
def user_level_select(object, field)
options = [
["Member", User::Levels::MEMBER],
["Privileged", User::Levels::PRIVILEGED],
["Gold", User::Levels::PRIVILEGED],
["Platinum", User::Levels::PLATINUM],
["Builder", User::Levels::BUILDER],
["Contributor", User::Levels::CONTRIBUTOR],
["Janitor", User::Levels::JANITOR],
["Moderator", User::Levels::MODERATOR],

View File

@@ -133,7 +133,19 @@ class AnonymousUser
:anonymous
end
%w(member banned privileged contributor janitor moderator admin).each do |name|
def tag_query_limit
2
end
def favorite_limit
0
end
def favorite_count
0
end
%w(member banned privileged platinum contributor janitor moderator admin).each do |name|
define_method("is_#{name}?") do
false
end

View File

@@ -49,24 +49,24 @@ class PostQueryBuilder
"''" + escaped_token + "''"
end
end
def add_tag_string_search_relation(tags, relation)
tag_query_sql = []
if tags[:include].any?
raise ::Post::SearchError.new("You cannot search for more than #{Danbooru.config.tag_query_limit} tags at a time") if tags[:include].size > Danbooru.config.tag_query_limit
raise ::Post::SearchError.new("You cannot search for more than #{CurrentUser.tag_query_limit} tags at a time") if tags[:include].size > CurrentUser.tag_query_limit
tag_query_sql << "(" + escape_string_for_tsquery(tags[:include]).join(" | ") + ")"
has_constraints!
end
if tags[:related].any?
raise ::Post::SearchError.new("You cannot search for more than #{Danbooru.config.tag_query_limit} tags at a time") if tags[:related].size > Danbooru.config.tag_query_limit
raise ::Post::SearchError.new("You cannot search for more than #{CurrentUser.tag_query_limit} tags at a time") if tags[:related].size > CurrentUser.tag_query_limit
tag_query_sql << "(" + escape_string_for_tsquery(tags[:related]).join(" & ") + ")"
has_constraints!
end
if tags[:exclude].any?
raise ::Post::SearchError.new("You cannot search for more than #{Danbooru.config.tag_query_limit} tags at a time") if tags[:exclude].size > Danbooru.config.tag_query_limit
raise ::Post::SearchError.new("You cannot search for more than #{CurrentUser.tag_query_limit} tags at a time") if tags[:exclude].size > CurrentUser.tag_query_limit
raise ::Post::SearchError.new("You cannot search for only excluded tags") unless has_constraints?
tag_query_sql << "!(" + escape_string_for_tsquery(tags[:exclude]).join(" | ") + ")"

View File

@@ -210,7 +210,7 @@ class Tag < ActiveRecord::Base
output[:include] << tag[1..-1]
elsif tag =~ /\*/
matches = Tag.name_matches(tag).all(:select => "name", :limit => Danbooru.config.tag_query_limit, :order => "post_count DESC").map(&:name)
matches = Tag.name_matches(tag).all(:select => "name", :limit => CurrentUser.tag_query_limit, :order => "post_count DESC").map(&:name)
matches = ["~no_matches~"] if matches.empty?
output[:include] += matches

View File

@@ -8,6 +8,7 @@ class User < ActiveRecord::Base
BLOCKED = 10
MEMBER = 20
PRIVILEGED = 30
PLATINUM = 31
BUILDER = 32
CONTRIBUTOR = 33
JANITOR = 35
@@ -262,7 +263,10 @@ class User < ActiveRecord::Base
"Builder"
when Levels::PRIVILEGED
"Privileged"
"Gold"
when Levels::PLATINUM
"Platinum"
when Levels::CONTRIBUTOR
"Contributor"
@@ -294,6 +298,10 @@ class User < ActiveRecord::Base
level >= Levels::PRIVILEGED
end
def is_platinum?
level >= Levels::PLATINUM
end
def is_contributor?
level >= Levels::CONTRIBUTOR
end
@@ -403,6 +411,26 @@ class User < ActiveRecord::Base
limit
end
def tag_query_limit
if is_privileged?
Danbooru.config.tag_query_limit
elsif is_platinum?
Danbooru.config.tag_query_limit * 2
else
2
end
end
def favorite_limit
if is_privileged?
5_000
elsif is_platinum?
nil
else
1_000
end
end
end
module ApiMethods

View File

@@ -36,7 +36,7 @@ module PostSetPresenters
end
def pattern_tags
Tag.name_matches(post_set.tag_string).all(:select => "name", :limit => Danbooru.config.tag_query_limit, :order => "post_count DESC").map(&:name)
Tag.name_matches(post_set.tag_string).all(:select => "name", :limit => CurrentUser.tag_query_limit, :order => "post_count DESC").map(&:name)
end
def related_tags_for_group

View File

@@ -1,2 +1,6 @@
$("a#add-to-favorites").hide();
$("a#remove-from-favorites").show();
<% if @error_msg %>
Danbooru.error("<%= @error_msg %>");
<% else %>
$("a#add-to-favorites").hide();
$("a#remove-from-favorites").show();
<% end %>

View File

@@ -8,6 +8,7 @@ FactoryGirl.define do
base_upload_limit 10
level 20
last_logged_in_at {Time.now}
favorite_count 0
factory(:banned_user) do
is_banned true