models: include all int/bool columns as html data attributes by default.

This commit is contained in:
evazion
2020-01-05 22:48:55 -06:00
parent 77935808e2
commit 895199ecfc
38 changed files with 10 additions and 240 deletions

View File

@@ -207,7 +207,7 @@ module ApplicationHelper
if current_item.present? if current_item.present?
model_name = current_item.model_name.singular.dasherize 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) current_item_data_attributes = data_attributes_for(current_item, model_name, model_attributes)
end end

View File

@@ -281,7 +281,11 @@ class ApplicationRecord < ActiveRecord::Base
end end
def html_data_attributes 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 end
def serializable_hash(options = {}) def serializable_hash(options = {})

View File

@@ -517,12 +517,6 @@ class Artist < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:creator_id]
end
end
include UrlMethods include UrlMethods
include NameMethods include NameMethods
include VersionMethods include VersionMethods
@@ -531,7 +525,6 @@ class Artist < ApplicationRecord
include TagMethods include TagMethods
include BanMethods include BanMethods
extend SearchMethods extend SearchMethods
include ApiMethods
def status def status
if is_banned? && is_active? if is_banned? && is_active?

View File

@@ -139,13 +139,6 @@ class ArtistCommentary < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:post_id]
end
end
extend SearchMethods extend SearchMethods
include VersionMethods include VersionMethods
include ApiMethods
end end

View File

@@ -7,12 +7,4 @@ class ArtistCommentaryVersion < ApplicationRecord
q = q.search_attributes(params, :post, :updater, :original_title, :original_description, :translated_title, :translated_description) q = q.search_attributes(params, :post, :updater, :original_title, :original_description, :translated_title, :translated_description)
q.apply_default_order(params) q.apply_default_order(params)
end end
module ApiMethods
def html_data_attributes
[:post_id, :updater_id]
end
end
include ApiMethods
end end

View File

@@ -23,14 +23,7 @@ class ArtistVersion < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:artist_id, :updater_id]
end
end
extend SearchMethods extend SearchMethods
include ApiMethods
def previous def previous
ArtistVersion.where("artist_id = ? and created_at < ?", artist_id, created_at).order("created_at desc").first ArtistVersion.where("artist_id = ? and created_at < ?", artist_id, created_at).order("created_at desc").first

View File

@@ -46,7 +46,7 @@ class Ban < ApplicationRecord
module ApiMethods module ApiMethods
def html_data_attributes def html_data_attributes
[:user_id, :banner_id, :expired?] super + [:expired?]
end end
end end

View File

@@ -135,16 +135,9 @@ class BulkUpdateRequest < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:user_id, :approver_id, :forum_topic_id, :forum_post_id]
end
end
extend SearchMethods extend SearchMethods
include ApprovalMethods include ApprovalMethods
include ValidationMethods include ValidationMethods
include ApiMethods
concerning :EmbeddedText do concerning :EmbeddedText do
class_methods do class_methods do

View File

@@ -51,12 +51,4 @@ class CommentVote < ApplicationRecord
def initialize_user def initialize_user
self.user_id = CurrentUser.user.id self.user_id = CurrentUser.user.id
end end
module ApiMethods
def html_data_attributes
[:comment_id, :user_id]
end
end
include ApiMethods
end end

View File

@@ -146,16 +146,9 @@ class Dmail < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:owner_id, :from_id, :to_id, :is_read?]
end
end
include AddressMethods include AddressMethods
include FactoryMethods include FactoryMethods
extend SearchMethods extend SearchMethods
include ApiMethods
def validate_sender_is_not_banned def validate_sender_is_not_banned
if from.try(:is_banned?) if from.try(:is_banned?)

View File

@@ -70,14 +70,7 @@ class FavoriteGroup < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:creator_id]
end
end
extend SearchMethods extend SearchMethods
include ApiMethods
def self.name_to_id(name) def self.name_to_id(name)
if name =~ /^\d+$/ if name =~ /^\d+$/

View File

@@ -75,7 +75,7 @@ class ForumPost < ApplicationRecord
module ApiMethods module ApiMethods
def html_data_attributes def html_data_attributes
[:topic_id, :creator_id, :updater_id, :is_deleted?, [:topic, :is_deleted?]] super + [[:topic, :is_deleted?]]
end end
end end

View File

