diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1807ea12b..23fd35ab7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 0b7ad0e40..767c92a18 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -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 = {}) diff --git a/app/models/artist.rb b/app/models/artist.rb index a10390064..783c5f17c 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -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? diff --git a/app/models/artist_commentary.rb b/app/models/artist_commentary.rb index 295675b5d..ed404a8aa 100644 --- a/app/models/artist_commentary.rb +++ b/app/models/artist_commentary.rb @@ -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 diff --git a/app/models/artist_commentary_version.rb b/app/models/artist_commentary_version.rb index cda5d81a6..0f90027d9 100644 --- a/app/models/artist_commentary_version.rb +++ b/app/models/artist_commentary_version.rb @@ -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 diff --git a/app/models/artist_version.rb b/app/models/artist_version.rb index e632f1807..03bde80fa 100644 --- a/app/models/artist_version.rb +++ b/app/models/artist_version.rb @@ -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 diff --git a/app/models/ban.rb b/app/models/ban.rb index e88f7e17e..e11b8414e 100644 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -46,7 +46,7 @@ class Ban < ApplicationRecord module ApiMethods def html_data_attributes - [:user_id, :banner_id, :expired?] + super + [:expired?] end end diff --git a/app/models/bulk_update_request.rb b/app/models/bulk_update_request.rb index a1825b118..04f1216ba 100644 --- a/app/models/bulk_update_request.rb +++ b/app/models/bulk_update_request.rb @@ -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 diff --git a/app/models/comment_vote.rb b/app/models/comment_vote.rb index b60079f20..701eead15 100644 --- a/app/models/comment_vote.rb +++ b/app/models/comment_vote.rb @@ -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 diff --git a/app/models/dmail.rb b/app/models/dmail.rb index 4b7ec5664..212426c4b 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -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?) diff --git a/app/models/favorite_group.rb b/app/models/favorite_group.rb index 2660743a0..a13003253 100644 --- a/app/models/favorite_group.rb +++ b/app/models/favorite_group.rb @@ -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+$/ diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index f376564be..074d465b2 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -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 diff --git a/app/models/forum_post_vote.rb b/app/models/forum_post_vote.rb index 6c1778604..9637aca8f 100644 --- a/app/models/forum_post_vote.rb +++ b/app/models/forum_post_vote.rb @@ -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 diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 85b5f8185..a96ff4a5e 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -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) diff --git a/app/models/ip_address.rb b/app/models/ip_address.rb index 816400ab5..add206bbc 100644 --- a/app/models/ip_address.rb +++ b/app/models/ip_address.rb @@ -42,12 +42,4 @@ class IpAddress < ApplicationRecord def readonly? true end - - module ApiMethods - def html_data_attributes - [:user_id] - end - end - - include ApiMethods end diff --git a/app/models/ip_ban.rb b/app/models/ip_ban.rb index d6fea18b9..0da1a8838 100644 --- a/app/models/ip_ban.rb +++ b/app/models/ip_ban.rb @@ -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 diff --git a/app/models/mod_action.rb b/app/models/mod_action.rb index 66b413c0c..fc4534b49 100644 --- a/app/models/mod_action.rb +++ b/app/models/mod_action.rb @@ -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 diff --git a/app/models/news_update.rb b/app/models/news_update.rb index 60a198bba..5e0fecb09 100644 --- a/app/models/news_update.rb +++ b/app/models/news_update.rb @@ -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 diff --git a/app/models/note.rb b/app/models/note.rb index 6a556160a..8402a850f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -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 diff --git a/app/models/note_version.rb b/app/models/note_version.rb index 83aef1535..231cb73f4 100644 --- a/app/models/note_version.rb +++ b/app/models/note_version.rb @@ -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 diff --git a/app/models/pool.rb b/app/models/pool.rb index dc9efd450..61a557521 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -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+$/ diff --git a/app/models/pool_archive.rb b/app/models/pool_archive.rb index 3ab57dc57..288f12588 100644 --- a/app/models/pool_archive.rb +++ b/app/models/pool_archive.rb @@ -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) diff --git a/app/models/post_appeal.rb b/app/models/post_appeal.rb index 7aaa6131c..b4fea7607 100644 --- a/app/models/post_appeal.rb +++ b/app/models/post_appeal.rb @@ -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? diff --git a/app/models/post_approval.rb b/app/models/post_approval.rb index 83d1e4c9a..1cb2d4654 100644 --- a/app/models/post_approval.rb +++ b/app/models/post_approval.rb @@ -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 diff --git a/app/models/post_archive.rb b/app/models/post_archive.rb index fd332b2b7..afc47e30e 100644 --- a/app/models/post_archive.rb +++ b/app/models/post_archive.rb @@ -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 diff --git a/app/models/post_disapproval.rb b/app/models/post_disapproval.rb index a6aa8acc5..427259896 100644 --- a/app/models/post_disapproval.rb +++ b/app/models/post_disapproval.rb @@ -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 diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb index aeacf4b39..197591a6c 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -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 diff --git a/app/models/post_replacement.rb b/app/models/post_replacement.rb index cedfaaaa5..49323bccc 100644 --- a/app/models/post_replacement.rb +++ b/app/models/post_replacement.rb @@ -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}" } diff --git a/app/models/post_vote.rb b/app/models/post_vote.rb index 83f54f9ff..cf91e3824 100644 --- a/app/models/post_vote.rb +++ b/app/models/post_vote.rb @@ -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 diff --git a/app/models/saved_search.rb b/app/models/saved_search.rb index 60e915da7..87b093000 100644 --- a/app/models/saved_search.rb +++ b/app/models/saved_search.rb @@ -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 diff --git a/app/models/tag.rb b/app/models/tag.rb index c8481c892..e2d4098e1 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -69,10 +69,6 @@ class Tag < ApplicationRecord "ambiguous" => false }.to_json end - - def html_data_attributes - [:category] - end end class CategoryMapping diff --git a/app/models/tag_relationship.rb b/app/models/tag_relationship.rb index bd5afe801..8a38995f3 100644 --- a/app/models/tag_relationship.rb +++ b/app/models/tag_relationship.rb @@ -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 diff --git a/app/models/upload.rb b/app/models/upload.rb index f3fb8152e..aa210271b 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -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? diff --git a/app/models/user.rb b/app/models/user.rb index 350b58f7f..db59924e5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/user_feedback.rb b/app/models/user_feedback.rb index c1fde6ff3..f52a9045a 100644 --- a/app/models/user_feedback.rb +++ b/app/models/user_feedback.rb @@ -42,7 +42,7 @@ class UserFeedback < ApplicationRecord module ApiMethods def html_data_attributes - [:user_id, :creator_id, :category] + super + [:category] end end diff --git a/app/models/user_name_change_request.rb b/app/models/user_name_change_request.rb index b35691b4e..655d30d14 100644 --- a/app/models/user_name_change_request.rb +++ b/app/models/user_name_change_request.rb @@ -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 diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index 15b401548..df2e16ef6 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -117,7 +117,7 @@ class WikiPage < ApplicationRecord module ApiMethods def html_data_attributes - [:category_name] + super + [:category_name] end end diff --git a/app/models/wiki_page_version.rb b/app/models/wiki_page_version.rb index 29c6f5a11..b0da8ffb3 100644 --- a/app/models/wiki_page_version.rb +++ b/app/models/wiki_page_version.rb @@ -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("_", " ")