Add API data to show/index views
This commit is contained in:
@@ -280,6 +280,10 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
self.class.api_attributes
|
||||
end
|
||||
|
||||
def html_data_attributes
|
||||
[]
|
||||
end
|
||||
|
||||
def serializable_hash(options = {})
|
||||
options ||= {}
|
||||
options[:only] ||= []
|
||||
|
||||
@@ -517,6 +517,12 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:creator_id, [:wiki_page, :id]]
|
||||
end
|
||||
end
|
||||
|
||||
include UrlMethods
|
||||
include NameMethods
|
||||
include VersionMethods
|
||||
@@ -525,6 +531,7 @@ class Artist < ApplicationRecord
|
||||
include TagMethods
|
||||
include BanMethods
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def status
|
||||
if is_banned? && is_active?
|
||||
|
||||
@@ -139,6 +139,13 @@ class ArtistCommentary < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include VersionMethods
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -7,4 +7,12 @@ class ArtistCommentaryVersion < ApplicationRecord
|
||||
q = q.search_attributes(params, :post, :updater, :original_title, :original_description, :translated_title, :translated_description)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id, :updater_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -23,7 +23,14 @@ class ArtistVersion < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:artist_id, :updater_id]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def previous
|
||||
ArtistVersion.where("artist_id = ? and created_at < ?", artist_id, created_at).order("created_at desc").first
|
||||
|
||||
@@ -44,6 +44,14 @@ class Ban < ApplicationRecord
|
||||
q
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:user_id, :banner_id, :expired?]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
|
||||
def self.prune!
|
||||
expired.includes(:user).find_each do |ban|
|
||||
ban.user.unban! if ban.user.ban_expired?
|
||||
|
||||
@@ -135,9 +135,16 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:user_id, :approver_id, :forum_topic_id, :forum_post_id]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApprovalMethods
|
||||
include ValidationMethods
|
||||
include ApiMethods
|
||||
|
||||
concerning :EmbeddedText do
|
||||
class_methods do
|
||||
|
||||
@@ -51,4 +51,12 @@ class CommentVote < ApplicationRecord
|
||||
def initialize_user
|
||||
self.user_id = CurrentUser.user.id
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:comment_id, :user_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -146,9 +146,16 @@ class Dmail < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:owner_id, :from_id, :to_id]
|
||||
end
|
||||
end
|
||||
|
||||
include AddressMethods
|
||||
include FactoryMethods
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def validate_sender_is_not_banned
|
||||
if from.try(:is_banned?)
|
||||
|
||||
@@ -70,7 +70,14 @@ class FavoriteGroup < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:creator_id]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def self.name_to_id(name)
|
||||
if name =~ /^\d+$/
|
||||
|
||||
@@ -73,7 +73,14 @@ class ForumPost < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:topic_id, :creator_id, :updater_id, :is_deleted?, [:topic, :is_deleted?]]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def self.new_reply(params)
|
||||
if params[:topic_id]
|
||||
|
||||
@@ -53,4 +53,12 @@ class ForumPostVote < ApplicationRecord
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:forum_post_id, :creator_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -131,10 +131,17 @@ class ForumTopic < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:creator_id, :updater_id, :category_id]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include CategoryMethods
|
||||
include VisitMethods
|
||||
include SubscriptionMethods
|
||||
include ApiMethods
|
||||
|
||||
def editable_by?(user)
|
||||
(creator_id == user.id || user.is_moderator?) && visible?(user)
|
||||
|
||||
@@ -42,4 +42,12 @@ class IpAddress < ApplicationRecord
|
||||
def readonly?
|
||||
true
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:user_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -42,4 +42,12 @@ class IpBan < ApplicationRecord
|
||||
str += "/" + ip_addr.prefix.to_s if has_subnet?
|
||||
str
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:creator_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -83,4 +83,12 @@ class ModAction < ApplicationRecord
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:category_id, :creator_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -2,4 +2,12 @@ class NewsUpdate < ApplicationRecord
|
||||
belongs_to_creator
|
||||
belongs_to_updater
|
||||
scope :recent, -> {where("created_at >= ?", 2.weeks.ago).order("created_at desc").limit(5)}
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:creator_id, :updater_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -157,4 +157,12 @@ class Note < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id, :creator_id, :version]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -15,4 +15,12 @@ class NoteVersion < ApplicationRecord
|
||||
def previous
|
||||
NoteVersion.where("note_id = ? and updated_at < ?", note_id, updated_at).order("updated_at desc").first
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:note_id, :post_id, :updater_id, :version]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -95,7 +95,14 @@ class Pool < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:creator_id]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def self.name_to_id(name)
|
||||
if name =~ /^\d+$/
|
||||
|
||||
@@ -33,7 +33,14 @@ class PoolArchive < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:pool_id, :updater_id, :version]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def self.sqs_service
|
||||
SqsService.new(Danbooru.config.aws_sqs_archives_url)
|
||||
|
||||
@@ -1481,6 +1481,10 @@ class Post < ApplicationRecord
|
||||
hash
|
||||
end
|
||||
|
||||
def html_data_attributes
|
||||
[:uploader_id, :approver_id]
|
||||
end
|
||||
|
||||
def status
|
||||
if is_pending?
|
||||
"pending"
|
||||
|
||||
@@ -36,7 +36,14 @@ class PostAppeal < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id, :creator_id]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def resolved?
|
||||
post.present? && !post.is_deleted? && !post.is_flagged?
|
||||
|
||||
@@ -37,4 +37,12 @@ class PostApproval < ApplicationRecord
|
||||
q = q.search_attributes(params, :user, :post)
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id, :user_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -75,8 +75,15 @@ class PostArchive < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id, :updater_id, :version]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ArchiveServiceMethods
|
||||
include ApiMethods
|
||||
|
||||
def tag_array
|
||||
tags.split
|
||||
|
||||
@@ -67,4 +67,12 @@ class PostDisapproval < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id, :user_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -94,13 +94,24 @@ class PostFlag < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def api_attributes
|
||||
attributes = super + [:category]
|
||||
attributes -= [:creator_id] unless CurrentUser.can_view_flagger_on_post?(self)
|
||||
attributes
|
||||
module ApiMethods
|
||||
def api_attributes
|
||||
attributes = super + [:category]
|
||||
attributes -= [:creator_id] unless CurrentUser.can_view_flagger_on_post?(self)
|
||||
attributes
|
||||
end
|
||||
|
||||
def html_data_attributes
|
||||
attributes = [:post_id]
|
||||
if CurrentUser.can_view_flagger_on_post?(self)
|
||||
attributes += [:creator_id]
|
||||
end
|
||||
attributes
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def category
|
||||
case reason
|
||||
|
||||
@@ -28,6 +28,14 @@ class PostReplacement < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id, :creator_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
|
||||
def suggested_tags_for_removal
|
||||
tags = post.tag_array.select { |tag| Danbooru.config.remove_tag_after_replacement?(tag) }
|
||||
tags = tags.map { |tag| "-#{tag}" }
|
||||
|
||||
@@ -68,4 +68,12 @@ class PostVote < ApplicationRecord
|
||||
1
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id, :user_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -171,4 +171,12 @@ class SavedSearch < ApplicationRecord
|
||||
def disable_labels=(value)
|
||||
CurrentUser.update(disable_categorized_saved_searches: true) if value.to_s.truthy?
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:user_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -69,6 +69,10 @@ class Tag < ApplicationRecord
|
||||
"ambiguous" => false
|
||||
}.to_json
|
||||
end
|
||||
|
||||
def html_data_attributes
|
||||
[:category]
|
||||
end
|
||||
end
|
||||
|
||||
class CategoryMapping
|
||||
|
||||
@@ -197,6 +197,12 @@ class TagRelationship < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:creator_id, :approver_id, :forum_topic_id, :forum_post_id]
|
||||
end
|
||||
end
|
||||
|
||||
concerning :EmbeddedText do
|
||||
class_methods do
|
||||
def embedded_pattern
|
||||
@@ -234,4 +240,5 @@ class TagRelationship < ApplicationRecord
|
||||
|
||||
extend SearchMethods
|
||||
include MessageMethods
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -228,12 +228,19 @@ class Upload < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id, :uploader_id]
|
||||
end
|
||||
end
|
||||
|
||||
include FileMethods
|
||||
include StatusMethods
|
||||
include UploaderMethods
|
||||
include VideoMethods
|
||||
extend SearchMethods
|
||||
include SourceMethods
|
||||
include ApiMethods
|
||||
|
||||
def uploader_is_not_limited
|
||||
if !uploader.can_upload?
|
||||
|
||||
@@ -614,6 +614,10 @@ class User < ApplicationRecord
|
||||
}.to_json
|
||||
end
|
||||
|
||||
def html_data_attributes
|
||||
[:inviter_id]
|
||||
end
|
||||
|
||||
def api_token
|
||||
api_key.try(:key)
|
||||
end
|
||||
|
||||
@@ -40,7 +40,14 @@ class UserFeedback < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:user_id, :creator_id]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def user_name=(name)
|
||||
self.user = User.find_by_name(name)
|
||||
|
||||
@@ -18,6 +18,14 @@ class UserNameChangeRequest < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:user_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
|
||||
def update_name!
|
||||
user.update!(name: desired_name)
|
||||
end
|
||||
|
||||
@@ -115,7 +115,14 @@ class WikiPage < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:category_name, [:artist, :id]]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def validate_not_locked
|
||||
if is_locked? && !CurrentUser.is_builder?
|
||||
|
||||
@@ -17,7 +17,14 @@ class WikiPageVersion < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:wiki_page_id, :updater_id]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def pretty_title
|
||||
title.tr("_", " ")
|
||||
|
||||
Reference in New Issue
Block a user