models: include all int/bool columns as html data attributes by default.
This commit is contained in:
@@ -207,7 +207,7 @@ module ApplicationHelper
|
||||
|
||||
if current_item.present?
|
||||
model_name = current_item.model_name.singular.dasherize
|
||||
model_attributes = current_item.html_data_attributes + [:id]
|
||||
model_attributes = current_item.html_data_attributes
|
||||
current_item_data_attributes = data_attributes_for(current_item, model_name, model_attributes)
|
||||
end
|
||||
|
||||
|
||||
@@ -281,7 +281,11 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def html_data_attributes
|
||||
[]
|
||||
data_attributes = self.class.columns.select do |column|
|
||||
column.type.in?([:integer, :boolean]) && !column.array?
|
||||
end.map(&:name).map(&:to_sym)
|
||||
|
||||
api_attributes & data_attributes
|
||||
end
|
||||
|
||||
def serializable_hash(options = {})
|
||||
|
||||
@@ -517,12 +517,6 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:creator_id]
|
||||
end
|
||||
end
|
||||
|
||||
include UrlMethods
|
||||
include NameMethods
|
||||
include VersionMethods
|
||||
@@ -531,7 +525,6 @@ class Artist < ApplicationRecord
|
||||
include TagMethods
|
||||
include BanMethods
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def status
|
||||
if is_banned? && is_active?
|
||||
|
||||
@@ -139,13 +139,6 @@ class ArtistCommentary < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id]
|
||||
end
|
||||
end
|
||||
|
||||
extend SearchMethods
|
||||
include VersionMethods
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -7,12 +7,4 @@ 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,14 +23,7 @@ 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
|
||||
|
||||
@@ -46,7 +46,7 @@ class Ban < ApplicationRecord
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:user_id, :banner_id, :expired?]
|
||||
super + [:expired?]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -135,16 +135,9 @@ 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,12 +51,4 @@ 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,16 +146,9 @@ class Dmail < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:owner_id, :from_id, :to_id, :is_read?]
|
||||
end
|
||||
end
|
||||
|
||||
include AddressMethods
|
||||
include FactoryMethods
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def validate_sender_is_not_banned
|
||||
if from.try(:is_banned?)
|
||||
|
||||
@@ -70,14 +70,7 @@ 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+$/
|
||||
|
||||
@@ -75,7 +75,7 @@ class ForumPost < ApplicationRecord
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:topic_id, :creator_id, :updater_id, :is_deleted?, [:topic, :is_deleted?]]
|
||||
super + [[:topic, :is_deleted?]]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -53,12 +53,4 @@ class ForumPostVote < ApplicationRecord
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:forum_post_id, :creator_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -131,17 +131,10 @@ 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,12 +42,4 @@ class IpAddress < ApplicationRecord
|
||||
def readonly?
|
||||
true
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:user_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -42,12 +42,4 @@ 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,12 +83,4 @@ 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,12 +2,4 @@ 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,12 +157,4 @@ class Note < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id, :creator_id, :version]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -15,12 +15,4 @@ 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,14 +95,7 @@ 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,14 +33,7 @@ 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)
|
||||
|
||||
@@ -36,14 +36,7 @@ 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,12 +37,4 @@ 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,15 +75,8 @@ 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,12 +67,4 @@ class PostDisapproval < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id, :user_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -100,14 +100,6 @@ class PostFlag < ApplicationRecord
|
||||
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
|
||||
|
||||
@@ -28,14 +28,6 @@ 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,12 +68,4 @@ class PostVote < ApplicationRecord
|
||||
1
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:post_id, :user_id]
|
||||
end
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -171,12 +171,4 @@ 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,10 +69,6 @@ class Tag < ApplicationRecord
|
||||
"ambiguous" => false
|
||||
}.to_json
|
||||
end
|
||||
|
||||
def html_data_attributes
|
||||
[:category]
|
||||
end
|
||||
end
|
||||
|
||||
class CategoryMapping
|
||||
|
||||
@@ -197,12 +197,6 @@ 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
|
||||
@@ -240,5 +234,4 @@ class TagRelationship < ApplicationRecord
|
||||
|
||||
extend SearchMethods
|
||||
include MessageMethods
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -228,19 +228,12 @@ 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,10 +614,6 @@ class User < ApplicationRecord
|
||||
}.to_json
|
||||
end
|
||||
|
||||
def html_data_attributes
|
||||
[:inviter_id]
|
||||
end
|
||||
|
||||
def api_token
|
||||
api_key.try(:key)
|
||||
end
|
||||
|
||||
@@ -42,7 +42,7 @@ class UserFeedback < ApplicationRecord
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:user_id, :creator_id, :category]
|
||||
super + [:category]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -18,14 +18,6 @@ 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
|
||||
|
||||
@@ -117,7 +117,7 @@ class WikiPage < ApplicationRecord
|
||||
|
||||
module ApiMethods
|
||||
def html_data_attributes
|
||||
[:category_name]
|
||||
super + [:category_name]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -17,14 +17,7 @@ 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