add basic support for safe mode

This commit is contained in:
r888888888
2013-07-17 13:59:44 -07:00
parent 01057a9cd5
commit 49d2df80f6
5 changed files with 43 additions and 6 deletions

View File

@@ -42,6 +42,18 @@ class CurrentUser
user.name
end
def self.safe_mode?
Thread.current[:safe_mode]
end
def self.set_safe_mode(req)
if req.host =~ /safe/
Thread.current[:safe_mode] = true
else
Thread.current[:safe_mode] = false
end
end
def self.method_missing(method, *params, &block)
if user.respond_to?(method)
user.__send__(method, *params, &block)

View File

@@ -112,6 +112,11 @@ class PostQueryBuilder
raise ::Post::SearchError.new("You cannot search for more than #{Danbooru.config.tag_query_limit} tags at a time")
end
if CurrentUser.safe_mode?
relation = relation.where(:rating => "s")
relation = relation.where("created_at <= ?", 3.months.ago)
end
relation = add_range_relation(q[:post_id], "posts.id", relation)
relation = add_range_relation(q[:mpixels], "posts.image_width * posts.image_height / 1000000.0", relation)
relation = add_range_relation(q[:width], "posts.image_width", relation)