api: refactor api attribute declarations.
Replace the `method_attributes` and `hidden_attributes` methods with
`api_attributes`. `api_attributes` can be used as a class macro:
# include only the given attributes.
api_attributes :id, :created_at, :creator_name, ...
# include all default attributes plus the `creator_name` method.
api_attributes including: [:creator_name]
or as an instance method:
def api_attributes
[:id, :created_at, :creator_name, ...]
end
By default, all attributes are included except for IP addresses and
tsvector columns.
This commit is contained in:
@@ -155,26 +155,6 @@ class ForumTopic < ApplicationRecord
|
||||
(response_count / Danbooru.config.posts_per_page.to_f).ceil
|
||||
end
|
||||
|
||||
def as_json(options = {})
|
||||
if CurrentUser.user.level < min_level
|
||||
options[:only] = [:id]
|
||||
end
|
||||
|
||||
super(options)
|
||||
end
|
||||
|
||||
def to_xml(options = {})
|
||||
if CurrentUser.user.level < min_level
|
||||
options[:only] = [:id]
|
||||
end
|
||||
|
||||
super(options)
|
||||
end
|
||||
|
||||
def hidden_attributes
|
||||
super + [:text_index, :min_level]
|
||||
end
|
||||
|
||||
def merge(topic)
|
||||
ForumPost.where(:id => self.posts.map(&:id)).update_all(:topic_id => topic.id)
|
||||
topic.update(response_count: topic.response_count + self.posts.length, updater_id: CurrentUser.id)
|
||||
|
||||
Reference in New Issue
Block a user