improved api censoring
This commit is contained in:
30
config/initializers/active_record_api_extensions.rb
Normal file
30
config/initializers/active_record_api_extensions.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
module Danbooru
|
||||
module Extensions
|
||||
module ActiveRecordApi
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def serializable_hash(options = {})
|
||||
options ||= {}
|
||||
options[:except] ||= []
|
||||
options[:except] += hidden_attributes
|
||||
super(options)
|
||||
end
|
||||
|
||||
def to_xml(options = {}, &block)
|
||||
# to_xml ignores serializable_hash
|
||||
options ||= {}
|
||||
options[:except] ||= []
|
||||
options[:except] += hidden_attributes
|
||||
super(options, &block)
|
||||
end
|
||||
|
||||
def hidden_attributes
|
||||
[:uploader_ip_addr, :updater_ip_addr, :creator_ip_addr, :ip_addr]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class ActiveRecord::Base
|
||||
include Danbooru::Extensions::ActiveRecordApi
|
||||
end
|
||||
@@ -44,11 +44,6 @@ module Danbooru
|
||||
|
||||
"case #{table_name}.id " + conditions.join(" ") + " end"
|
||||
end
|
||||
|
||||
def serializable_hash(options = {})
|
||||
options = {:except => [:uploader_ip_addr, :updater_ip_addr, :creator_ip_addr, :ip_addr]}.merge(options ||= {})
|
||||
super(options)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user