add basic support for safe mode
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user