@@ -53,12 +53,4 @@ class ForumPostVote < ApplicationRecord
raise raise
end end
end end
module ApiMethods
def html_data_attributes
[:forum_post_id, :creator_id]
end
end
include ApiMethods
end end

View File

@@ -131,17 +131,10 @@ class ForumTopic < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:creator_id, :updater_id, :category_id]
end
end
extend SearchMethods extend SearchMethods
include CategoryMethods include CategoryMethods
include VisitMethods include VisitMethods
include SubscriptionMethods include SubscriptionMethods
include ApiMethods
def editable_by?(user) def editable_by?(user)
(creator_id == user.id || user.is_moderator?) && visible?(user) (creator_id == user.id || user.is_moderator?) && visible?(user)

View File

@@ -42,12 +42,4 @@ class IpAddress < ApplicationRecord
def readonly? def readonly?
true true
end end
module ApiMethods
def html_data_attributes
[:user_id]
end
end
include ApiMethods
end end

View File

@@ -42,12 +42,4 @@ class IpBan < ApplicationRecord
str += "/" + ip_addr.prefix.to_s if has_subnet? str += "/" + ip_addr.prefix.to_s if has_subnet?
str str
end end
module ApiMethods
def html_data_attributes
[:creator_id]
end
end
include ApiMethods
end end

View File

@@ -83,12 +83,4 @@ class ModAction < ApplicationRecord
def initialize_creator def initialize_creator
self.creator_id = CurrentUser.id self.creator_id = CurrentUser.id
end end
module ApiMethods
def html_data_attributes
[:category_id, :creator_id]
end
end
include ApiMethods
end end

View File

@@ -2,12 +2,4 @@ class NewsUpdate < ApplicationRecord
belongs_to_creator belongs_to_creator
belongs_to_updater belongs_to_updater
scope :recent, -> {where("created_at >= ?", 2.weeks.ago).order("created_at desc").limit(5)} 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 end

View File

@@ -157,12 +157,4 @@ class Note < ApplicationRecord
end end
end end
end end
module ApiMethods
def html_data_attributes
[:post_id, :creator_id, :version]
end
end
include ApiMethods
end end

View File

@@ -15,12 +15,4 @@ class NoteVersion < ApplicationRecord
def previous def previous
NoteVersion.where("note_id = ? and updated_at < ?", note_id, updated_at).order("updated_at desc").first NoteVersion.where("note_id = ? and updated_at < ?", note_id, updated_at).order("updated_at desc").first
end end
module ApiMethods
def html_data_attributes
[:note_id, :post_id, :updater_id, :version]
end
end
include ApiMethods
end end

View File

@@ -95,14 +95,7 @@ class Pool < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:creator_id]
end
end
extend SearchMethods extend SearchMethods
include ApiMethods
def self.name_to_id(name) def self.name_to_id(name)
if name =~ /^\d+$/ if name =~ /^\d+$/

View File

@@ -33,14 +33,7 @@ class PoolArchive < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:pool_id, :updater_id, :version]
end
end
extend SearchMethods extend SearchMethods
include ApiMethods
def self.sqs_service def self.sqs_service
SqsService.new(Danbooru.config.aws_sqs_archives_url) SqsService.new(Danbooru.config.aws_sqs_archives_url)

View File

@@ -36,14 +36,7 @@ class PostAppeal < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:post_id, :creator_id]
end
end
extend SearchMethods extend SearchMethods
include ApiMethods
def resolved? def resolved?
post.present? && !post.is_deleted? && !post.is_flagged? post.present? && !post.is_deleted? && !post.is_flagged?

View File

@@ -37,12 +37,4 @@ class PostApproval < ApplicationRecord
q = q.search_attributes(params, :user, :post) q = q.search_attributes(params, :user, :post)
q.apply_default_order(params) q.apply_default_order(params)
end end
module ApiMethods
def html_data_attributes
[:post_id, :user_id]
end
end
include ApiMethods
end end

View File

@@ -75,15 +75,8 @@ class PostArchive < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:post_id, :updater_id, :version]
end
end
extend SearchMethods extend SearchMethods
include ArchiveServiceMethods include ArchiveServiceMethods
include ApiMethods
def tag_array def tag_array
tags.split tags.split

View File

