Add API data to show/index views
This commit is contained in:
@@ -43,7 +43,7 @@ class ArtistsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@artist = Artist.find(params[:id])
|
@current_item = @artist = Artist.find(params[:id])
|
||||||
@post_set = PostSets::Artist.new(@artist)
|
@post_set = PostSets::Artist.new(@artist)
|
||||||
respond_with(@artist)
|
respond_with(@artist)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class BansController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@ban = Ban.find(params[:id])
|
@current_item = @ban = Ban.find(params[:id])
|
||||||
respond_with(@ban)
|
respond_with(@ban)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class BulkUpdateRequestsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@bulk_update_request = BulkUpdateRequest.find(params[:id])
|
@current_item = @bulk_update_request = BulkUpdateRequest.find(params[:id])
|
||||||
respond_with(@bulk_update_request)
|
respond_with(@bulk_update_request)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class DmailsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@dmail = Dmail.find(params[:id])
|
@current_item = @dmail = Dmail.find(params[:id])
|
||||||
check_privilege(@dmail)
|
check_privilege(@dmail)
|
||||||
@dmail.mark_as_read!
|
@dmail.mark_as_read!
|
||||||
respond_with(@dmail)
|
respond_with(@dmail)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class FavoriteGroupsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@favorite_group = FavoriteGroup.find(params[:id])
|
@current_item = @favorite_group = FavoriteGroup.find(params[:id])
|
||||||
check_read_privilege(@favorite_group)
|
check_read_privilege(@favorite_group)
|
||||||
@post_set = PostSets::FavoriteGroup.new(@favorite_group, params[:page])
|
@post_set = PostSets::FavoriteGroup.new(@favorite_group, params[:page])
|
||||||
respond_with(@favorite_group)
|
respond_with(@favorite_group)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ class ForumTopicsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@current_item = @forum_topic
|
||||||
if request.format == Mime::Type.lookup("text/html")
|
if request.format == Mime::Type.lookup("text/html")
|
||||||
@forum_topic.mark_as_read!(CurrentUser.user)
|
@forum_topic.mark_as_read!(CurrentUser.user)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class PoolsController < ApplicationController
|
|||||||
def show
|
def show
|
||||||
limit = params[:limit].presence || CurrentUser.user.per_page
|
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)
|
@posts = @pool.posts.paginate(params[:page], limit: limit, count: @pool.post_count)
|
||||||
respond_with(@pool)
|
respond_with(@pool)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class PostsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@post = Post.find(params[:id])
|
@current_item = @post = Post.find(params[:id])
|
||||||
|
|
||||||
@comments = @post.comments
|
@comments = @post.comments
|
||||||
@comments = @comments.includes(:creator)
|
@comments = @comments.includes(:creator)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class TagAliasesController < ApplicationController
|
|||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@tag_alias = TagAlias.find(params[:id])
|
@current_item = @tag_alias = TagAlias.find(params[:id])
|
||||||
respond_with(@tag_alias)
|
respond_with(@tag_alias)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class TagImplicationsController < ApplicationController
|
|||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@tag_implication = TagImplication.find(params[:id])
|
@current_item = @tag_implication = TagImplication.find(params[:id])
|
||||||
respond_with(@tag_implication)
|
respond_with(@tag_implication)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ class TagsController < ApplicationController
|
|||||||
respond_to :html, :xml, :json
|
respond_to :html, :xml, :json
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@tag = Tag.find(params[:id])
|
@current_item = @tag = Tag.find(params[:id])
|
||||||
check_privilege(@tag)
|
check_privilege(@tag)
|
||||||
respond_with(@tag)
|
respond_with(@tag)
|
||||||
end
|
end
|
||||||
@@ -26,7 +26,7 @@ class TagsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@tag = Tag.find(params[:id])
|
@current_item = @tag = Tag.find(params[:id])
|
||||||
respond_with(@tag)
|
respond_with(@tag)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class UploadsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@upload = Upload.find(params[:id])
|
@current_item = @upload = Upload.find(params[:id])
|
||||||
respond_with(@upload) do |format|
|
respond_with(@upload) do |format|
|
||||||
format.html do
|
format.html do
|
||||||
if @upload.is_completed? && @upload.post_id
|
if @upload.is_completed? && @upload.post_id
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class UserFeedbacksController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@user_feedback = UserFeedback.visible.find(params[:id])
|
@current_item = @user_feedback = UserFeedback.visible.find(params[:id])
|
||||||
respond_with(@user_feedback)
|
respond_with(@user_feedback)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class UserNameChangeRequestsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@change_request = UserNameChangeRequest.find(params[:id])
|
@current_item = @change_request = UserNameChangeRequest.find(params[:id])
|
||||||
check_privileges!(@change_request)
|
check_privileges!(@change_request)
|
||||||
respond_with(@change_request)
|
respond_with(@change_request)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class UsersController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@user = User.find(params[:id])
|
@current_item = @user = User.find(params[:id])
|
||||||
respond_with(@user, methods: @user.full_attributes)
|
respond_with(@user, methods: @user.full_attributes)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ class WikiPageVersionsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@wiki_page_version = WikiPageVersion.find(params[:id])
|
@current_item = @wiki_page_version = WikiPageVersion.find(params[:id])
|
||||||
respond_with(@wiki_page_version)
|
respond_with(@wiki_page_version)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class WikiPagesController < ApplicationController
|
|||||||
|
|
||||||
def show
|
def show
|
||||||
@wiki_page, found_by = WikiPage.find_by_id_or_title(params[:id])
|
@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
|
if request.format.html? && @wiki_page.blank? && found_by == :title
|
||||||
@wiki_page = WikiPage.new(title: params[:id])
|
@wiki_page = WikiPage.new(title: params[:id])
|
||||||
respond_with @wiki_page, status: 404
|
respond_with @wiki_page, status: 404
|
||||||
|
|||||||
@@ -202,10 +202,13 @@ module ApplicationHelper
|
|||||||
render "table_builder/table", table: table
|
render "table_builder/table", table: table
|
||||||
end
|
end
|
||||||
|
|
||||||
def body_attributes(user = CurrentUser.user)
|
def body_attributes(user = CurrentUser.user, current_item = nil)
|
||||||
attributes = %i[id name level level_string theme] + User::BOOLEAN_ATTRIBUTES.map(&:to_sym)
|
user_attributes = %i[id name level level_string theme] + User::BOOLEAN_ATTRIBUTES.map(&:to_sym)
|
||||||
attributes += User::Roles.map { |role| :"is_#{role}?" }
|
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
|
controller_param = params[:controller].parameterize.dasherize
|
||||||
action_param = params[:action].parameterize.dasherize
|
action_param = params[:action].parameterize.dasherize
|
||||||
|
|
||||||
@@ -216,17 +219,34 @@ module ApplicationHelper
|
|||||||
controller: controller_param,
|
controller: controller_param,
|
||||||
action: action_param,
|
action: action_param,
|
||||||
layout: controller.class.send(:_layout),
|
layout: controller.class.send(:_layout),
|
||||||
**data_attributes_for(user, "user", attributes)
|
**all_mapped_attributes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def data_attributes_for(record, prefix, attributes)
|
def data_attributes_for(record, prefix, attributes)
|
||||||
attributes.map do |attr|
|
attributes.map do |attr|
|
||||||
name = attr.to_s.dasherize.delete("?")
|
if attr.kind_of?(Array)
|
||||||
value = record.send(attr)
|
name = attr.map {|sym| sym.to_s.dasherize.delete("?")}.join('-')
|
||||||
|
value = record
|
||||||
[:"#{prefix}-#{name}", value]
|
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.to_h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,13 @@ class TableBuilder
|
|||||||
else
|
else
|
||||||
standard_attributes = {}
|
standard_attributes = {}
|
||||||
end
|
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?
|
if !row_attributes.nil?
|
||||||
mapped_row_attributes = row_attributes.clone
|
mapped_row_attributes = row_attributes.clone
|
||||||
mapped_row_attributes.clone.each do |key, value|
|
mapped_row_attributes.clone.each do |key, value|
|
||||||
@@ -53,6 +60,7 @@ class TableBuilder
|
|||||||
else
|
else
|
||||||
mapped_row_attributes = {}
|
mapped_row_attributes = {}
|
||||||
end
|
end
|
||||||
standard_attributes.merge(mapped_row_attributes)
|
|
||||||
|
standard_attributes.merge(class_attributes).merge(mapped_row_attributes)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -280,6 +280,10 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
self.class.api_attributes
|
self.class.api_attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def html_data_attributes
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
def serializable_hash(options = {})
|
def serializable_hash(options = {})
|
||||||
options ||= {}
|
options ||= {}
|
||||||
options[:only] ||= []
|
options[:only] ||= []
|
||||||
|
|||||||
@@ -517,6 +517,12 @@ class Artist < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module ApiMethods
|
||||||
|
def html_data_attributes
|
||||||
|
[:creator_id, [:wiki_page, :id]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
include UrlMethods
|
include UrlMethods
|
||||||
include NameMethods
|
include NameMethods
|
||||||
include VersionMethods
|
include VersionMethods
|
||||||
@@ -525,6 +531,7 @@ 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?
|
||||||
|
|||||||
@@ -139,6 +139,13 @@ 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
|
||||||
|
|||||||
@@ -7,4 +7,12 @@ 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
|
||||||
|
|||||||
@@ -23,7 +23,14 @@ 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
|
||||||
|
|||||||
@@ -44,6 +44,14 @@ class Ban < ApplicationRecord
|
|||||||
q
|
q
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module ApiMethods
|
||||||
|
def html_data_attributes
|
||||||
|
[:user_id, :banner_id, :expired?]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
include ApiMethods
|
||||||
|
|
||||||
def self.prune!
|
def self.prune!
|
||||||
expired.includes(:user).find_each do |ban|
|
expired.includes(:user).find_each do |ban|
|
||||||
ban.user.unban! if ban.user.ban_expired?
|
ban.user.unban! if ban.user.ban_expired?
|
||||||
|
|||||||
@@ -135,9 +135,16 @@ 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
|
||||||
|
|||||||
@@ -51,4 +51,12 @@ 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
|
||||||
|
|||||||
@@ -146,9 +146,16 @@ class Dmail < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module ApiMethods
|
||||||
|
def html_data_attributes
|
||||||
|
[:owner_id, :from_id, :to_id]
|
||||||
|
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?)
|
||||||
|
|||||||
@@ -70,7 +70,14 @@ 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+$/
|
||||||
|
|||||||
@@ -73,7 +73,14 @@ class ForumPost < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module ApiMethods
|
||||||
|
def html_data_attributes
|
||||||
|
[:topic_id, :creator_id, :updater_id, :is_deleted?, [:topic, :is_deleted?]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
|
include ApiMethods
|
||||||
|
|
||||||
def self.new_reply(params)
|
def self.new_reply(params)
|
||||||
if params[:topic_id]
|
if params[:topic_id]
|
||||||
|
|||||||
@@ -53,4 +53,12 @@ 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
|
||||||
|
|||||||
@@ -131,10 +131,17 @@ 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)
|
||||||
|
|||||||
@@ -42,4 +42,12 @@ 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
|
||||||
|
|||||||
@@ -42,4 +42,12 @@ 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
|
||||||
|
|||||||
@@ -83,4 +83,12 @@ 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
|
||||||
|
|||||||
@@ -2,4 +2,12 @@ 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
|
||||||
|
|||||||
@@ -157,4 +157,12 @@ 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
|
||||||
|
|||||||
@@ -15,4 +15,12 @@ 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
|
||||||
|
|||||||
@@ -95,7 +95,14 @@ 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+$/
|
||||||
|
|||||||
@@ -33,7 +33,14 @@ 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)
|
||||||
|
|||||||
@@ -1481,6 +1481,10 @@ class Post < ApplicationRecord
|
|||||||
hash
|
hash
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def html_data_attributes
|
||||||
|
[:uploader_id, :approver_id]
|
||||||
|
end
|
||||||
|
|
||||||
def status
|
def status
|
||||||
if is_pending?
|
if is_pending?
|
||||||
"pending"
|
"pending"
|
||||||
|
|||||||
@@ -36,7 +36,14 @@ 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?
|
||||||
|
|||||||
@@ -37,4 +37,12 @@ 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
|
||||||
|
|||||||
@@ -75,8 +75,15 @@ 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
|
||||||
|
|||||||
@@ -67,4 +67,12 @@ 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
|
||||||
|
|||||||
@@ -94,13 +94,24 @@ class PostFlag < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def api_attributes
|
module ApiMethods
|
||||||
attributes = super + [:category]
|
def api_attributes
|
||||||
attributes -= [:creator_id] unless CurrentUser.can_view_flagger_on_post?(self)
|
attributes = super + [:category]
|
||||||
attributes
|
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
|
end
|
||||||
|
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
|
include ApiMethods
|
||||||
|
|
||||||
def category
|
def category
|
||||||
case reason
|
case reason
|
||||||
|
|||||||
@@ -28,6 +28,14 @@ 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}" }
|
||||||
|
|||||||
@@ -68,4 +68,12 @@ 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
|
||||||
|
|||||||
@@ -171,4 +171,12 @@ 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
|
||||||
|
|||||||
@@ -69,6 +69,10 @@ 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
|
||||||
|
|||||||
@@ -197,6 +197,12 @@ 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
|
||||||
@@ -234,4 +240,5 @@ class TagRelationship < ApplicationRecord
|
|||||||
|
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
include MessageMethods
|
include MessageMethods
|
||||||
|
include ApiMethods
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -228,12 +228,19 @@ 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?
|
||||||
|
|||||||
@@ -614,6 +614,10 @@ 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
|
||||||
|
|||||||
@@ -40,7 +40,14 @@ class UserFeedback < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module ApiMethods
|
||||||
|
def html_data_attributes
|
||||||
|
[:user_id, :creator_id]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
|
include ApiMethods
|
||||||
|
|
||||||
def user_name=(name)
|
def user_name=(name)
|
||||||
self.user = User.find_by_name(name)
|
self.user = User.find_by_name(name)
|
||||||
|
|||||||
@@ -18,6 +18,14 @@ 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
|
||||||
|
|||||||
@@ -115,7 +115,14 @@ class WikiPage < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module ApiMethods
|
||||||
|
def html_data_attributes
|
||||||
|
[:category_name, [:artist, :id]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
|
include ApiMethods
|
||||||
|
|
||||||
def validate_not_locked
|
def validate_not_locked
|
||||||
if is_locked? && !CurrentUser.is_builder?
|
if is_locked? && !CurrentUser.is_builder?
|
||||||
|
|||||||
@@ -17,7 +17,14 @@ 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("_", " ")
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<%= render "search" %>
|
<%= 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| %>
|
<% t.column "Banned User" do |ban| %>
|
||||||
<%= link_to_user(ban.user) %>
|
<%= link_to_user(ban.user) %>
|
||||||
<%= link_to "»", bans_path(search: search_params.merge(user_name: ban.user.name)) %>
|
<%= link_to "»", bans_path(search: search_params.merge(user_name: ban.user.name)) %>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div id="c-forum-posts">
|
<div id="c-forum-posts">
|
||||||
<div id="a-index">
|
<div id="a-index">
|
||||||
|
|
||||||
<%= 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| %>
|
<% t.column "Topic", nil, {class: "forum-post-topic-title"} do |forum_post| %>
|
||||||
<%= link_to forum_post.topic.title, forum_topic_path(forum_post.topic) %>
|
<%= link_to forum_post.topic.title, forum_topic_path(forum_post.topic) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -75,7 +75,7 @@
|
|||||||
<%= yield :html_header %>
|
<%= yield :html_header %>
|
||||||
<%= raw Danbooru.config.custom_html_header_content %>
|
<%= raw Danbooru.config.custom_html_header_content %>
|
||||||
</head>
|
</head>
|
||||||
<%= tag.body **body_attributes(CurrentUser.user) do %>
|
<%= tag.body **body_attributes(CurrentUser.user, (defined?(@current_item) ? @current_item : nil)) do %>
|
||||||
<%= render "news_updates/listing" %>
|
<%= render "news_updates/listing" %>
|
||||||
|
|
||||||
<header id="top">
|
<header id="top">
|
||||||
|
|||||||
Reference in New Issue
Block a user