Merge branch 'master' into fix-3278
This commit is contained in:
@@ -84,5 +84,9 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def warnings
|
||||
@warnings ||= ActiveModel::Errors.new(self)
|
||||
end
|
||||
|
||||
include ApiMethods
|
||||
end
|
||||
|
||||
@@ -182,8 +182,8 @@ class Comment < ApplicationRecord
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id ||= CurrentUser.user.id
|
||||
self.updater_ip_addr ||= CurrentUser.ip_addr
|
||||
self.updater_id = CurrentUser.user.id
|
||||
self.updater_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def creator_name
|
||||
|
||||
@@ -30,6 +30,12 @@ class Dmail < ApplicationRecord
|
||||
def creator_ip_addr_str
|
||||
creator_ip_addr.to_s
|
||||
end
|
||||
|
||||
def spam?(sender = CurrentUser.user)
|
||||
return false if Danbooru.config.rakismet_key.blank?
|
||||
return false if sender.is_gold?
|
||||
super()
|
||||
end
|
||||
end
|
||||
|
||||
module AddressMethods
|
||||
@@ -52,12 +58,7 @@ class Dmail < ApplicationRecord
|
||||
def initialize_attributes
|
||||
self.from_id ||= CurrentUser.id
|
||||
self.creator_ip_addr ||= CurrentUser.ip_addr
|
||||
if CurrentUser.is_gold?
|
||||
self.is_spam = false
|
||||
else
|
||||
self.is_spam = spam?
|
||||
end
|
||||
true
|
||||
self.is_spam = spam?(CurrentUser.user)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -173,11 +173,13 @@ class FavoriteGroup < ApplicationRecord
|
||||
end
|
||||
|
||||
def add!(post_id)
|
||||
post_id = post_id.id if post_id.is_a?(Post)
|
||||
return if contains?(post_id)
|
||||
with_lock do
|
||||
post_id = post_id.id if post_id.is_a?(Post)
|
||||
return if contains?(post_id)
|
||||
|
||||
clear_post_id_array
|
||||
update_attributes(:post_ids => add_number_to_string(post_id, post_ids))
|
||||
clear_post_id_array
|
||||
update_attributes(:post_ids => add_number_to_string(post_id, post_ids))
|
||||
end
|
||||
end
|
||||
|
||||
def self.purge_post(post_id)
|
||||
@@ -188,11 +190,13 @@ class FavoriteGroup < ApplicationRecord
|
||||
end
|
||||
|
||||
def remove!(post_id)
|
||||
post_id = post_id.id if post_id.is_a?(Post)
|
||||
return unless contains?(post_id)
|
||||
with_lock do
|
||||
post_id = post_id.id if post_id.is_a?(Post)
|
||||
return unless contains?(post_id)
|
||||
|
||||
clear_post_id_array
|
||||
update_attributes(:post_ids => remove_number_from_string(post_id, post_ids))
|
||||
clear_post_id_array
|
||||
update_attributes(:post_ids => remove_number_from_string(post_id, post_ids))
|
||||
end
|
||||
end
|
||||
|
||||
def add_number_to_string(number, string)
|
||||
|
||||
@@ -18,6 +18,10 @@ class Post < ApplicationRecord
|
||||
validates_uniqueness_of :md5, :on => :create
|
||||
validates_inclusion_of :rating, in: %w(s q e), message: "rating must be s, q, or e"
|
||||
validate :tag_names_are_valid
|
||||
validate :added_tags_are_valid
|
||||
validate :removed_tags_are_valid
|
||||
validate :has_artist_tag
|
||||
validate :has_copyright_tag
|
||||
validate :post_is_not_its_own_parent
|
||||
validate :updater_can_change_rating
|
||||
before_save :update_tag_post_counts
|
||||
@@ -196,6 +200,14 @@ class Post < ApplicationRecord
|
||||
"http://#{Danbooru.config.hostname}#{preview_file_url}"
|
||||
end
|
||||
|
||||
def open_graph_image_url
|
||||
if is_image? && has_large?
|
||||
"http://#{Danbooru.config.hostname}#{large_file_url}"
|
||||
else
|
||||
complete_preview_file_url
|
||||
end
|
||||
end
|
||||
|
||||
def file_url_for(user)
|
||||
if CurrentUser.mobile_mode?
|
||||
large_file_url
|
||||
@@ -592,6 +604,18 @@ class Post < ApplicationRecord
|
||||
@tag_array_was ||= Tag.scan_tags(tag_string_was)
|
||||
end
|
||||
|
||||
def tags
|
||||
Tag.where(name: tag_array)
|
||||
end
|
||||
|
||||
def tags_was
|
||||
Tag.where(name: tag_array_was)
|
||||
end
|
||||
|
||||
def added_tags
|
||||
tags - tags_was
|
||||
end
|
||||
|
||||
def decrement_tag_post_counts
|
||||
Tag.where(:name => tag_array).update_all("post_count = post_count - 1") if tag_array.any?
|
||||
end
|
||||
@@ -633,12 +657,18 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def merge_old_changes
|
||||
@removed_tags = []
|
||||
|
||||
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()
|
||||
old_tags = Tag.scan_tags(old_tag_string)
|
||||
|
||||
kept_tags = current_tags & new_tags
|
||||
@removed_tags = old_tags - kept_tags
|
||||
|
||||
set_tag_string(((current_tags + new_tags) - old_tags + (current_tags & new_tags)).uniq.sort.join(" "))
|
||||
end
|
||||
|
||||
@@ -687,10 +717,10 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def remove_negated_tags(tags)
|
||||
negated_tags, tags = tags.partition {|x| x =~ /\A-/i}
|
||||
negated_tags = negated_tags.map {|x| x[1..-1]}
|
||||
negated_tags = TagAlias.to_aliased(negated_tags)
|
||||
return tags - negated_tags
|
||||
@negated_tags, tags = tags.partition {|x| x =~ /\A-/i}
|
||||
@negated_tags = @negated_tags.map {|x| x[1..-1]}
|
||||
@negated_tags = TagAlias.to_aliased(@negated_tags)
|
||||
return tags - @negated_tags
|
||||
end
|
||||
|
||||
def add_automatic_tags(tags)
|
||||
@@ -1136,6 +1166,7 @@ class Post < ApplicationRecord
|
||||
|
||||
module CountMethods
|
||||
def fast_count(tags = "", options = {})
|
||||
tags = tags.to_s
|
||||
tags += " rating:s" if CurrentUser.safe_mode?
|
||||
tags += " -status:deleted" if CurrentUser.hide_deleted_posts? && tags !~ /(?:^|\s)(?:-)?status:.+/
|
||||
tags = Tag.normalize_query(tags)
|
||||
@@ -1368,18 +1399,15 @@ class Post < ApplicationRecord
|
||||
Post.transaction do
|
||||
flag!(reason, is_deletion: true)
|
||||
|
||||
self.is_deleted = true
|
||||
self.is_pending = false
|
||||
self.is_flagged = false
|
||||
self.is_banned = true if options[:ban] || has_tag?("banned_artist")
|
||||
update_columns(
|
||||
:is_deleted => is_deleted,
|
||||
:is_pending => is_pending,
|
||||
:is_flagged => is_flagged,
|
||||
:is_banned => is_banned
|
||||
)
|
||||
update({
|
||||
is_deleted: true,
|
||||
is_pending: false,
|
||||
is_flagged: false,
|
||||
is_banned: is_banned || options[:ban] || has_tag?("banned_artist")
|
||||
}, without_protection: true)
|
||||
|
||||
# XXX This must happen *after* the `is_deleted` flag is set to true (issue #3419).
|
||||
give_favorites_to_parent if options[:move_favorites]
|
||||
update_parent_on_save
|
||||
|
||||
unless options[:without_mod_action]
|
||||
ModAction.log("deleted post ##{id}, reason: #{reason}")
|
||||
@@ -1707,6 +1735,53 @@ class Post < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def added_tags_are_valid
|
||||
new_tags = added_tags.select { |t| t.post_count <= 1 }
|
||||
new_general_tags = new_tags.select { |t| t.category == Tag.categories.general }
|
||||
new_artist_tags = new_tags.select { |t| t.category == Tag.categories.artist }
|
||||
|
||||
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(", ")}"
|
||||
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?name=#{CGI::escape(tag.name)}]"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def removed_tags_are_valid
|
||||
attempted_removed_tags = @removed_tags + @negated_tags
|
||||
unremoved_tags = tag_array & attempted_removed_tags
|
||||
|
||||
if unremoved_tags.present?
|
||||
unremoved_tags_list = unremoved_tags.map { |t| "[[#{t}]]" }.to_sentence
|
||||
self.warnings[:base] << "#{unremoved_tags_list} could not be removed. Check for implications and try again"
|
||||
end
|
||||
end
|
||||
|
||||
def has_artist_tag
|
||||
return if !new_record?
|
||||
return if source !~ %r!\Ahttps?://!
|
||||
return if has_tag?("artist_request") || has_tag?("official_art")
|
||||
return if tags.any? { |t| t.category == Tag.categories.artist }
|
||||
|
||||
site = Sources::Site.new(source)
|
||||
self.warnings[:base] << "Artist tag is required. Create a new tag with [[artist:<artist_name>]]. Ask on the forum if you need naming help"
|
||||
rescue Sources::Site::NoStrategyError => e
|
||||
# unrecognized source; do nothing.
|
||||
end
|
||||
|
||||
def has_copyright_tag
|
||||
return if !new_record?
|
||||
return if has_tag?("copyright_request") || tags.any? { |t| t.category == Tag.categories.copyright }
|
||||
|
||||
self.warnings[:base] << "Copyright tag is required. Consider adding [[copyright request]] or [[original]]"
|
||||
end
|
||||
end
|
||||
|
||||
include FileMethods
|
||||
@@ -1737,11 +1812,22 @@ class Post < ApplicationRecord
|
||||
)
|
||||
has_bit_flags BOOLEAN_ATTRIBUTES
|
||||
|
||||
def safeblocked?
|
||||
CurrentUser.safe_mode? && (rating != "s" || has_tag?("toddlercon|toddler|diaper|tentacle|rape|bestiality|beastiality|lolita|loli|nude|shota|pussy|penis"))
|
||||
end
|
||||
|
||||
def levelblocked?
|
||||
!Danbooru.config.can_user_see_post?(CurrentUser.user, self)
|
||||
end
|
||||
|
||||
def banblocked?
|
||||
is_banned? && !CurrentUser.is_gold?
|
||||
end
|
||||
|
||||
def visible?
|
||||
return false if !Danbooru.config.can_user_see_post?(CurrentUser.user, self)
|
||||
return false if CurrentUser.safe_mode? && rating != "s"
|
||||
return false if CurrentUser.safe_mode? && has_tag?("toddlercon|toddler|diaper|tentacle|rape|bestiality|beastiality|lolita|loli|nude|shota|pussy|penis")
|
||||
return false if is_banned? && !CurrentUser.is_gold?
|
||||
return false if safeblocked?
|
||||
return false if levelblocked?
|
||||
return false if banblocked?
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ class Tag < ApplicationRecord
|
||||
attr_accessible :category, :as => [:moderator, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
|
||||
attr_accessible :is_locked, :as => [:moderator, :admin]
|
||||
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
|
||||
has_one :artist, :foreign_key => "name", :primary_key => "name"
|
||||
has_one :antecedent_alias, lambda {active}, :class_name => "TagAlias", :foreign_key => "antecedent_name", :primary_key => "name"
|
||||
has_many :consequent_aliases, lambda {active}, :class_name => "TagAlias", :foreign_key => "consequent_name", :primary_key => "name"
|
||||
has_many :antecedent_implications, lambda {active}, :class_name => "TagImplication", :foreign_key => "antecedent_name", :primary_key => "name"
|
||||
|
||||
@@ -21,7 +21,7 @@ class TagImplication < TagRelationship
|
||||
end
|
||||
|
||||
def automatic_tags_for(names)
|
||||
tags = names.grep(/\A(.+)_\(cosplay\)\Z/) { "char:#{$1}" }
|
||||
tags = names.grep(/\A(.+)_\(cosplay\)\Z/) { "char:#{TagAlias.to_aliased([$1]).first}" }
|
||||
tags << "cosplay" if tags.present?
|
||||
tags.uniq
|
||||
end
|
||||
|
||||
@@ -148,6 +148,8 @@ class Upload < ApplicationRecord
|
||||
else
|
||||
update_attribute(:status, "error: " + post.errors.full_messages.join(", "))
|
||||
end
|
||||
|
||||
post
|
||||
end
|
||||
|
||||
def process!(force = false)
|
||||
@@ -155,7 +157,7 @@ class Upload < ApplicationRecord
|
||||
return if !force && status =~ /processing|completed|error/
|
||||
|
||||
process_upload
|
||||
create_post_from_upload
|
||||
post = create_post_from_upload
|
||||
|
||||
rescue Timeout::Error, Net::HTTP::Persistent::Error => x
|
||||
if @tries > 3
|
||||
@@ -164,9 +166,11 @@ class Upload < ApplicationRecord
|
||||
@tries += 1
|
||||
retry
|
||||
end
|
||||
nil
|
||||
|
||||
rescue Exception => x
|
||||
update_attributes(:status => "error: #{x.class} - #{x.message}", :backtrace => x.backtrace.join("\n"))
|
||||
nil
|
||||
|
||||
ensure
|
||||
delete_temp_file
|
||||
|
||||
Reference in New Issue
Block a user