change privileged accounts to gold accounts, add platinum accounts, add favorite and tag query limiting based on level
This commit is contained in:
@@ -10,7 +10,11 @@ class FavoritesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
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
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ module Admin::UsersHelper
|
|||||||
def user_level_select(object, field)
|
def user_level_select(object, field)
|
||||||
options = [
|
options = [
|
||||||
["Member", User::Levels::MEMBER],
|
["Member", User::Levels::MEMBER],
|
||||||
["Privileged", User::Levels::PRIVILEGED],
|
["Gold", User::Levels::PRIVILEGED],
|
||||||
|
["Platinum", User::Levels::PLATINUM],
|
||||||
|
["Builder", User::Levels::BUILDER],
|
||||||
["Contributor", User::Levels::CONTRIBUTOR],
|
["Contributor", User::Levels::CONTRIBUTOR],
|
||||||
["Janitor", User::Levels::JANITOR],
|
["Janitor", User::Levels::JANITOR],
|
||||||
["Moderator", User::Levels::MODERATOR],
|
["Moderator", User::Levels::MODERATOR],
|
||||||
|
|||||||
@@ -133,7 +133,19 @@ class AnonymousUser
|
|||||||
:anonymous
|
:anonymous
|
||||||
end
|
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
|
define_method("is_#{name}?") do
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,24 +49,24 @@ class PostQueryBuilder
|
|||||||
"''" + escaped_token + "''"
|
"''" + escaped_token + "''"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_tag_string_search_relation(tags, relation)
|
def add_tag_string_search_relation(tags, relation)
|
||||||
tag_query_sql = []
|
tag_query_sql = []
|
||||||
|
|
||||||
if tags[:include].any?
|
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(" | ") + ")"
|
tag_query_sql << "(" + escape_string_for_tsquery(tags[:include]).join(" | ") + ")"
|
||||||
has_constraints!
|
has_constraints!
|
||||||
end
|
end
|
||||||
|
|
||||||
if tags[:related].any?
|
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(" & ") + ")"
|
tag_query_sql << "(" + escape_string_for_tsquery(tags[:related]).join(" & ") + ")"
|
||||||
has_constraints!
|
has_constraints!
|
||||||
end
|
end
|
||||||
|
|
||||||
if tags[:exclude].any?
|
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?
|
raise ::Post::SearchError.new("You cannot search for only excluded tags") unless has_constraints?
|
||||||
|
|
||||||
tag_query_sql << "!(" + escape_string_for_tsquery(tags[:exclude]).join(" | ") + ")"
|
tag_query_sql << "!(" + escape_string_for_tsquery(tags[:exclude]).join(" | ") + ")"
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ class Tag < ActiveRecord::Base
|
|||||||
output[:include] << tag[1..-1]
|
output[:include] << tag[1..-1]
|
||||||
|
|
||||||
elsif tag =~ /\*/
|
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?
|
matches = ["~no_matches~"] if matches.empty?
|
||||||
output[:include] += matches
|
output[:include] += matches
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class User < ActiveRecord::Base
|
|||||||
BLOCKED = 10
|
BLOCKED = 10
|
||||||
MEMBER = 20
|
MEMBER = 20
|
||||||
PRIVILEGED = 30
|
PRIVILEGED = 30
|
||||||
|
PLATINUM = 31
|
||||||
BUILDER = 32
|
BUILDER = 32
|
||||||
CONTRIBUTOR = 33
|
CONTRIBUTOR = 33
|
||||||
JANITOR = 35
|
JANITOR = 35
|
||||||
@@ -262,7 +263,10 @@ class User < ActiveRecord::Base
|
|||||||
"Builder"
|
"Builder"
|
||||||
|
|
||||||
when Levels::PRIVILEGED
|
when Levels::PRIVILEGED
|
||||||
"Privileged"
|
"Gold"
|
||||||
|
|
||||||
|
when Levels::PLATINUM
|
||||||
|
"Platinum"
|
||||||
|
|
||||||
when Levels::CONTRIBUTOR
|
when Levels::CONTRIBUTOR
|
||||||
"Contributor"
|
"Contributor"
|
||||||
@@ -294,6 +298,10 @@ class User < ActiveRecord::Base
|
|||||||
level >= Levels::PRIVILEGED
|
level >= Levels::PRIVILEGED
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_platinum?
|
||||||
|
level >= Levels::PLATINUM
|
||||||
|
end
|
||||||
|
|
||||||
def is_contributor?
|
def is_contributor?
|
||||||
level >= Levels::CONTRIBUTOR
|
level >= Levels::CONTRIBUTOR
|
||||||
end
|
end
|
||||||
@@ -403,6 +411,26 @@ class User < ActiveRecord::Base
|
|||||||
|
|
||||||
limit
|
limit
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
module ApiMethods
|
module ApiMethods
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ module PostSetPresenters
|
|||||||
end
|
end
|
||||||
|
|
||||||
def pattern_tags
|
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
|
end
|
||||||
|
|
||||||
def related_tags_for_group
|
def related_tags_for_group
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
$("a#add-to-favorites").hide();
|
<% if @error_msg %>
|
||||||
$("a#remove-from-favorites").show();
|
Danbooru.error("<%= @error_msg %>");
|
||||||
|
<% else %>
|
||||||
|
$("a#add-to-favorites").hide();
|
||||||
|
$("a#remove-from-favorites").show();
|
||||||
|
<% end %>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ FactoryGirl.define do
|
|||||||
base_upload_limit 10
|
base_upload_limit 10
|
||||||
level 20
|
level 20
|
||||||
last_logged_in_at {Time.now}
|
last_logged_in_at {Time.now}
|
||||||
|
favorite_count 0
|
||||||
|
|
||||||
factory(:banned_user) do
|
factory(:banned_user) do
|
||||||
is_banned true
|
is_banned true
|
||||||
|
|||||||
Reference in New Issue
Block a user