rubocop: fix various style issues.
This commit is contained in:
@@ -356,7 +356,7 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
def belongs_to_creator(options = {})
|
||||
class_eval do
|
||||
belongs_to :creator, options.merge(class_name: "User")
|
||||
before_validation(on: :create) do |rec|
|
||||
before_validation(on: :create) do |rec|
|
||||
if rec.creator_id.nil?
|
||||
rec.creator_id = CurrentUser.id
|
||||
rec.creator_ip_addr = CurrentUser.ip_addr if rec.respond_to?(:creator_ip_addr=)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Artist < ApplicationRecord
|
||||
extend Memoist
|
||||
class RevertError < Exception ; end
|
||||
class RevertError < Exception; end
|
||||
|
||||
attr_accessor :url_string_changed
|
||||
array_attribute :other_names
|
||||
@@ -140,7 +140,7 @@ class Artist < ApplicationRecord
|
||||
"youtube.com/c", # https://www.youtube.com/c/serafleurArt
|
||||
"youtube.com/channel", # https://www.youtube.com/channel/UCfrCa2Y6VulwHD3eNd3HBRA
|
||||
"youtube.com/user", # https://www.youtube.com/user/148nasuka
|
||||
"youtu.be", # http://youtu.be/gibeLKKRT-0
|
||||
"youtu.be" # http://youtu.be/gibeLKKRT-0
|
||||
]
|
||||
|
||||
SITE_BLACKLIST_REGEXP = Regexp.union(SITE_BLACKLIST.map do |domain|
|
||||
@@ -213,13 +213,13 @@ class Artist < ApplicationRecord
|
||||
|
||||
def domains
|
||||
Cache.get("artist-domains-#{id}", 1.day) do
|
||||
Post.raw_tag_match(name).pluck(:source).map do |x|
|
||||
begin
|
||||
map_domain(Addressable::URI.parse(x).domain)
|
||||
rescue Addressable::URI::InvalidURIError
|
||||
nil
|
||||
end
|
||||
end.compact.inject(Hash.new(0)) {|h, x| h[x] += 1; h}.sort {|a, b| b[1] <=> a[1]}
|
||||
domains = Post.raw_tag_match(name).pluck(:source).map do |x|
|
||||
map_domain(Addressable::URI.parse(x).domain)
|
||||
rescue Addressable::URI::InvalidURIError
|
||||
nil
|
||||
end
|
||||
|
||||
domains.compact.inject(Hash.new(0)) {|h, x| h[x] += 1; h}.sort {|a, b| b[1] <=> a[1]}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -248,7 +248,7 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
module VersionMethods
|
||||
def create_version(force=false)
|
||||
def create_version(force = false)
|
||||
if saved_change_to_name? || url_string_changed || saved_change_to_is_active? || saved_change_to_is_banned? || saved_change_to_other_names? || saved_change_to_group_name? || saved_change_to_notes? || force
|
||||
if merge_version?
|
||||
merge_version
|
||||
@@ -401,7 +401,7 @@ class Artist < ApplicationRecord
|
||||
Post.transaction do
|
||||
CurrentUser.without_safe_mode do
|
||||
ti = TagImplication.where(:antecedent_name => name, :consequent_name => "banned_artist").first
|
||||
ti.destroy if ti
|
||||
ti&.destroy
|
||||
|
||||
Post.tag_match(name).where("true /* Artist.unban */").each do |post|
|
||||
post.unban!
|
||||
@@ -410,7 +410,7 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
update_column(:is_banned, false)
|
||||
ModAction.log("unbanned artist ##{id}",:artist_unban)
|
||||
ModAction.log("unbanned artist ##{id}", :artist_unban)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -429,7 +429,7 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
update_column(:is_banned, true)
|
||||
ModAction.log("banned artist ##{id}",:artist_ban)
|
||||
ModAction.log("banned artist ##{id}", :artist_ban)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class ArtistCommentary < ApplicationRecord
|
||||
class RevertError < Exception ; end
|
||||
class RevertError < Exception; end
|
||||
|
||||
attr_accessor :remove_commentary_tag, :remove_commentary_request_tag, :remove_commentary_check_tag, :remove_partial_commentary_tag
|
||||
attr_accessor :add_commentary_tag, :add_commentary_request_tag, :add_commentary_check_tag, :add_partial_commentary_tag
|
||||
@@ -109,7 +109,7 @@ class ArtistCommentary < ApplicationRecord
|
||||
original_title: original_title,
|
||||
original_description: original_description,
|
||||
translated_title: translated_title,
|
||||
translated_description: translated_description,
|
||||
translated_description: translated_description
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -29,17 +29,17 @@ class ArtistUrl < ApplicationRecord
|
||||
|
||||
# the strategy won't always work for twitter because it looks for a status
|
||||
url = url.downcase if url =~ %r!^https?://(?:mobile\.)?twitter\.com!
|
||||
|
||||
|
||||
begin
|
||||
source = Sources::Strategies.find(url)
|
||||
|
||||
|
||||
if !source.normalized_for_artist_finder? && source.normalizable_for_artist_finder?
|
||||
url = source.normalize_for_artist_finder
|
||||
end
|
||||
rescue Net::OpenTimeout, PixivApiClient::Error
|
||||
raise if Rails.env.test?
|
||||
end
|
||||
|
||||
|
||||
url = url.gsub(/\/+\Z/, "")
|
||||
url = url.gsub(%r!^https://!, "http://")
|
||||
url + "/"
|
||||
|
||||
@@ -94,9 +94,7 @@ class Ban < ApplicationRecord
|
||||
@duration = dur
|
||||
end
|
||||
|
||||
def duration
|
||||
@duration
|
||||
end
|
||||
attr_reader :duration
|
||||
|
||||
def humanized_duration
|
||||
ApplicationController.helpers.distance_of_time_in_words(created_at, expires_at)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class BulkUpdateRequest < ApplicationRecord
|
||||
attr_accessor :reason, :skip_secondary_validations
|
||||
attr_accessor :reason
|
||||
attr_reader :skip_secondary_validations
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :forum_topic, optional: true
|
||||
@@ -65,8 +66,8 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
nil
|
||||
end
|
||||
ForumUpdater.new(
|
||||
forum_topic,
|
||||
forum_post: post,
|
||||
forum_topic,
|
||||
forum_post: post,
|
||||
expected_title: title,
|
||||
skip_update: !TagRelationship::SUPPORT_HARD_CODED
|
||||
)
|
||||
@@ -81,11 +82,10 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has been approved by @#{approver.name}.", "APPROVED")
|
||||
end
|
||||
end
|
||||
|
||||
rescue AliasAndImplicationImporter::Error => x
|
||||
self.approver = approver
|
||||
CurrentUser.scoped(approver) do
|
||||
forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has failed: #{x.to_s}", "FAILED")
|
||||
forum_updater.update("The #{bulk_update_request_link} (forum ##{forum_post.id}) has failed: #{x}", "FAILED")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -129,11 +129,9 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
end
|
||||
|
||||
def validate_script
|
||||
begin
|
||||
AliasAndImplicationImporter.new(script, forum_topic_id, "1", skip_secondary_validations).validate!
|
||||
rescue RuntimeError => e
|
||||
errors[:base] << e.message
|
||||
end
|
||||
AliasAndImplicationImporter.new(script, forum_topic_id, "1", skip_secondary_validations).validate!
|
||||
rescue RuntimeError => e
|
||||
errors[:base] << e.message
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -10,16 +10,16 @@ class Comment < ApplicationRecord
|
||||
has_many :votes, :class_name => "CommentVote", :dependent => :destroy
|
||||
after_create :update_last_commented_at_on_create
|
||||
after_update(:if => ->(rec) {(!rec.is_deleted? || !rec.saved_change_to_is_deleted?) && CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log("comment ##{rec.id} updated by #{CurrentUser.name}",:comment_update)
|
||||
ModAction.log("comment ##{rec.id} updated by #{CurrentUser.name}", :comment_update)
|
||||
end
|
||||
after_save :update_last_commented_at_on_destroy, :if => ->(rec) {rec.is_deleted? && rec.saved_change_to_is_deleted?}
|
||||
after_save(:if => ->(rec) {rec.is_deleted? && rec.saved_change_to_is_deleted? && CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log("comment ##{rec.id} deleted by #{CurrentUser.name}",:comment_delete)
|
||||
ModAction.log("comment ##{rec.id} deleted by #{CurrentUser.name}", :comment_delete)
|
||||
end
|
||||
mentionable(
|
||||
:message_field => :body,
|
||||
:message_field => :body,
|
||||
:title => ->(user_name) {"#{creator.name} mentioned you in a comment on post ##{post_id}"},
|
||||
:body => ->(user_name) {"@#{creator.name} mentioned you in a \"comment\":/posts/#{post_id}#comment-#{id} on post ##{post_id}:\n\n[quote]\n#{DText.excerpt(body, "@"+user_name)}\n[/quote]\n"},
|
||||
:body => ->(user_name) {"@#{creator.name} mentioned you in a \"comment\":/posts/#{post_id}#comment-#{id} on post ##{post_id}:\n\n[quote]\n#{DText.excerpt(body, "@" + user_name)}\n[/quote]\n"}
|
||||
)
|
||||
|
||||
api_attributes including: [:creator_name, :updater_name]
|
||||
@@ -56,7 +56,7 @@ class Comment < ApplicationRecord
|
||||
|
||||
module VoteMethods
|
||||
def vote!(val)
|
||||
numerical_score = val == "up" ? 1 : -1
|
||||
numerical_score = (val == "up") ? 1 : -1
|
||||
vote = votes.create!(:score => numerical_score)
|
||||
|
||||
if vote.is_positive?
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class CommentVote < ApplicationRecord
|
||||
class Error < Exception ; end
|
||||
class Error < Exception; end
|
||||
|
||||
belongs_to :comment
|
||||
belongs_to :user
|
||||
|
||||
@@ -11,7 +11,7 @@ class DmailFilter < ApplicationRecord
|
||||
end
|
||||
|
||||
def filtered?(dmail)
|
||||
dmail.from.level < User::Levels::MODERATOR && has_filter? && (dmail.body =~ regexp || dmail.title =~ regexp || dmail.from.name =~ regexp)
|
||||
dmail.from.level < User::Levels::MODERATOR && has_filter? && (dmail.body.match?(regexp) || dmail.title.match?(regexp) || dmail.from.name.match?(regexp))
|
||||
end
|
||||
|
||||
def has_filter?
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Favorite < ApplicationRecord
|
||||
class Error < Exception ; end
|
||||
class Error < Exception; end
|
||||
|
||||
belongs_to :post
|
||||
belongs_to :user
|
||||
@@ -34,7 +34,7 @@ class Favorite < ApplicationRecord
|
||||
return unless Favorite.for_user(user.id).where(:user_id => user.id, :post_id => post_id).exists?
|
||||
Favorite.for_user(user.id).where(post_id: post_id).delete_all
|
||||
Post.where(:id => post_id).update_all("fav_count = fav_count - 1")
|
||||
post.delete_user_from_fav_string(user.id) if post
|
||||
post&.delete_user_from_fav_string(user.id)
|
||||
User.where(:id => user.id).update_all("favorite_count = favorite_count - 1")
|
||||
user.favorite_count -= 1
|
||||
post.fav_count -= 1 if post
|
||||
|
||||
@@ -31,7 +31,7 @@ class FavoriteGroup < ApplicationRecord
|
||||
where("name ilike ? escape E'\\\\'", name.to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
def hide_private(user,params)
|
||||
def hide_private(user, params)
|
||||
if user.hide_favorites?
|
||||
where("is_public = true")
|
||||
elsif params[:is_public].present?
|
||||
@@ -51,14 +51,14 @@ class FavoriteGroup < ApplicationRecord
|
||||
|
||||
if params[:creator_id].present?
|
||||
user = User.find(params[:creator_id])
|
||||
q = q.hide_private(user,params)
|
||||
q = q.hide_private(user, params)
|
||||
q = q.where("creator_id = ?", user.id)
|
||||
elsif params[:creator_name].present?
|
||||
user = User.find_by_name(params[:creator_name])
|
||||
q = q.hide_private(user,params)
|
||||
q = q.hide_private(user, params)
|
||||
q = q.where("creator_id = ?", user.id)
|
||||
else
|
||||
q = q.hide_private(CurrentUser.user,params)
|
||||
q = q.hide_private(CurrentUser.user, params)
|
||||
q = q.where("creator_id = ?", CurrentUser.user.id)
|
||||
end
|
||||
|
||||
@@ -130,13 +130,11 @@ class FavoriteGroup < ApplicationRecord
|
||||
offset = options[:offset] || 0
|
||||
limit = options[:limit] || Danbooru.config.posts_per_page
|
||||
slice = post_id_array.slice(offset, limit)
|
||||
if slice && slice.any?
|
||||
if slice&.any?
|
||||
slice.map do |id|
|
||||
begin
|
||||
Post.find(id)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
# swallow
|
||||
end
|
||||
Post.find(id)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
# swallow
|
||||
end.compact
|
||||
else
|
||||
[]
|
||||
|
||||
@@ -23,15 +23,15 @@ class ForumPost < ApplicationRecord
|
||||
before_destroy :validate_topic_is_unlocked
|
||||
after_save :delete_topic_if_original_post
|
||||
after_update(:if => ->(rec) {rec.updater_id != rec.creator_id}) do |rec|
|
||||
ModAction.log("#{CurrentUser.name} updated forum ##{rec.id}",:forum_post_update)
|
||||
ModAction.log("#{CurrentUser.name} updated forum ##{rec.id}", :forum_post_update)
|
||||
end
|
||||
after_destroy(:if => ->(rec) {rec.updater_id != rec.creator_id}) do |rec|
|
||||
ModAction.log("#{CurrentUser.name} deleted forum ##{rec.id}",:forum_post_delete)
|
||||
ModAction.log("#{CurrentUser.name} deleted forum ##{rec.id}", :forum_post_delete)
|
||||
end
|
||||
mentionable(
|
||||
:message_field => :body,
|
||||
:message_field => :body,
|
||||
:title => ->(user_name) {%{#{creator.name} mentioned you in topic ##{topic_id} (#{topic.title})}},
|
||||
:body => ->(user_name) {%{@#{creator.name} mentioned you in topic ##{topic_id} ("#{topic.title}":[/forum_topics/#{topic_id}?page=#{forum_topic_page}]):\n\n[quote]\n#{DText.excerpt(body, "@"+user_name)}\n[/quote]\n}},
|
||||
:body => ->(user_name) {%{@#{creator.name} mentioned you in topic ##{topic_id} ("#{topic.title}":[/forum_topics/#{topic_id}?page=#{forum_topic_page}]):\n\n[quote]\n#{DText.excerpt(body, "@" + user_name)}\n[/quote]\n}}
|
||||
)
|
||||
|
||||
module SearchMethods
|
||||
@@ -173,11 +173,11 @@ class ForumPost < ApplicationRecord
|
||||
max = ForumPost.where(:topic_id => topic.id, :is_deleted => false).order("updated_at desc").first
|
||||
if max
|
||||
ForumTopic.where(:id => topic.id).update_all(["response_count = response_count - 1, updated_at = ?, updater_id = ?", max.updated_at, max.updater_id])
|
||||
topic.response_count -= 1
|
||||
else
|
||||
ForumTopic.where(:id => topic.id).update_all("response_count = response_count - 1")
|
||||
topic.response_count -= 1
|
||||
end
|
||||
|
||||
topic.response_count -= 1
|
||||
end
|
||||
|
||||
def initialize_is_deleted
|
||||
@@ -189,7 +189,7 @@ class ForumPost < ApplicationRecord
|
||||
end
|
||||
|
||||
def forum_topic_page
|
||||
((ForumPost.where("topic_id = ? and created_at <= ?", topic_id, created_at).count) / Danbooru.config.posts_per_page.to_f).ceil
|
||||
(ForumPost.where("topic_id = ? and created_at <= ?", topic_id, created_at).count / Danbooru.config.posts_per_page.to_f).ceil
|
||||
end
|
||||
|
||||
def is_original_post?(original_post_id = nil)
|
||||
|
||||
@@ -8,7 +8,7 @@ class ForumTopic < ApplicationRecord
|
||||
MIN_LEVELS = {
|
||||
None: 0,
|
||||
Moderator: User::Levels::MODERATOR,
|
||||
Admin: User::Levels::ADMIN,
|
||||
Admin: User::Levels::ADMIN
|
||||
}
|
||||
|
||||
belongs_to_creator
|
||||
@@ -25,7 +25,7 @@ class ForumTopic < ApplicationRecord
|
||||
accepts_nested_attributes_for :original_post
|
||||
after_update :update_orignal_post
|
||||
after_save(:if => ->(rec) {rec.is_locked? && rec.saved_change_to_is_locked?}) do |rec|
|
||||
ModAction.log("locked forum topic ##{id} (title: #{title})",:forum_topic_lock)
|
||||
ModAction.log("locked forum topic ##{id} (title: #{title})", :forum_topic_lock)
|
||||
end
|
||||
|
||||
module CategoryMethods
|
||||
@@ -97,7 +97,7 @@ class ForumTopic < ApplicationRecord
|
||||
|
||||
def mark_as_read!(user = CurrentUser.user)
|
||||
return if user.is_anonymous?
|
||||
|
||||
|
||||
match = ForumTopicVisit.where(:user_id => user.id, :forum_topic_id => id).first
|
||||
if match
|
||||
match.update_attribute(:last_read_at, updated_at)
|
||||
@@ -105,10 +105,15 @@ class ForumTopic < ApplicationRecord
|
||||
ForumTopicVisit.create(:user_id => user.id, :forum_topic_id => id, :last_read_at => updated_at)
|
||||
end
|
||||
|
||||
has_unread_topics = ForumTopic.permitted.active.where("forum_topics.updated_at >= ?", user.last_forum_read_at)
|
||||
.joins("left join forum_topic_visits on (forum_topic_visits.forum_topic_id = forum_topics.id and forum_topic_visits.user_id = #{user.id})")
|
||||
.where("(forum_topic_visits.id is null or forum_topic_visits.last_read_at < forum_topics.updated_at)")
|
||||
.exists?
|
||||
has_unread_topics =
|
||||
ForumTopic
|
||||
.permitted
|
||||
.active
|
||||
.where("forum_topics.updated_at >= ?", user.last_forum_read_at)
|
||||
.joins("left join forum_topic_visits on (forum_topic_visits.forum_topic_id = forum_topics.id and forum_topic_visits.user_id = #{user.id})")
|
||||
.where("(forum_topic_visits.id is null or forum_topic_visits.last_read_at < forum_topics.updated_at)")
|
||||
.exists?
|
||||
|
||||
unless has_unread_topics
|
||||
user.update_attribute(:last_forum_read_at, Time.now)
|
||||
ForumTopicVisit.prune!(user)
|
||||
@@ -136,11 +141,11 @@ class ForumTopic < ApplicationRecord
|
||||
end
|
||||
|
||||
def create_mod_action_for_delete
|
||||
ModAction.log("deleted forum topic ##{id} (title: #{title})",:forum_topic_delete)
|
||||
ModAction.log("deleted forum topic ##{id} (title: #{title})", :forum_topic_delete)
|
||||
end
|
||||
|
||||
def create_mod_action_for_undelete
|
||||
ModAction.log("undeleted forum topic ##{id} (title: #{title})",:forum_topic_undelete)
|
||||
ModAction.log("undeleted forum topic ##{id} (title: #{title})", :forum_topic_undelete)
|
||||
end
|
||||
|
||||
def initialize_is_deleted
|
||||
@@ -170,8 +175,6 @@ class ForumTopic < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_orignal_post
|
||||
if original_post
|
||||
original_post.update_columns(:updater_id => CurrentUser.id, :updated_at => Time.now)
|
||||
end
|
||||
original_post&.update_columns(:updater_id => CurrentUser.id, :updated_at => Time.now)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -36,7 +36,7 @@ class IpAddress < ApplicationRecord
|
||||
|
||||
def to_s
|
||||
# include the subnet mask only when the IP denotes a subnet.
|
||||
ip_addr.size > 1 ? ip_addr.to_string : ip_addr.to_s
|
||||
(ip_addr.size > 1) ? ip_addr.to_string : ip_addr.to_s
|
||||
end
|
||||
|
||||
def readonly?
|
||||
|
||||
@@ -4,17 +4,17 @@ class ModAction < ApplicationRecord
|
||||
|
||||
api_attributes including: [:category_id]
|
||||
|
||||
#####DIVISIONS#####
|
||||
#Groups: 0-999
|
||||
#Individual: 1000-1999
|
||||
#####Actions#####
|
||||
#Create: 0
|
||||
#Update: 1
|
||||
#Delete: 2
|
||||
#Undelete: 3
|
||||
#Ban: 4
|
||||
#Unban: 5
|
||||
#Misc: 6-19
|
||||
# ####DIVISIONS#####
|
||||
# Groups: 0-999
|
||||
# Individual: 1000-1999
|
||||
# ####Actions#####
|
||||
# Create: 0
|
||||
# Update: 1
|
||||
# Delete: 2
|
||||
# Undelete: 3
|
||||
# Ban: 4
|
||||
# Unban: 5
|
||||
# Misc: 6-19
|
||||
enum category: {
|
||||
user_delete: 2,
|
||||
user_ban: 4,
|
||||
@@ -77,7 +77,7 @@ class ModAction < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.log(desc, cat = :other)
|
||||
create(:description => desc,:category => categories[cat])
|
||||
create(:description => desc, :category => categories[cat])
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Note < ApplicationRecord
|
||||
class RevertError < Exception ; end
|
||||
class RevertError < Exception; end
|
||||
|
||||
attr_accessor :html_id
|
||||
belongs_to :post
|
||||
|
||||
@@ -4,10 +4,10 @@ class PixivUgoiraFrameData < ApplicationRecord
|
||||
|
||||
def normalize_data
|
||||
return if data.nil?
|
||||
|
||||
|
||||
if data[0]["delay_msec"]
|
||||
self.data = data.map.with_index do |datum, i|
|
||||
filename = "%06d.jpg" % [i]
|
||||
filename = format("%06d.jpg", i)
|
||||
{"delay" => datum["delay_msec"], "file" => filename}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Pool < ApplicationRecord
|
||||
class RevertError < Exception ; end
|
||||
class RevertError < Exception; end
|
||||
POOL_ORDER_LIMIT = 1000
|
||||
|
||||
array_attribute :post_ids, parse: /\d+/, cast: :to_i
|
||||
@@ -188,11 +188,11 @@ class Pool < ApplicationRecord
|
||||
end
|
||||
|
||||
def create_mod_action_for_delete
|
||||
ModAction.log("deleted pool ##{id} (name: #{name})",:pool_delete)
|
||||
ModAction.log("deleted pool ##{id} (name: #{name})", :pool_delete)
|
||||
end
|
||||
|
||||
def create_mod_action_for_undelete
|
||||
ModAction.log("undeleted pool ##{id} (name: #{name})",:pool_undelete)
|
||||
ModAction.log("undeleted pool ##{id} (name: #{name})", :pool_undelete)
|
||||
end
|
||||
|
||||
def add!(post)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
class PoolArchive < ApplicationRecord
|
||||
|
||||
belongs_to :updater, :class_name => "User"
|
||||
|
||||
def self.enabled?
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class PoolVersion < ApplicationRecord
|
||||
class Error < Exception ; end
|
||||
class Error < Exception; end
|
||||
|
||||
belongs_to :pool
|
||||
belongs_to_updater
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
require 'danbooru/has_bit_flags'
|
||||
|
||||
class Post < ApplicationRecord
|
||||
class ApprovalError < Exception ; end
|
||||
class DisapprovalError < Exception ; end
|
||||
class RevertError < Exception ; end
|
||||
class SearchError < Exception ; end
|
||||
class DeletionError < Exception ; end
|
||||
class TimeoutError < Exception ; end
|
||||
class ApprovalError < Exception; end
|
||||
class DisapprovalError < Exception; end
|
||||
class RevertError < Exception; end
|
||||
class SearchError < Exception; end
|
||||
class DeletionError < Exception; end
|
||||
class TimeoutError < Exception; end
|
||||
|
||||
# Tags to copy when copying notes.
|
||||
NOTE_COPY_TAGS = %w[translated partially_translated check_translation translation_request reverse_translation]
|
||||
@@ -222,9 +222,7 @@ class Post < ApplicationRecord
|
||||
is_image? && image_width.present? && image_width > Danbooru.config.large_image_width
|
||||
end
|
||||
|
||||
def has_large
|
||||
!!has_large?
|
||||
end
|
||||
alias has_large has_large?
|
||||
|
||||
def large_image_width
|
||||
if has_large?
|
||||
@@ -344,7 +342,7 @@ class Post < ApplicationRecord
|
||||
when %r{\Ahttps?://twitter.com/[^/]+/status/(\d+)\z}i
|
||||
"https://twitter.com/i/web/status/#{$1}"
|
||||
|
||||
when %r{\Ahttps?://lohas\.nicoseiga\.jp/priv/(\d+)\?e=\d+&h=[a-f0-9]+}i,
|
||||
when %r{\Ahttps?://lohas\.nicoseiga\.jp/priv/(\d+)\?e=\d+&h=[a-f0-9]+}i,
|
||||
%r{\Ahttps?://lohas\.nicoseiga\.jp/priv/[a-f0-9]+/\d+/(\d+)}i
|
||||
"https://seiga.nicovideo.jp/seiga/im#{$1}"
|
||||
|
||||
@@ -410,7 +408,7 @@ class Post < ApplicationRecord
|
||||
subdomain = $1
|
||||
filename = $2
|
||||
"http://#{subdomain}.wikia.com/wiki/File:#{filename}"
|
||||
|
||||
|
||||
when %r{\Ahttps?://vignette(?:\d*)\.wikia\.nocookie\.net/([^/]+)/images/[a-f0-9]/[a-f0-9]{2}/([^/]+)}i
|
||||
subdomain = $1
|
||||
filename = $2
|
||||
@@ -426,28 +424,28 @@ class Post < ApplicationRecord
|
||||
|
||||
when %r{\Ahttp://jpg\.nijigen-daiaru\.com/(\d+)}i
|
||||
"http://nijigen-daiaru.com/book.php?idb=#{$1}"
|
||||
|
||||
|
||||
when %r{\Ahttps?://sozai\.doujinantena\.com/contents_jpg/([a-f0-9]{32})/}i
|
||||
"http://doujinantena.com/page.php?id=#{$1}"
|
||||
|
||||
when %r{\Ahttp://rule34-(?:data-\d{3}|images)\.paheal\.net/(?:_images/)?([a-f0-9]{32})}i
|
||||
"https://rule34.paheal.net/post/list/md5:#{$1}/1"
|
||||
|
||||
|
||||
when %r{\Ahttp://shimmie\.katawa-shoujo\.com/image/(\d+)}i
|
||||
"https://shimmie.katawa-shoujo.com/post/view/#{$1}"
|
||||
|
||||
|
||||
when %r{\Ahttp://(?:(?:(?:img\d?|cdn)\.)?rule34\.xxx|img\.booru\.org/(?:rule34|r34))(?:/(?:img/rule34|r34))?/{1,2}images/\d+/(?:[a-f0-9]{32}|[a-f0-9]{40})\.}i
|
||||
"https://rule34.xxx/index.php?page=post&s=list&md5=#{md5}"
|
||||
|
||||
|
||||
when %r{(\Ahttp://.+)/diarypro/d(?:ata/upfile/|iary\.cgi\?mode=image&upfile=)(\d+)}i
|
||||
base_url = $1
|
||||
entry_no = $2
|
||||
"#{base_url}/diarypro/diary.cgi?no=#{entry_no}"
|
||||
|
||||
|
||||
# XXX site is defunct
|
||||
when %r{\Ahttp://i(?:\d)?\.minus\.com/(?:i|j)([^\.]{12,})}i
|
||||
"http://minus.com/i/#{$1}"
|
||||
|
||||
|
||||
when %r{\Ahttps?://pic0[1-4]\.nijie\.info/nijie_picture/(?:diff/main/)?\d+_(\d+)_(?:\d+{10}|\d+_\d+{14})}i
|
||||
"https://nijie.info/view.php?id=#{$1}"
|
||||
|
||||
@@ -475,16 +473,16 @@ class Post < ApplicationRecord
|
||||
# https://gfee_li.artstation.com/projects/asuka-7
|
||||
when %r{\Ahttps?://\w+\.artstation.com/(?:artwork|projects)/(?<project_id>[a-z0-9-]+)\z/}i
|
||||
"https://www.artstation.com/artwork/#{$~[:project_id]}"
|
||||
|
||||
|
||||
when %r{\Ahttps?://(?:o|image-proxy-origin)\.twimg\.com/\d/proxy\.jpg\?t=(\w+)&}i
|
||||
str = Base64.decode64($1)
|
||||
url = URI.extract(str, ['http', 'https'])
|
||||
if url.any?
|
||||
url = url[0]
|
||||
if (url =~ /^https?:\/\/twitpic.com\/show\/large\/[a-z0-9]+/i)
|
||||
if url =~ /^https?:\/\/twitpic.com\/show\/large\/[a-z0-9]+/i
|
||||
url.gsub!(/show\/large\//, "")
|
||||
index = url.rindex('.')
|
||||
url = url[0..index-1]
|
||||
url = url[0..index - 1]
|
||||
end
|
||||
url
|
||||
else
|
||||
@@ -524,7 +522,7 @@ class Post < ApplicationRecord
|
||||
|
||||
url = Addressable::URI.parse(normalized_source)
|
||||
url.domain
|
||||
rescue
|
||||
rescue StandardError
|
||||
""
|
||||
end
|
||||
end
|
||||
@@ -558,7 +556,7 @@ class Post < ApplicationRecord
|
||||
decrement_tags = tag_array_was - tag_array
|
||||
|
||||
decrement_tags_except_requests = decrement_tags.reject {|tag| tag == "tagme" || tag.end_with?("_request")}
|
||||
if decrement_tags_except_requests.size > 0 && !CurrentUser.is_builder? && CurrentUser.created_at > 1.week.ago
|
||||
if !decrement_tags_except_requests.empty? && !CurrentUser.is_builder? && CurrentUser.created_at > 1.week.ago
|
||||
self.errors.add(:updater_id, "must have an account at least 1 week old to remove tags")
|
||||
return false
|
||||
end
|
||||
@@ -572,17 +570,17 @@ class Post < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def set_tag_count(category,tagcount)
|
||||
self.send("tag_count_#{category}=",tagcount)
|
||||
def set_tag_count(category, tagcount)
|
||||
self.send("tag_count_#{category}=", tagcount)
|
||||
end
|
||||
|
||||
def inc_tag_count(category)
|
||||
set_tag_count(category,self.send("tag_count_#{category}") + 1)
|
||||
set_tag_count(category, self.send("tag_count_#{category}") + 1)
|
||||
end
|
||||
|
||||
def set_tag_counts(disable_cache = true)
|
||||
self.tag_count = 0
|
||||
TagCategory.categories.each {|x| set_tag_count(x,0)}
|
||||
TagCategory.categories.each {|x| set_tag_count(x, 0)}
|
||||
categories = Tag.categories_for(tag_array, :disable_caching => disable_cache)
|
||||
categories.each_value do |category|
|
||||
self.tag_count += 1
|
||||
@@ -596,8 +594,8 @@ class Post < ApplicationRecord
|
||||
if old_tag_string
|
||||
# If someone else committed changes to this post before we did,
|
||||
# then try to merge the tag changes together.
|
||||
current_tags = tag_array_was()
|
||||
new_tags = tag_array()
|
||||
current_tags = tag_array_was
|
||||
new_tags = tag_array
|
||||
old_tags = Tag.scan_tags(old_tag_string)
|
||||
|
||||
kept_tags = current_tags & new_tags
|
||||
@@ -645,7 +643,7 @@ class Post < ApplicationRecord
|
||||
normalized_tags = add_automatic_tags(normalized_tags)
|
||||
normalized_tags = remove_invalid_tags(normalized_tags)
|
||||
normalized_tags = Tag.convert_cosplay_tags(normalized_tags)
|
||||
normalized_tags = normalized_tags + Tag.create_for_list(TagImplication.automatic_tags_for(normalized_tags))
|
||||
normalized_tags += Tag.create_for_list(TagImplication.automatic_tags_for(normalized_tags))
|
||||
normalized_tags = TagImplication.with_descendants(normalized_tags)
|
||||
normalized_tags = normalized_tags.compact.uniq.sort
|
||||
normalized_tags = Tag.create_for_list(normalized_tags)
|
||||
@@ -732,9 +730,9 @@ class Post < ApplicationRecord
|
||||
|
||||
def apply_casesensitive_metatags(tags)
|
||||
casesensitive_metatags, tags = tags.partition {|x| x =~ /\A(?:source):/i}
|
||||
#Reuse the following metatags after the post has been saved
|
||||
# Reuse the following metatags after the post has been saved
|
||||
casesensitive_metatags += tags.select {|x| x =~ /\A(?:newpool):/i}
|
||||
if casesensitive_metatags.length > 0
|
||||
if !casesensitive_metatags.empty?
|
||||
case casesensitive_metatags[-1]
|
||||
when /^source:none$/i
|
||||
self.source = ""
|
||||
@@ -825,19 +823,19 @@ class Post < ApplicationRecord
|
||||
|
||||
when /^-favgroup:(\d+)$/i
|
||||
favgroup = FavoriteGroup.where("id = ?", $1.to_i).for_creator(CurrentUser.user.id).first
|
||||
favgroup.remove!(id) if favgroup
|
||||
favgroup&.remove!(id)
|
||||
|
||||
when /^-favgroup:(.+)$/i
|
||||
favgroup = FavoriteGroup.named($1).for_creator(CurrentUser.user.id).first
|
||||
favgroup.remove!(id) if favgroup
|
||||
favgroup&.remove!(id)
|
||||
|
||||
when /^favgroup:(\d+)$/i
|
||||
favgroup = FavoriteGroup.where("id = ?", $1.to_i).for_creator(CurrentUser.user.id).first
|
||||
favgroup.add!(id) if favgroup
|
||||
favgroup&.add!(id)
|
||||
|
||||
when /^favgroup:(.+)$/i
|
||||
favgroup = FavoriteGroup.named($1).for_creator(CurrentUser.user.id).first
|
||||
favgroup.add!(id) if favgroup
|
||||
favgroup&.add!(id)
|
||||
|
||||
end
|
||||
end
|
||||
@@ -866,20 +864,20 @@ class Post < ApplicationRecord
|
||||
self.rating = $1
|
||||
|
||||
when /^(-?)locked:notes?$/i
|
||||
self.is_note_locked = ($1 != "-" ) if CurrentUser.is_builder?
|
||||
self.is_note_locked = ($1 != "-") if CurrentUser.is_builder?
|
||||
|
||||
when /^(-?)locked:rating$/i
|
||||
self.is_rating_locked = ($1 != "-" ) if CurrentUser.is_builder?
|
||||
self.is_rating_locked = ($1 != "-") if CurrentUser.is_builder?
|
||||
|
||||
when /^(-?)locked:status$/i
|
||||
self.is_status_locked = ($1 != "-" ) if CurrentUser.is_admin?
|
||||
self.is_status_locked = ($1 != "-") if CurrentUser.is_admin?
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def has_tag?(tag)
|
||||
!!(tag_string =~ /(?:^| )(?:#{tag})(?:$| )/)
|
||||
tag_string.match?(/(?:^| )(?:#{tag})(?:$| )/)
|
||||
end
|
||||
|
||||
def add_tag(tag)
|
||||
@@ -910,7 +908,6 @@ class Post < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module FavoriteMethods
|
||||
def clean_fav_string?
|
||||
true
|
||||
@@ -925,10 +922,10 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def favorited_by?(user_id = CurrentUser.id)
|
||||
!!(fav_string =~ /(?:\A| )fav:#{user_id}(?:\Z| )/)
|
||||
fav_string.match?(/(?:\A| )fav:#{user_id}(?:\Z| )/)
|
||||
end
|
||||
|
||||
alias_method :is_favorited?, :favorited_by?
|
||||
alias is_favorited? favorited_by?
|
||||
|
||||
def append_user_to_fav_string(user_id)
|
||||
update_column(:fav_string, (fav_string + " fav:#{user_id}").strip)
|
||||
@@ -966,13 +963,13 @@ class Post < ApplicationRecord
|
||||
ordered_users
|
||||
end
|
||||
|
||||
def favorite_groups(active_id=nil)
|
||||
def favorite_groups(active_id = nil)
|
||||
@favorite_groups ||= begin
|
||||
groups = []
|
||||
|
||||
if active_id.present?
|
||||
active_group = FavoriteGroup.where(:id => active_id.to_i).first
|
||||
groups << active_group if active_group && active_group.contains?(self.id)
|
||||
groups << active_group if active_group&.contains?(self.id)
|
||||
end
|
||||
|
||||
groups += CurrentUser.user.favorite_groups.select do |favgroup|
|
||||
@@ -1016,7 +1013,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def has_active_pools?
|
||||
pools.undeleted.length > 0
|
||||
!pools.undeleted.empty?
|
||||
end
|
||||
|
||||
def belongs_to_pool?(pool)
|
||||
@@ -1091,7 +1088,7 @@ class Post < ApplicationRecord
|
||||
tags += " -status:deleted" if CurrentUser.hide_deleted_posts? && !Tag.has_metatag?(tags, "status", "-status")
|
||||
tags = Tag.normalize_query(tags)
|
||||
|
||||
# optimize some cases. these are just estimates but at these
|
||||
# Optimize some cases. these are just estimates but at these
|
||||
# quantities being off by a few hundred doesn't matter much
|
||||
if Danbooru.config.estimate_post_counts
|
||||
if tags == ""
|
||||
@@ -1148,7 +1145,7 @@ class Post < ApplicationRecord
|
||||
def fix_post_counts(post)
|
||||
post.set_tag_counts(false)
|
||||
if post.changes_saved?
|
||||
args = Hash[TagCategory.categories.map {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}].update(:tag_count => post.tag_count)
|
||||
args = Hash[TagCategory.categories.map {|x| ["tag_count_#{x}", post.send("tag_count_#{x}")]}].update(:tag_count => post.tag_count)
|
||||
post.update_columns(args)
|
||||
end
|
||||
end
|
||||
@@ -1207,7 +1204,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_parent_on_destroy
|
||||
parent.update_has_children_flag if parent
|
||||
parent&.update_has_children_flag
|
||||
end
|
||||
|
||||
def update_children_on_destroy
|
||||
@@ -1239,7 +1236,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
unless options[:without_mod_action]
|
||||
ModAction.log("moved favorites from post ##{id} to post ##{parent.id}",:post_move_favorites)
|
||||
ModAction.log("moved favorites from post ##{id} to post ##{parent.id}", :post_move_favorites)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1260,7 +1257,7 @@ class Post < ApplicationRecord
|
||||
|
||||
def children_ids
|
||||
if has_children?
|
||||
children.map{|p| p.id}.join(' ')
|
||||
children.map {|p| p.id}.join(' ')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1274,7 +1271,7 @@ class Post < ApplicationRecord
|
||||
|
||||
transaction do
|
||||
Post.without_timeout do
|
||||
ModAction.log("permanently deleted post ##{id}",:post_permanent_delete)
|
||||
ModAction.log("permanently deleted post ##{id}", :post_permanent_delete)
|
||||
|
||||
give_favorites_to_parent
|
||||
update_children_on_destroy
|
||||
@@ -1290,12 +1287,12 @@ class Post < ApplicationRecord
|
||||
|
||||
def ban!
|
||||
update_column(:is_banned, true)
|
||||
ModAction.log("banned post ##{id}",:post_ban)
|
||||
ModAction.log("banned post ##{id}", :post_ban)
|
||||
end
|
||||
|
||||
def unban!
|
||||
update_column(:is_banned, false)
|
||||
ModAction.log("unbanned post ##{id}",:post_unban)
|
||||
ModAction.log("unbanned post ##{id}", :post_unban)
|
||||
end
|
||||
|
||||
def delete!(reason, options = {})
|
||||
@@ -1318,7 +1315,7 @@ class Post < ApplicationRecord
|
||||
give_favorites_to_parent(options) if options[:move_favorites]
|
||||
|
||||
unless options[:without_mod_action]
|
||||
ModAction.log("deleted post ##{id}, reason: #{reason}",:post_delete)
|
||||
ModAction.log("deleted post ##{id}, reason: #{reason}", :post_delete)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1329,7 +1326,7 @@ class Post < ApplicationRecord
|
||||
return false
|
||||
end
|
||||
|
||||
if !CurrentUser.is_admin?
|
||||
if !CurrentUser.is_admin?
|
||||
if approved_by?(CurrentUser.user)
|
||||
raise ApprovalError.new("You have previously approved this post and cannot undelete it")
|
||||
elsif uploader_id == CurrentUser.id
|
||||
@@ -1341,7 +1338,7 @@ class Post < ApplicationRecord
|
||||
self.approver_id = CurrentUser.id
|
||||
flags.each {|x| x.resolve!}
|
||||
save
|
||||
ModAction.log("undeleted post ##{id}",:post_undelete)
|
||||
ModAction.log("undeleted post ##{id}", :post_undelete)
|
||||
end
|
||||
|
||||
def replace!(params)
|
||||
@@ -1445,7 +1442,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def associated_attributes
|
||||
[ :pixiv_ugoira_frame_data ]
|
||||
[:pixiv_ugoira_frame_data]
|
||||
end
|
||||
|
||||
def as_json(options = {})
|
||||
@@ -1645,7 +1642,7 @@ class Post < ApplicationRecord
|
||||
PostQueryBuilder.new(query).build
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
module PixivMethods
|
||||
def parse_pixiv_id
|
||||
self.pixiv_id = nil
|
||||
@@ -1713,18 +1710,18 @@ class Post < ApplicationRecord
|
||||
if new_general_tags.present?
|
||||
n = new_general_tags.size
|
||||
tag_wiki_links = new_general_tags.map { |tag| "[[#{tag.name}]]" }
|
||||
self.warnings[:base] << "Created #{n} new #{n == 1 ? "tag" : "tags"}: #{tag_wiki_links.join(", ")}"
|
||||
self.warnings[:base] << "Created #{n} new #{(n == 1) ? "tag" : "tags"}: #{tag_wiki_links.join(", ")}"
|
||||
end
|
||||
|
||||
if repopulated_tags.present?
|
||||
n = repopulated_tags.size
|
||||
tag_wiki_links = repopulated_tags.map { |tag| "[[#{tag.name}]]" }
|
||||
self.warnings[:base] << "Repopulated #{n} old #{n == 1 ? "tag" : "tags"}: #{tag_wiki_links.join(", ")}"
|
||||
self.warnings[:base] << "Repopulated #{n} old #{(n == 1) ? "tag" : "tags"}: #{tag_wiki_links.join(", ")}"
|
||||
end
|
||||
|
||||
new_artist_tags.each do |tag|
|
||||
if tag.artist.blank?
|
||||
self.warnings[:base] << "Artist [[#{tag.name}]] requires an artist entry. \"Create new artist entry\":[/artists/new?artist%5Bname%5D=#{CGI::escape(tag.name)}]"
|
||||
self.warnings[:base] << "Artist [[#{tag.name}]] requires an artist entry. \"Create new artist entry\":[/artists/new?artist%5Bname%5D=#{CGI.escape(tag.name)}]"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1746,7 +1743,7 @@ class Post < ApplicationRecord
|
||||
return if tags.any? { |t| t.category == Tag.categories.artist }
|
||||
return if Sources::Strategies.find(source).is_a?(Sources::Strategies::Null)
|
||||
|
||||
self.warnings[:base] << "Artist tag is required. \"Create new artist tag\":[/artists/new?artist%5Bsource%5D=#{CGI::escape(source)}]. Ask on the forum if you need naming help"
|
||||
self.warnings[:base] << "Artist tag is required. \"Create new artist tag\":[/artists/new?artist%5Bsource%5D=#{CGI.escape(source)}]. Ask on the forum if you need naming help"
|
||||
end
|
||||
|
||||
def has_copyright_tag
|
||||
@@ -1764,7 +1761,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
include FileMethods
|
||||
include ImageMethods
|
||||
include ApprovalMethods
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class PostAppeal < ApplicationRecord
|
||||
class Error < Exception ; end
|
||||
class Error < Exception; end
|
||||
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :post
|
||||
|
||||
@@ -26,7 +26,7 @@ class PostApproval < ApplicationRecord
|
||||
end
|
||||
|
||||
def approve_post
|
||||
ModAction.log("undeleted post ##{post_id}",:post_undelete) if post.is_deleted
|
||||
ModAction.log("undeleted post ##{post_id}", :post_undelete) if post.is_deleted
|
||||
|
||||
post.flags.each(&:resolve!)
|
||||
post.update(approver: user, is_flagged: false, is_pending: false, is_deleted: false)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class PostArchive < ApplicationRecord
|
||||
class RevertError < Exception ; end
|
||||
class RevertError < Exception; end
|
||||
extend Memoist
|
||||
|
||||
belongs_to :post
|
||||
@@ -102,7 +102,7 @@ class PostArchive < ApplicationRecord
|
||||
end
|
||||
|
||||
def visible?
|
||||
post && post.visible?
|
||||
post&.visible?
|
||||
end
|
||||
|
||||
def diff(version = nil)
|
||||
@@ -135,10 +135,10 @@ class PostArchive < ApplicationRecord
|
||||
:removed_tags => removed_tags,
|
||||
:obsolete_added_tags => added_tags - latest_tags,
|
||||
:obsolete_removed_tags => removed_tags & latest_tags,
|
||||
:unchanged_tags => new_tags & old_tags,
|
||||
:unchanged_tags => new_tags & old_tags
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
def changes
|
||||
delta = {
|
||||
:added_tags => added_tags,
|
||||
|
||||
@@ -58,7 +58,7 @@ class PostEvent
|
||||
"created_at": nil,
|
||||
"reason": nil,
|
||||
"is_resolved": nil,
|
||||
"type": nil,
|
||||
"type": nil
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class PostFlag < ApplicationRecord
|
||||
class Error < Exception ; end
|
||||
class Error < Exception; end
|
||||
|
||||
module Reasons
|
||||
UNAPPROVED = "Unapproved in three days"
|
||||
|
||||
@@ -33,5 +33,4 @@ class PostReplacement < ApplicationRecord
|
||||
tags = tags.map { |tag| "-#{tag}" }
|
||||
tags.join(" ")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -85,7 +85,7 @@ class PostVersion < ApplicationRecord
|
||||
:removed_tags => removed_tags,
|
||||
:obsolete_added_tags => added_tags - latest_tags,
|
||||
:obsolete_removed_tags => removed_tags & latest_tags,
|
||||
:unchanged_tags => new_tags & old_tags,
|
||||
:unchanged_tags => new_tags & old_tags
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class PostVote < ApplicationRecord
|
||||
class Error < Exception ; end
|
||||
class Error < Exception; end
|
||||
|
||||
belongs_to :post
|
||||
belongs_to :user
|
||||
|
||||
@@ -46,11 +46,11 @@ class SavedSearch < ApplicationRecord
|
||||
concerning :Labels do
|
||||
class_methods do
|
||||
def normalize_label(label)
|
||||
label.
|
||||
to_s.
|
||||
strip.
|
||||
downcase.
|
||||
gsub(/[[:space:]]/, "_")
|
||||
label
|
||||
.to_s
|
||||
.strip
|
||||
.downcase
|
||||
.gsub(/[[:space:]]/, "_")
|
||||
end
|
||||
|
||||
def search_labels(user_id, params)
|
||||
@@ -67,17 +67,15 @@ class SavedSearch < ApplicationRecord
|
||||
end
|
||||
|
||||
def labels_for(user_id)
|
||||
SavedSearch.
|
||||
where(user_id: user_id).
|
||||
order("label").
|
||||
pluck(Arel.sql("distinct unnest(labels) as label"))
|
||||
SavedSearch
|
||||
.where(user_id: user_id)
|
||||
.order("label")
|
||||
.pluck(Arel.sql("distinct unnest(labels) as label"))
|
||||
end
|
||||
end
|
||||
|
||||
def normalize_labels
|
||||
self.labels = labels.
|
||||
map {|x| SavedSearch.normalize_label(x)}.
|
||||
reject {|x| x.blank?}
|
||||
self.labels = labels.map {|x| SavedSearch.normalize_label(x)}.reject(&:blank?)
|
||||
end
|
||||
|
||||
def label_string
|
||||
@@ -137,13 +135,13 @@ class SavedSearch < ApplicationRecord
|
||||
concerning :Queries do
|
||||
class_methods do
|
||||
def queries_for(user_id, label: nil, options: {})
|
||||
SavedSearch.
|
||||
where(user_id: user_id).
|
||||
labeled(label).
|
||||
pluck(:query).
|
||||
map {|x| Tag.normalize_query(x, sort: true)}.
|
||||
sort.
|
||||
uniq
|
||||
SavedSearch
|
||||
.where(user_id: user_id)
|
||||
.labeled(label)
|
||||
.pluck(:query)
|
||||
.map {|x| Tag.normalize_query(x, sort: true)}
|
||||
.sort
|
||||
.uniq
|
||||
end
|
||||
end
|
||||
|
||||
@@ -156,7 +154,7 @@ class SavedSearch < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
attr_accessor :disable_labels
|
||||
attr_reader :disable_labels
|
||||
belongs_to :user
|
||||
validates :query, presence: true
|
||||
validate :validate_count
|
||||
|
||||
@@ -40,9 +40,9 @@ class Tag < ApplicationRecord
|
||||
random
|
||||
custom
|
||||
] +
|
||||
COUNT_METATAGS +
|
||||
COUNT_METATAG_SYNONYMS.flat_map { |str| [str, "#{str}_asc"] } +
|
||||
TagCategory.short_name_list.flat_map { |str| ["#{str}tags", "#{str}tags_asc"] }
|
||||
COUNT_METATAGS +
|
||||
COUNT_METATAG_SYNONYMS.flat_map { |str| [str, "#{str}_asc"] } +
|
||||
TagCategory.short_name_list.flat_map { |str| ["#{str}tags", "#{str}tags_asc"] }
|
||||
|
||||
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
|
||||
has_one :artist, :foreign_key => "name", :primary_key => "name"
|
||||
@@ -130,7 +130,7 @@ class Tag < ApplicationRecord
|
||||
module CategoryMethods
|
||||
module ClassMethods
|
||||
def categories
|
||||
@category_mapping ||= CategoryMapping.new
|
||||
@categories ||= CategoryMapping.new
|
||||
end
|
||||
|
||||
def select_category_for(tag_name)
|
||||
@@ -170,11 +170,11 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_category_post_counts
|
||||
Post.with_timeout(30_000, nil, {:tags => name}) do
|
||||
Post.with_timeout(30_000, nil, :tags => name) do
|
||||
Post.raw_tag_match(name).where("true /* Tag#update_category_post_counts */").find_each do |post|
|
||||
post.reload
|
||||
post.set_tag_counts(false)
|
||||
args = TagCategory.categories.map {|x| ["tag_count_#{x}",post.send("tag_count_#{x}")]}.to_h.update(:tag_count => post.tag_count)
|
||||
args = TagCategory.categories.map {|x| ["tag_count_#{x}", post.send("tag_count_#{x}")]}.to_h.update(:tag_count => post.tag_count)
|
||||
Post.where(:id => post.id).update_all(args)
|
||||
end
|
||||
end
|
||||
@@ -314,11 +314,7 @@ class Tag < ApplicationRecord
|
||||
object.to_f
|
||||
|
||||
when :date, :datetime
|
||||
begin
|
||||
Time.zone.parse(object)
|
||||
rescue Exception
|
||||
nil
|
||||
end
|
||||
Time.zone.parse(object) rescue nil
|
||||
|
||||
when :age
|
||||
DurationParser.parse(object).ago
|
||||
@@ -327,7 +323,7 @@ class Tag < ApplicationRecord
|
||||
object =~ /\A(\d+(?:\.\d+)?):(\d+(?:\.\d+)?)\Z/i
|
||||
|
||||
if $1 && $2.to_f != 0.0
|
||||
($1.to_f / $2.to_f).round(2)
|
||||
($1.to_f / $2.to_f).round(2)
|
||||
else
|
||||
object.to_f.round(2)
|
||||
end
|
||||
@@ -750,7 +746,7 @@ class Tag < ApplicationRecord
|
||||
when "order"
|
||||
g2 = g2.downcase
|
||||
|
||||
order, suffix, _ = g2.partition(/_(asc|desc)\z/i)
|
||||
order, suffix, _tail = g2.partition(/_(asc|desc)\z/i)
|
||||
if order.in?(COUNT_METATAG_SYNONYMS)
|
||||
g2 = order.singularize + "_count" + suffix
|
||||
end
|
||||
@@ -898,10 +894,14 @@ class Tag < ApplicationRecord
|
||||
name = normalize_name(name)
|
||||
wildcard_name = name + '*'
|
||||
|
||||
query1 = Tag.select("tags.name, tags.post_count, tags.category, null AS antecedent_name")
|
||||
query1 =
|
||||
Tag
|
||||
.select("tags.name, tags.post_count, tags.category, null AS antecedent_name")
|
||||
.search(:name_matches => wildcard_name, :order => "count").limit(limit)
|
||||
|
||||
query2 = TagAlias.select("tags.name, tags.post_count, tags.category, tag_aliases.antecedent_name")
|
||||
query2 =
|
||||
TagAlias
|
||||
.select("tags.name, tags.post_count, tags.category, tag_aliases.antecedent_name")
|
||||
.joins("INNER JOIN tags ON tags.name = tag_aliases.consequent_name")
|
||||
.where("tag_aliases.antecedent_name LIKE ? ESCAPE E'\\\\'", wildcard_name.to_escaped_for_sql_like)
|
||||
.active
|
||||
@@ -922,7 +922,7 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.convert_cosplay_tags(tags)
|
||||
cosplay_tags,other_tags = tags.partition {|tag| tag.match(/\A(.+)_\(cosplay\)\Z/) }
|
||||
cosplay_tags, other_tags = tags.partition {|tag| tag.match(/\A(.+)_\(cosplay\)\Z/) }
|
||||
cosplay_tags.grep(/\A(.+)_\(cosplay\)\Z/) { "#{TagAlias.to_aliased([$1]).first}_(cosplay)" } + other_tags
|
||||
end
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class TagAlias < TagRelationship
|
||||
nil
|
||||
end
|
||||
ForumUpdater.new(
|
||||
forum_topic,
|
||||
forum_topic,
|
||||
forum_post: post,
|
||||
expected_title: "Tag alias: #{antecedent_name} -> #{consequent_name}",
|
||||
skip_update: !TagRelationship::SUPPORT_HARD_CODED
|
||||
@@ -69,7 +69,7 @@ class TagAlias < TagRelationship
|
||||
rescue Exception => e
|
||||
if tries < 5
|
||||
tries += 1
|
||||
sleep 2 ** tries
|
||||
sleep 2**tries
|
||||
retry
|
||||
end
|
||||
|
||||
@@ -148,7 +148,7 @@ class TagAlias < TagRelationship
|
||||
|
||||
def rename_wiki_and_artist
|
||||
antecedent_wiki = WikiPage.titled(antecedent_name).first
|
||||
if antecedent_wiki.present?
|
||||
if antecedent_wiki.present?
|
||||
if WikiPage.titled(consequent_name).blank?
|
||||
antecedent_wiki.update!(title: consequent_name, skip_secondary_validations: true)
|
||||
else
|
||||
@@ -178,22 +178,22 @@ class TagAlias < TagRelationship
|
||||
end
|
||||
|
||||
def create_mod_action
|
||||
alias_desc = %Q("tag alias ##{id}":[#{Rails.application.routes.url_helpers.tag_alias_path(self)}]: [[#{antecedent_name}]] -> [[#{consequent_name}]])
|
||||
alias_desc = %("tag alias ##{id}":[#{Rails.application.routes.url_helpers.tag_alias_path(self)}]: [[#{antecedent_name}]] -> [[#{consequent_name}]])
|
||||
|
||||
if saved_change_to_id?
|
||||
ModAction.log("created #{status} #{alias_desc}",:tag_alias_create)
|
||||
ModAction.log("created #{status} #{alias_desc}", :tag_alias_create)
|
||||
else
|
||||
# format the changes hash more nicely.
|
||||
change_desc = saved_changes.except(:updated_at).map do |attribute, values|
|
||||
old, new = values[0], values[1]
|
||||
if old.nil?
|
||||
%Q(set #{attribute} to "#{new}")
|
||||
%(set #{attribute} to "#{new}")
|
||||
else
|
||||
%Q(changed #{attribute} from "#{old}" to "#{new}")
|
||||
%(changed #{attribute} from "#{old}" to "#{new}")
|
||||
end
|
||||
end.join(", ")
|
||||
|
||||
ModAction.log("updated #{alias_desc}\n#{change_desc}",:tag_alias_update)
|
||||
ModAction.log("updated #{alias_desc}\n#{change_desc}", :tag_alias_update)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -144,7 +144,7 @@ class TagImplication < TagRelationship
|
||||
rescue Exception => e
|
||||
if tries < 5
|
||||
tries += 1
|
||||
sleep 2 ** tries
|
||||
sleep 2**tries
|
||||
retry
|
||||
end
|
||||
|
||||
@@ -170,22 +170,22 @@ class TagImplication < TagRelationship
|
||||
end
|
||||
|
||||
def create_mod_action
|
||||
implication = %Q("tag implication ##{id}":[#{Rails.application.routes.url_helpers.tag_implication_path(self)}]: [[#{antecedent_name}]] -> [[#{consequent_name}]])
|
||||
implication = %("tag implication ##{id}":[#{Rails.application.routes.url_helpers.tag_implication_path(self)}]: [[#{antecedent_name}]] -> [[#{consequent_name}]])
|
||||
|
||||
if saved_change_to_id?
|
||||
ModAction.log("created #{status} #{implication}",:tag_implication_create)
|
||||
ModAction.log("created #{status} #{implication}", :tag_implication_create)
|
||||
else
|
||||
# format the changes hash more nicely.
|
||||
change_desc = saved_changes.except(:updated_at).map do |attribute, values|
|
||||
old, new = values[0], values[1]
|
||||
if old.nil?
|
||||
%Q(set #{attribute} to "#{new}")
|
||||
%(set #{attribute} to "#{new}")
|
||||
else
|
||||
%Q(changed #{attribute} from "#{old}" to "#{new}")
|
||||
%(changed #{attribute} from "#{old}" to "#{new}")
|
||||
end
|
||||
end.join(", ")
|
||||
|
||||
ModAction.log("updated #{implication}\n#{change_desc}",:tag_implication_update)
|
||||
ModAction.log("updated #{implication}\n#{change_desc}", :tag_implication_update)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -196,8 +196,8 @@ class TagImplication < TagRelationship
|
||||
nil
|
||||
end
|
||||
ForumUpdater.new(
|
||||
forum_topic,
|
||||
forum_post: post,
|
||||
forum_topic,
|
||||
forum_post: post,
|
||||
expected_title: "Tag implication: #{antecedent_name} -> #{consequent_name}",
|
||||
skip_update: !TagRelationship::SUPPORT_HARD_CODED
|
||||
)
|
||||
|
||||
@@ -16,13 +16,13 @@ class TagRelationship < ApplicationRecord
|
||||
has_one :antecedent_wiki, through: :antecedent_tag, source: :wiki_page
|
||||
has_one :consequent_wiki, through: :consequent_tag, source: :wiki_page
|
||||
|
||||
scope :active, ->{approved}
|
||||
scope :approved, ->{where(status: %w[active processing queued])}
|
||||
scope :deleted, ->{where(status: "deleted")}
|
||||
scope :expired, ->{where("created_at < ?", EXPIRY.days.ago)}
|
||||
scope :old, ->{where("created_at >= ? and created_at < ?", EXPIRY.days.ago, EXPIRY_WARNING.days.ago)}
|
||||
scope :pending, ->{where(status: "pending")}
|
||||
scope :retired, ->{where(status: "retired")}
|
||||
scope :active, -> {approved}
|
||||
scope :approved, -> {where(status: %w[active processing queued])}
|
||||
scope :deleted, -> {where(status: "deleted")}
|
||||
scope :expired, -> {where("created_at < ?", EXPIRY.days.ago)}
|
||||
scope :old, -> {where("created_at >= ? and created_at < ?", EXPIRY.days.ago, EXPIRY_WARNING.days.ago)}
|
||||
scope :pending, -> {where(status: "pending")}
|
||||
scope :retired, -> {where(status: "retired")}
|
||||
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :normalize_names
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
require "tmpdir"
|
||||
|
||||
class Upload < ApplicationRecord
|
||||
class Error < Exception ; end
|
||||
class Error < Exception; end
|
||||
|
||||
class FileValidator < ActiveModel::Validator
|
||||
def validate(record)
|
||||
@@ -54,7 +54,6 @@ class Upload < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
attr_accessor :as_pending, :replaced_post, :file
|
||||
belongs_to :uploader, :class_name => "User"
|
||||
belongs_to :post, optional: true
|
||||
@@ -64,7 +63,7 @@ class Upload < ApplicationRecord
|
||||
validate :uploader_is_not_limited, on: :create
|
||||
# validates :source, format: { with: /\Ahttps?/ }, if: ->(record) {record.file.blank?}, on: :create
|
||||
validates :rating, inclusion: { in: %w(q e s) }, allow_nil: true
|
||||
validates :md5, confirmation: true, if: -> (rec) { rec.md5_confirmation.present? }
|
||||
validates :md5, confirmation: true, if: ->(rec) { rec.md5_confirmation.present? }
|
||||
validates_with FileValidator, on: :file
|
||||
serialize :context, JSON
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ require 'digest/sha1'
|
||||
require 'danbooru/has_bit_flags'
|
||||
|
||||
class User < ApplicationRecord
|
||||
class Error < Exception ; end
|
||||
class PrivilegeError < Exception ; end
|
||||
class Error < Exception; end
|
||||
class PrivilegeError < Exception; end
|
||||
|
||||
module Levels
|
||||
ANONYMOUS = 0
|
||||
@@ -20,7 +20,7 @@ class User < ApplicationRecord
|
||||
:banned,
|
||||
:approver,
|
||||
:voter,
|
||||
:super_voter,
|
||||
:super_voter
|
||||
]
|
||||
|
||||
# candidates for removal:
|
||||
@@ -199,7 +199,7 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def reset_password_and_deliver_notice
|
||||
new_password = reset_password()
|
||||
new_password = reset_password
|
||||
Maintenance::User::PasswordResetMailer.confirmation(self, new_password).deliver_now
|
||||
end
|
||||
end
|
||||
@@ -296,7 +296,7 @@ class User < ApplicationRecord
|
||||
|
||||
when Levels::ADMIN
|
||||
"Admin"
|
||||
|
||||
|
||||
else
|
||||
""
|
||||
end
|
||||
@@ -570,23 +570,23 @@ class User < ApplicationRecord
|
||||
|
||||
module ApiMethods
|
||||
def api_attributes
|
||||
attributes = [
|
||||
:id, :created_at, :name, :inviter_id, :level, :base_upload_limit,
|
||||
:post_upload_count, :post_update_count, :note_update_count, :is_banned,
|
||||
:can_approve_posts, :can_upload_free, :is_super_voter, :level_string,
|
||||
attributes = %i[
|
||||
id created_at name inviter_id level base_upload_limit
|
||||
post_upload_count post_update_count note_update_count is_banned
|
||||
can_approve_posts can_upload_free is_super_voter level_string
|
||||
]
|
||||
|
||||
if id == CurrentUser.user.id
|
||||
attributes += BOOLEAN_ATTRIBUTES
|
||||
attributes += [
|
||||
:updated_at, :email, :last_logged_in_at, :last_forum_read_at,
|
||||
:comment_threshold, :default_image_size,
|
||||
:favorite_tags, :blacklisted_tags, :time_zone, :per_page,
|
||||
:custom_style, :favorite_count, :api_regen_multiplier,
|
||||
:api_burst_limit, :remaining_api_limit, :statement_timeout,
|
||||
:favorite_group_limit, :favorite_limit, :tag_query_limit,
|
||||
:can_comment_vote?, :can_remove_from_pools?, :is_comment_limited?,
|
||||
:can_comment?, :can_upload?, :max_saved_searches, :theme
|
||||
attributes += %i[
|
||||
updated_at email last_logged_in_at last_forum_read_at
|
||||
comment_threshold default_image_size
|
||||
favorite_tags blacklisted_tags time_zone per_page
|
||||
custom_style favorite_count api_regen_multiplier
|
||||
api_burst_limit remaining_api_limit statement_timeout
|
||||
favorite_group_limit favorite_limit tag_query_limit
|
||||
can_comment_vote? can_remove_from_pools? is_comment_limited?
|
||||
can_comment? can_upload? max_saved_searches theme
|
||||
]
|
||||
end
|
||||
|
||||
@@ -595,13 +595,13 @@ class User < ApplicationRecord
|
||||
|
||||
# extra attributes returned for /users/:id.json but not for /users.json.
|
||||
def full_attributes
|
||||
[
|
||||
:wiki_page_version_count, :artist_version_count,
|
||||
:artist_commentary_version_count, :pool_version_count,
|
||||
:forum_post_count, :comment_count, :favorite_group_count,
|
||||
:appeal_count, :flag_count, :positive_feedback_count,
|
||||
:neutral_feedback_count, :negative_feedback_count, :upload_limit,
|
||||
:max_upload_limit
|
||||
%i[
|
||||
wiki_page_version_count artist_version_count
|
||||
artist_commentary_version_count pool_version_count
|
||||
forum_post_count comment_count favorite_group_count
|
||||
appeal_count flag_count positive_feedback_count
|
||||
neutral_feedback_count negative_feedback_count upload_limit
|
||||
max_upload_limit
|
||||
]
|
||||
end
|
||||
|
||||
@@ -731,10 +731,10 @@ class User < ApplicationRecord
|
||||
if params[x].present?
|
||||
attr_idx = BOOLEAN_ATTRIBUTES.index(x.to_s)
|
||||
if params[x].to_s.truthy?
|
||||
bitprefs_include ||= "0"*bitprefs_length
|
||||
bitprefs_include ||= "0" * bitprefs_length
|
||||
bitprefs_include[attr_idx] = '1'
|
||||
elsif params[x].to_s.falsy?
|
||||
bitprefs_exclude ||= "0"*bitprefs_length
|
||||
bitprefs_exclude ||= "0" * bitprefs_length
|
||||
bitprefs_exclude[attr_idx] = '1'
|
||||
end
|
||||
end
|
||||
@@ -743,13 +743,13 @@ class User < ApplicationRecord
|
||||
if bitprefs_include
|
||||
bitprefs_include.reverse!
|
||||
q = q.where("bit_prefs::bit(:len) & :bits::bit(:len) = :bits::bit(:len)",
|
||||
{:len => bitprefs_length, :bits => bitprefs_include})
|
||||
:len => bitprefs_length, :bits => bitprefs_include)
|
||||
end
|
||||
|
||||
if bitprefs_exclude
|
||||
bitprefs_exclude.reverse!
|
||||
q = q.where("bit_prefs::bit(:len) & :bits::bit(:len) = 0::bit(:len)",
|
||||
{:len => bitprefs_length, :bits => bitprefs_exclude})
|
||||
:len => bitprefs_length, :bits => bitprefs_exclude)
|
||||
end
|
||||
|
||||
if params[:current_user_first].to_s.truthy? && !CurrentUser.is_anonymous?
|
||||
|
||||
@@ -9,10 +9,10 @@ class UserFeedback < ApplicationRecord
|
||||
validate :user_is_not_creator
|
||||
after_create :create_dmail, unless: :disable_dmail_notification
|
||||
after_update(:if => ->(rec) { CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log(%{#{CurrentUser.name} updated user feedback for "#{rec.user.name}":/users/#{rec.user_id}},:user_feedback_update)
|
||||
ModAction.log(%{#{CurrentUser.name} updated user feedback for "#{rec.user.name}":/users/#{rec.user_id}}, :user_feedback_update)
|
||||
end
|
||||
after_destroy(:if => ->(rec) { CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log(%{#{CurrentUser.name} deleted user feedback for "#{rec.user.name}":/users/#{rec.user_id}},:user_feedback_delete)
|
||||
ModAction.log(%{#{CurrentUser.name} deleted user feedback for "#{rec.user.name}":/users/#{rec.user_id}}, :user_feedback_delete)
|
||||
end
|
||||
|
||||
module SearchMethods
|
||||
@@ -77,7 +77,7 @@ class UserFeedback < ApplicationRecord
|
||||
errors[:creator] << "cannot submit feedback"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def user_is_not_creator
|
||||
if user_id == creator_id
|
||||
errors[:creator] << "cannot submit feedback for yourself"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class WikiPage < ApplicationRecord
|
||||
class RevertError < Exception ; end
|
||||
class RevertError < Exception; end
|
||||
|
||||
META_WIKIS = ["list_of_", "tag_group:", "pool_group:", "howto:", "about:", "help:", "template:"]
|
||||
|
||||
@@ -128,13 +128,13 @@ class WikiPage < ApplicationRecord
|
||||
|
||||
tag_was = Tag.find_by_name(Tag.normalize_name(title_was))
|
||||
if tag_was.present? && tag_was.post_count > 0
|
||||
warnings[:base] << %Q!Warning: {{#{title_was}}} still has #{tag_was.post_count} #{"post".pluralize(tag_was.post_count)}. Be sure to move the posts!
|
||||
warnings[:base] << %!Warning: {{#{title_was}}} still has #{tag_was.post_count} #{"post".pluralize(tag_was.post_count)}. Be sure to move the posts!
|
||||
end
|
||||
|
||||
broken_wikis = WikiPage.linked_to(title_was)
|
||||
if broken_wikis.count > 0
|
||||
broken_wiki_search = Rails.application.routes.url_helpers.wiki_pages_path(search: { linked_to: title_was })
|
||||
warnings[:base] << %Q!Warning: [[#{title_was}]] is still linked from "#{broken_wikis.count} #{"other wiki page".pluralize(broken_wikis.count)}":[#{broken_wiki_search}]. Update #{broken_wikis.count > 1 ? "these wikis" : "this wiki"} to link to [[#{title}]] instead!
|
||||
warnings[:base] << %!Warning: [[#{title_was}]] is still linked from "#{broken_wikis.count} #{"other wiki page".pluralize(broken_wikis.count)}":[#{broken_wiki_search}]. Update #{(broken_wikis.count > 1) ? "these wikis" : "this wiki"} to link to [[#{title}]] instead!
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user