fixes #2096
This commit is contained in:
@@ -1101,7 +1101,19 @@ class Post < ActiveRecord::Base
|
|||||||
|
|
||||||
module ApiMethods
|
module ApiMethods
|
||||||
def hidden_attributes
|
def hidden_attributes
|
||||||
super + [:tag_index]
|
list = [:tag_index]
|
||||||
|
if !Danbooru.config.can_user_see_post?(CurrentUser.user, self)
|
||||||
|
list += [:md5, :file_ext]
|
||||||
|
end
|
||||||
|
super + list
|
||||||
|
end
|
||||||
|
|
||||||
|
def method_attributes
|
||||||
|
list = [:uploader_name, :has_large, :tag_string_artist, :tag_string_character, :tag_string_copyright, :tag_string_general]
|
||||||
|
if Danbooru.config.can_user_see_post?(CurrentUser.user, self)
|
||||||
|
list += [:file_url, :large_file_url, :preview_file_url]
|
||||||
|
end
|
||||||
|
list
|
||||||
end
|
end
|
||||||
|
|
||||||
def serializable_hash(options = {})
|
def serializable_hash(options = {})
|
||||||
@@ -1110,7 +1122,7 @@ class Post < ActiveRecord::Base
|
|||||||
options[:except] += hidden_attributes
|
options[:except] += hidden_attributes
|
||||||
unless options[:builder]
|
unless options[:builder]
|
||||||
options[:methods] ||= []
|
options[:methods] ||= []
|
||||||
options[:methods] += [:uploader_name, :has_large, :tag_string_artist, :tag_string_character, :tag_string_copyright, :tag_string_general, :file_url, :large_file_url, :preview_file_url]
|
options[:methods] += method_attributes
|
||||||
end
|
end
|
||||||
hash = super(options)
|
hash = super(options)
|
||||||
hash
|
hash
|
||||||
@@ -1119,32 +1131,37 @@ class Post < ActiveRecord::Base
|
|||||||
def to_xml(options = {}, &block)
|
def to_xml(options = {}, &block)
|
||||||
options ||= {}
|
options ||= {}
|
||||||
options[:methods] ||= []
|
options[:methods] ||= []
|
||||||
options[:methods] += [:uploader_name, :has_large, :tag_string_artist, :tag_string_character, :tag_string_copyright, :tag_string_general, :file_url, :large_file_url, :preview_file_url]
|
options[:methods] += method_attributes
|
||||||
super(options, &block)
|
super(options, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_legacy_json
|
def to_legacy_json
|
||||||
return {
|
hash = {
|
||||||
"has_comments" => last_commented_at.present?,
|
"has_comments" => last_commented_at.present?,
|
||||||
"parent_id" => parent_id,
|
"parent_id" => parent_id,
|
||||||
"status" => status,
|
"status" => status,
|
||||||
"has_children" => has_children?,
|
"has_children" => has_children?,
|
||||||
"created_at" => created_at.to_formatted_s(:db),
|
"created_at" => created_at.to_formatted_s(:db),
|
||||||
"md5" => md5,
|
|
||||||
"has_notes" => has_notes?,
|
"has_notes" => has_notes?,
|
||||||
"rating" => rating,
|
"rating" => rating,
|
||||||
"author" => uploader_name,
|
"author" => uploader_name,
|
||||||
"creator_id" => uploader_id,
|
"creator_id" => uploader_id,
|
||||||
"width" => image_width,
|
"width" => image_width,
|
||||||
"source" => source,
|
"source" => source,
|
||||||
"preview_url" => preview_file_url,
|
|
||||||
"score" => score,
|
"score" => score,
|
||||||
"tags" => tag_string,
|
"tags" => tag_string,
|
||||||
"height" => image_height,
|
"height" => image_height,
|
||||||
"file_size" => file_size,
|
"file_size" => file_size,
|
||||||
"id" => id,
|
"id" => id,
|
||||||
"file_url" => file_url
|
}
|
||||||
}.to_json
|
|
||||||
|
if Danbooru.config.can_user_see_post?(CurrentUser.user, self)
|
||||||
|
hash["file_url"] = file_url
|
||||||
|
hash["preview_url"] = preview_file_url
|
||||||
|
hash["md5"] = md5
|
||||||
|
end
|
||||||
|
|
||||||
|
hash
|
||||||
end
|
end
|
||||||
|
|
||||||
def status
|
def status
|
||||||
|
|||||||
Reference in New Issue
Block a user