diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index c54d68754..4c707cf73 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -43,7 +43,7 @@ class ArtistsController < ApplicationController end def show - @artist = Artist.find(params[:id]) + @current_item = @artist = Artist.find(params[:id]) @post_set = PostSets::Artist.new(@artist) respond_with(@artist) end diff --git a/app/controllers/bans_controller.rb b/app/controllers/bans_controller.rb index 3a8b1645e..94db739e3 100644 --- a/app/controllers/bans_controller.rb +++ b/app/controllers/bans_controller.rb @@ -19,7 +19,7 @@ class BansController < ApplicationController end def show - @ban = Ban.find(params[:id]) + @current_item = @ban = Ban.find(params[:id]) respond_with(@ban) end diff --git a/app/controllers/bulk_update_requests_controller.rb b/app/controllers/bulk_update_requests_controller.rb index 0fcb3ff8d..0b982152a 100644 --- a/app/controllers/bulk_update_requests_controller.rb +++ b/app/controllers/bulk_update_requests_controller.rb @@ -15,7 +15,7 @@ class BulkUpdateRequestsController < ApplicationController end def show - @bulk_update_request = BulkUpdateRequest.find(params[:id]) + @current_item = @bulk_update_request = BulkUpdateRequest.find(params[:id]) respond_with(@bulk_update_request) end diff --git a/app/controllers/dmails_controller.rb b/app/controllers/dmails_controller.rb index d76e19985..ee72408de 100644 --- a/app/controllers/dmails_controller.rb +++ b/app/controllers/dmails_controller.rb @@ -24,7 +24,7 @@ class DmailsController < ApplicationController end def show - @dmail = Dmail.find(params[:id]) + @current_item = @dmail = Dmail.find(params[:id]) check_privilege(@dmail) @dmail.mark_as_read! respond_with(@dmail) diff --git a/app/controllers/favorite_groups_controller.rb b/app/controllers/favorite_groups_controller.rb index c7c5129d1..b7598a1be 100644 --- a/app/controllers/favorite_groups_controller.rb +++ b/app/controllers/favorite_groups_controller.rb @@ -8,7 +8,7 @@ class FavoriteGroupsController < ApplicationController end def show - @favorite_group = FavoriteGroup.find(params[:id]) + @current_item = @favorite_group = FavoriteGroup.find(params[:id]) check_read_privilege(@favorite_group) @post_set = PostSets::FavoriteGroup.new(@favorite_group, params[:page]) respond_with(@favorite_group) diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index dc5e2c2cf..248734d2b 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -32,6 +32,7 @@ class ForumTopicsController < ApplicationController end def show + @current_item = @forum_topic if request.format == Mime::Type.lookup("text/html") @forum_topic.mark_as_read!(CurrentUser.user) end diff --git a/app/controllers/pools_controller.rb b/app/controllers/pools_controller.rb index 9fdbf748f..ad2ec943c 100644 --- a/app/controllers/pools_controller.rb +++ b/app/controllers/pools_controller.rb @@ -37,7 +37,7 @@ class PoolsController < ApplicationController def show limit = params[:limit].presence || CurrentUser.user.per_page - @pool = Pool.find(params[:id]) + @current_item = @pool = Pool.find(params[:id]) @posts = @pool.posts.paginate(params[:page], limit: limit, count: @pool.post_count) respond_with(@pool) end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 2b0be440b..d1267d1db 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -19,7 +19,7 @@ class PostsController < ApplicationController end def show - @post = Post.find(params[:id]) + @current_item = @post = Post.find(params[:id]) @comments = @post.comments @comments = @comments.includes(:creator) diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index acc86b969..7f6ae076c 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -3,7 +3,7 @@ class TagAliasesController < ApplicationController respond_to :html, :xml, :json, :js def show - @tag_alias = TagAlias.find(params[:id]) + @current_item = @tag_alias = TagAlias.find(params[:id]) respond_with(@tag_alias) end diff --git a/app/controllers/tag_implications_controller.rb b/app/controllers/tag_implications_controller.rb index 0b3f1f077..fab6d579d 100644 --- a/app/controllers/tag_implications_controller.rb +++ b/app/controllers/tag_implications_controller.rb @@ -3,7 +3,7 @@ class TagImplicationsController < ApplicationController respond_to :html, :xml, :json, :js def show - @tag_implication = TagImplication.find(params[:id]) + @current_item = @tag_implication = TagImplication.find(params[:id]) respond_with(@tag_implication) end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 4a3cd5665..aac893786 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -3,7 +3,7 @@ class TagsController < ApplicationController respond_to :html, :xml, :json def edit - @tag = Tag.find(params[:id]) + @current_item = @tag = Tag.find(params[:id]) check_privilege(@tag) respond_with(@tag) end @@ -26,7 +26,7 @@ class TagsController < ApplicationController end def show - @tag = Tag.find(params[:id]) + @current_item = @tag = Tag.find(params[:id]) respond_with(@tag) end diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 072e7341c..f3e772c24 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -29,7 +29,7 @@ class UploadsController < ApplicationController end def show - @upload = Upload.find(params[:id]) + @current_item = @upload = Upload.find(params[:id]) respond_with(@upload) do |format| format.html do if @upload.is_completed? && @upload.post_id diff --git a/app/controllers/user_feedbacks_controller.rb b/app/controllers/user_feedbacks_controller.rb index dfd9b94c9..3f77f00e1 100644 --- a/app/controllers/user_feedbacks_controller.rb +++ b/app/controllers/user_feedbacks_controller.rb @@ -14,7 +14,7 @@ class UserFeedbacksController < ApplicationController end def show - @user_feedback = UserFeedback.visible.find(params[:id]) + @current_item = @user_feedback = UserFeedback.visible.find(params[:id]) respond_with(@user_feedback) end diff --git a/app/controllers/user_name_change_requests_controller.rb b/app/controllers/user_name_change_requests_controller.rb index 40df71d1b..e4c58c699 100644 --- a/app/controllers/user_name_change_requests_controller.rb +++ b/app/controllers/user_name_change_requests_controller.rb @@ -14,7 +14,7 @@ class UserNameChangeRequestsController < ApplicationController end def show - @change_request = UserNameChangeRequest.find(params[:id]) + @current_item = @change_request = UserNameChangeRequest.find(params[:id]) check_privileges!(@change_request) respond_with(@change_request) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 66d524cfd..eea6fff76 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -43,7 +43,7 @@ class UsersController < ApplicationController end def show - @user = User.find(params[:id]) + @current_item = @user = User.find(params[:id]) respond_with(@user, methods: @user.full_attributes) end diff --git a/app/controllers/wiki_page_versions_controller.rb b/app/controllers/wiki_page_versions_controller.rb index 112960d2d..8a7fa7273 100644 --- a/app/controllers/wiki_page_versions_controller.rb +++ b/app/controllers/wiki_page_versions_controller.rb @@ -8,7 +8,7 @@ class WikiPageVersionsController < ApplicationController end def show - @wiki_page_version = WikiPageVersion.find(params[:id]) + @current_item = @wiki_page_version = WikiPageVersion.find(params[:id]) respond_with(@wiki_page_version) end diff --git a/app/controllers/wiki_pages_controller.rb b/app/controllers/wiki_pages_controller.rb index 10a50f0d3..34bc094e2 100644 --- a/app/controllers/wiki_pages_controller.rb +++ b/app/controllers/wiki_pages_controller.rb @@ -30,7 +30,7 @@ class WikiPagesController < ApplicationController def show @wiki_page, found_by = WikiPage.find_by_id_or_title(params[:id]) - + @current_item = @wiki_page if request.format.html? && @wiki_page.blank? && found_by == :title @wiki_page = WikiPage.new(title: params[:id]) respond_with @wiki_page, status: 404 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e9bf75873..ded81b7ba 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -202,10 +202,13 @@ module ApplicationHelper render "table_builder/table", table: table end - def body_attributes(user = CurrentUser.user) - attributes = %i[id name level level_string theme] + User::BOOLEAN_ATTRIBUTES.map(&:to_sym) - attributes += User::Roles.map { |role| :"is_#{role}?" } - + def body_attributes(user = CurrentUser.user, current_item = nil) + user_attributes = %i[id name level level_string theme] + User::BOOLEAN_ATTRIBUTES.map(&:to_sym) + user_attributes += User::Roles.map { |role| :"is_#{role}?" } + mapped_user_attributes = data_attributes_for(user, "user", user_attributes) + model_attributes = (!current_item.nil? ? (!current_item.id.nil? ? [:id] : [] ) + current_item.html_data_attributes : []) + mapped_model_attributes = (!current_item.nil? ? data_attributes_for(current_item, "show", model_attributes) : {} ) + all_mapped_attributes = mapped_user_attributes.merge(mapped_model_attributes) controller_param = params[:controller].parameterize.dasherize action_param = params[:action].parameterize.dasherize @@ -216,17 +219,34 @@ module ApplicationHelper controller: controller_param, action: action_param, layout: controller.class.send(:_layout), - **data_attributes_for(user, "user", attributes) + **all_mapped_attributes } } end def data_attributes_for(record, prefix, attributes) attributes.map do |attr| - name = attr.to_s.dasherize.delete("?") - value = record.send(attr) - - [:"#{prefix}-#{name}", value] + if attr.kind_of?(Array) + name = attr.map {|sym| sym.to_s.dasherize.delete("?")}.join('-') + value = record + attr.each do |sym| + value = value.send(sym) + if value.nil? + break + end + end + else + name = attr.to_s.dasherize.delete("?") + value = record.send(attr) + end + if value.nil? + value = "null" + end + if prefix.length == 0 + [:"#{name}", value] + else + [:"#{prefix}-#{name}", value] + end end.to_h end diff --git a/app/logical/table_builder.rb b/app/logical/table_builder.rb index 5a2bde151..2f5017429 100644 --- a/app/logical/table_builder.rb +++ b/app/logical/table_builder.rb @@ -43,6 +43,13 @@ class TableBuilder else standard_attributes = {} end + + if item.html_data_attributes.length > 0 + class_attributes = ApplicationController.helpers.data_attributes_for(item, "data", item.html_data_attributes) + else + class_attributes = {} + end + if !row_attributes.nil? mapped_row_attributes = row_attributes.clone mapped_row_attributes.clone.each do |key, value| @@ -53,6 +60,7 @@ class TableBuilder else mapped_row_attributes = {} end - standard_attributes.merge(mapped_row_attributes) + + standard_attributes.merge(class_attributes).merge(mapped_row_attributes) end end diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 90378f8c5..0b7ad0e40 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -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] ||= [] diff --git a/app/models/artist.rb b/app/models/artist.rb index 783c5f17c..45fbf8312 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -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? diff --git a/app/models/artist_commentary.rb b/app/models/artist_commentary.rb index ed404a8aa..295675b5d 100644 --- a/app/models/artist_commentary.rb +++ b/app/models/artist_commentary.rb @@ -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 diff --git a/app/models/artist_commentary_version.rb b/app/models/artist_commentary_version.rb index 0f90027d9..cda5d81a6 100644 --- a/app/models/artist_commentary_version.rb +++ b/app/models/artist_commentary_version.rb @@ -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 diff --git a/app/models/artist_version.rb b/app/models/artist_version.rb index 03bde80fa..e632f1807 100644 --- a/app/models/artist_version.rb +++ b/app/models/artist_version.rb @@ -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 diff --git a/app/models/ban.rb b/app/models/ban.rb index 741a8815f..e88f7e17e 100644 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -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? diff --git a/app/models/bulk_update_request.rb b/app/models/bulk_update_request.rb index 04f1216ba..a1825b118 100644 --- a/app/models/bulk_update_request.rb +++ b/app/models/bulk_update_request.rb @@ -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 diff --git a/app/models/comment_vote.rb b/app/models/comment_vote.rb index 701eead15..b60079f20 100644 --- a/app/models/comment_vote.rb +++ b/app/models/comment_vote.rb @@ -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 diff --git a/app/models/dmail.rb b/app/models/dmail.rb index 212426c4b..fc60007eb 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -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?) diff --git a/app/models/favorite_group.rb b/app/models/favorite_group.rb index a13003253..2660743a0 100644 --- a/app/models/favorite_group.rb +++ b/app/models/favorite_group.rb @@ -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+$/ diff --git a/app/models/forum_post.rb b/app/models/forum_post.rb index 0053468eb..f376564be 100644 --- a/app/models/forum_post.rb +++ b/app/models/forum_post.rb @@ -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] diff --git a/app/models/forum_post_vote.rb b/app/models/forum_post_vote.rb index 9637aca8f..6c1778604 100644 --- a/app/models/forum_post_vote.rb +++ b/app/models/forum_post_vote.rb @@ -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 diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index a96ff4a5e..85b5f8185 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -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) diff --git a/app/models/ip_address.rb b/app/models/ip_address.rb index add206bbc..816400ab5 100644 --- a/app/models/ip_address.rb +++ b/app/models/ip_address.rb @@ -42,4 +42,12 @@ 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 0da1a8838..d6fea18b9 100644 --- a/app/models/ip_ban.rb +++ b/app/models/ip_ban.rb @@ -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 diff --git a/app/models/mod_action.rb b/app/models/mod_action.rb index fc4534b49..66b413c0c 100644 --- a/app/models/mod_action.rb +++ b/app/models/mod_action.rb @@ -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 diff --git a/app/models/news_update.rb b/app/models/news_update.rb index 5e0fecb09..60a198bba 100644 --- a/app/models/news_update.rb +++ b/app/models/news_update.rb @@ -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 diff --git a/app/models/note.rb b/app/models/note.rb index 8402a850f..6a556160a 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -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 diff --git a/app/models/note_version.rb b/app/models/note_version.rb index 231cb73f4..83aef1535 100644 --- a/app/models/note_version.rb +++ b/app/models/note_version.rb @@ -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 diff --git a/app/models/pool.rb b/app/models/pool.rb index 61a557521..dc9efd450 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -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+$/ diff --git a/app/models/pool_archive.rb b/app/models/pool_archive.rb index 288f12588..3ab57dc57 100644 --- a/app/models/pool_archive.rb +++ b/app/models/pool_archive.rb @@ -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) diff --git a/app/models/post.rb b/app/models/post.rb index ba1ece4c7..70f3e1038 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1481,6 +1481,10 @@ class Post < ApplicationRecord hash end + def html_data_attributes + [:uploader_id, :approver_id] + end + def status if is_pending? "pending" diff --git a/app/models/post_appeal.rb b/app/models/post_appeal.rb index b4fea7607..7aaa6131c 100644 --- a/app/models/post_appeal.rb +++ b/app/models/post_appeal.rb @@ -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? diff --git a/app/models/post_approval.rb b/app/models/post_approval.rb index 1cb2d4654..83d1e4c9a 100644 --- a/app/models/post_approval.rb +++ b/app/models/post_approval.rb @@ -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 diff --git a/app/models/post_archive.rb b/app/models/post_archive.rb index afc47e30e..fd332b2b7 100644 --- a/app/models/post_archive.rb +++ b/app/models/post_archive.rb @@ -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 diff --git a/app/models/post_disapproval.rb b/app/models/post_disapproval.rb index 427259896..a6aa8acc5 100644 --- a/app/models/post_disapproval.rb +++ b/app/models/post_disapproval.rb @@ -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 diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb index e99affea4..aeacf4b39 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -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 diff --git a/app/models/post_replacement.rb b/app/models/post_replacement.rb index 49323bccc..cedfaaaa5 100644 --- a/app/models/post_replacement.rb +++ b/app/models/post_replacement.rb @@ -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}" } diff --git a/app/models/post_vote.rb b/app/models/post_vote.rb index cf91e3824..83f54f9ff 100644 --- a/app/models/post_vote.rb +++ b/app/models/post_vote.rb @@ -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 diff --git a/app/models/saved_search.rb b/app/models/saved_search.rb index 87b093000..60e915da7 100644 --- a/app/models/saved_search.rb +++ b/app/models/saved_search.rb @@ -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 diff --git a/app/models/tag.rb b/app/models/tag.rb index e2d4098e1..c8481c892 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -69,6 +69,10 @@ 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 8a38995f3..bd5afe801 100644 --- a/app/models/tag_relationship.rb +++ b/app/models/tag_relationship.rb @@ -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 diff --git a/app/models/upload.rb b/app/models/upload.rb index aa210271b..f3fb8152e 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -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? diff --git a/app/models/user.rb b/app/models/user.rb index db59924e5..350b58f7f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/user_feedback.rb b/app/models/user_feedback.rb index f90a99fe7..2ca160c03 100644 --- a/app/models/user_feedback.rb +++ b/app/models/user_feedback.rb @@ -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) diff --git a/app/models/user_name_change_request.rb b/app/models/user_name_change_request.rb index 655d30d14..b35691b4e 100644 --- a/app/models/user_name_change_request.rb +++ b/app/models/user_name_change_request.rb @@ -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 diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index ef88dea28..31f55919a 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -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? diff --git a/app/models/wiki_page_version.rb b/app/models/wiki_page_version.rb index b0da8ffb3..29c6f5a11 100644 --- a/app/models/wiki_page_version.rb +++ b/app/models/wiki_page_version.rb @@ -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("_", " ") diff --git a/app/views/bans/index.html.erb b/app/views/bans/index.html.erb index 2a9d1692d..64e7609ee 100644 --- a/app/views/bans/index.html.erb +++ b/app/views/bans/index.html.erb @@ -4,7 +4,7 @@ <%= render "search" %> - <%= table_for @bans, {class: "striped autofit"}, {"data-expired": ["%s", "item.expired?"]} do |t| %> + <%= table_for @bans, {class: "striped autofit"} do |t| %> <% t.column "Banned User" do |ban| %> <%= link_to_user(ban.user) %> <%= link_to "ยป", bans_path(search: search_params.merge(user_name: ban.user.name)) %> diff --git a/app/views/forum_posts/index.html.erb b/app/views/forum_posts/index.html.erb index 87683811f..040f87155 100644 --- a/app/views/forum_posts/index.html.erb +++ b/app/views/forum_posts/index.html.erb @@ -1,7 +1,7 @@
- <%= table_for @forum_posts, {class: "striped", width: "100%"}, {"data-is-deleted": ["%s", "item.is_deleted?"], "data-topic-is-deleted": ["%s", "item.topic.is_deleted?"]} do |t| %> + <%= table_for @forum_posts, {class: "striped", width: "100%"} do |t| %> <% t.column "Topic", nil, {class: "forum-post-topic-title"} do |forum_post| %> <%= link_to forum_post.topic.title, forum_topic_path(forum_post.topic) %> <% end %> diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index 409dc93ba..741c8d50c 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -75,7 +75,7 @@ <%= yield :html_header %> <%= raw Danbooru.config.custom_html_header_content %> -<%= tag.body **body_attributes(CurrentUser.user) do %> +<%= tag.body **body_attributes(CurrentUser.user, (defined?(@current_item) ? @current_item : nil)) do %> <%= render "news_updates/listing" %>