Merge branch 'danbooru:master' into master
This commit is contained in:
@@ -15,13 +15,14 @@ class ForumPost < ApplicationRecord
|
||||
has_one :bulk_update_request
|
||||
|
||||
validates :body, presence: true, length: { maximum: 200_000 }, if: :body_changed?
|
||||
validate :validate_deletion_of_original_post
|
||||
validate :validate_undeletion_of_post
|
||||
|
||||
before_create :autoreport_spam
|
||||
before_save :handle_reports_on_deletion
|
||||
after_create :update_topic_updated_at_on_create
|
||||
after_update :update_topic_updated_at_on_update_for_original_posts
|
||||
after_destroy :update_topic_updated_at_on_destroy
|
||||
after_save :delete_topic_if_original_post
|
||||
after_update(:if => ->(rec) {rec.updater_id != rec.creator_id}) do |rec|
|
||||
ModAction.log("#{CurrentUser.user.name} updated forum ##{rec.id}", :forum_post_update)
|
||||
end
|
||||
@@ -83,6 +84,18 @@ class ForumPost < ApplicationRecord
|
||||
votes.exists?(creator_id: user.id, score: score)
|
||||
end
|
||||
|
||||
def validate_deletion_of_original_post
|
||||
if is_original_post? && is_deleted? && !topic.is_deleted?
|
||||
errors.add(:base, "Can't delete original post without deleting the topic first")
|
||||
end
|
||||
end
|
||||
|
||||
def validate_undeletion_of_post
|
||||
if topic.is_deleted? && !is_deleted?
|
||||
errors.add(:base, "Can't undelete post without undeleting the topic first")
|
||||
end
|
||||
end
|
||||
|
||||
def autoreport_spam
|
||||
if SpamDetector.new(self, user_ip: CurrentUser.ip_addr).spam?
|
||||
moderation_reports << ModerationReport.new(creator: User.system, reason: "Spam.")
|
||||
@@ -153,12 +166,6 @@ class ForumPost < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def delete_topic_if_original_post
|
||||
if is_deleted? && is_original_post?
|
||||
topic.update_attribute(:is_deleted, true)
|
||||
end
|
||||
end
|
||||
|
||||
def handle_reports_on_deletion
|
||||
return unless moderation_reports.pending.present? && is_deleted_change == [false, true]
|
||||
|
||||
|
||||
@@ -24,12 +24,13 @@ class ForumTopic < ApplicationRecord
|
||||
has_many :tag_implications
|
||||
|
||||
validates :title, presence: true, length: { maximum: 200 }, if: :title_changed?
|
||||
validates_associated :original_post
|
||||
validates :category_id, inclusion: { in: CATEGORIES.keys }
|
||||
validates :min_level, inclusion: { in: MIN_LEVELS.values }
|
||||
|
||||
accepts_nested_attributes_for :original_post
|
||||
after_update :update_orignal_post
|
||||
|
||||
after_update :update_posts_on_deletion_or_undeletion
|
||||
after_update :update_original_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)
|
||||
end
|
||||
@@ -179,7 +180,14 @@ class ForumTopic < ApplicationRecord
|
||||
(response_count / Danbooru.config.posts_per_page.to_f).ceil
|
||||
end
|
||||
|
||||
def update_orignal_post
|
||||
# Delete all posts when the topic is deleted. Undelete all posts when the topic is undeleted.
|
||||
def update_posts_on_deletion_or_undeletion
|
||||
if saved_change_to_is_deleted?
|
||||
forum_posts.update!(is_deleted: is_deleted) # XXX depends on current user
|
||||
end
|
||||
end
|
||||
|
||||
def update_original_post
|
||||
original_post&.update_columns(:updater_id => updater.id, :updated_at => Time.now)
|
||||
end
|
||||
|
||||
|
||||
6
app/models/upload_media_asset.rb
Normal file
6
app/models/upload_media_asset.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class UploadMediaAsset < ApplicationRecord
|
||||
belongs_to :upload
|
||||
belongs_to :media_asset
|
||||
end
|
||||
Reference in New Issue
Block a user