@@ -67,12 +67,4 @@ class PostDisapproval < ApplicationRecord
end end
end end
end end
module ApiMethods
def html_data_attributes
[:post_id, :user_id]
end
end
include ApiMethods
end end

View File

@@ -100,14 +100,6 @@ class PostFlag < ApplicationRecord
attributes -= [:creator_id] unless CurrentUser.can_view_flagger_on_post?(self) attributes -= [:creator_id] unless CurrentUser.can_view_flagger_on_post?(self)
attributes attributes
end end
def html_data_attributes
attributes = [:post_id]
if CurrentUser.can_view_flagger_on_post?(self)
attributes += [:creator_id]
end
attributes
end
end end
extend SearchMethods extend SearchMethods

View File

@@ -28,14 +28,6 @@ class PostReplacement < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:post_id, :creator_id]
end
end
include ApiMethods
def suggested_tags_for_removal def suggested_tags_for_removal
tags = post.tag_array.select { |tag| Danbooru.config.remove_tag_after_replacement?(tag) } tags = post.tag_array.select { |tag| Danbooru.config.remove_tag_after_replacement?(tag) }
tags = tags.map { |tag| "-#{tag}" } tags = tags.map { |tag| "-#{tag}" }

View File

@@ -68,12 +68,4 @@ class PostVote < ApplicationRecord
1 1
end end
end end
module ApiMethods
def html_data_attributes
[:post_id, :user_id]
end
end
include ApiMethods
end end

View File

@@ -171,12 +171,4 @@ class SavedSearch < ApplicationRecord
def disable_labels=(value) def disable_labels=(value)
CurrentUser.update(disable_categorized_saved_searches: true) if value.to_s.truthy? CurrentUser.update(disable_categorized_saved_searches: true) if value.to_s.truthy?
end end
module ApiMethods
def html_data_attributes
[:user_id]
end
end
include ApiMethods
end end

View File

@@ -69,10 +69,6 @@ class Tag < ApplicationRecord
"ambiguous" => false "ambiguous" => false
}.to_json }.to_json
end end
def html_data_attributes
[:category]
end
end end
class CategoryMapping class CategoryMapping

View File

@@ -197,12 +197,6 @@ class TagRelationship < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:creator_id, :approver_id, :forum_topic_id, :forum_post_id]
end
end
concerning :EmbeddedText do concerning :EmbeddedText do
class_methods do class_methods do
def embedded_pattern def embedded_pattern
@@ -240,5 +234,4 @@ class TagRelationship < ApplicationRecord
extend SearchMethods extend SearchMethods
include MessageMethods include MessageMethods
include ApiMethods
end end

View File

@@ -228,19 +228,12 @@ class Upload < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:post_id, :uploader_id]
end
end
include FileMethods include FileMethods
include StatusMethods include StatusMethods
include UploaderMethods include UploaderMethods
include VideoMethods include VideoMethods
extend SearchMethods extend SearchMethods
include SourceMethods include SourceMethods
include ApiMethods
def uploader_is_not_limited def uploader_is_not_limited
if !uploader.can_upload? if !uploader.can_upload?

View File

@@ -614,10 +614,6 @@ class User < ApplicationRecord
}.to_json }.to_json
end end
def html_data_attributes
[:inviter_id]
end
def api_token def api_token
api_key.try(:key) api_key.try(:key)
end end

View File

@@ -42,7 +42,7 @@ class UserFeedback < ApplicationRecord
module ApiMethods module ApiMethods
def html_data_attributes def html_data_attributes
[:user_id, :creator_id, :category] super + [:category]
end end
end end

View File

@@ -18,14 +18,6 @@ class UserNameChangeRequest < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:user_id]
end
end
include ApiMethods
def update_name! def update_name!
user.update!(name: desired_name) user.update!(name: desired_name)
end end

View File

@@ -117,7 +117,7 @@ class WikiPage < ApplicationRecord
module ApiMethods module ApiMethods
def html_data_attributes def html_data_attributes
[:category_name] super + [:category_name]
end end
end end

View File

@@ -17,14 +17,7 @@ class WikiPageVersion < ApplicationRecord
end end
end end
module ApiMethods
def html_data_attributes
[:wiki_page_id, :updater_id]
end
end
extend SearchMethods extend SearchMethods
include ApiMethods
def pretty_title def pretty_title
title.tr("_", " ") title.tr("_", " ")