models: set more creator names explicitly.
Set creators explicitly for bans, BURs, comment votes, and posts.
This commit is contained in:
@@ -24,7 +24,7 @@ class BansController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@ban = Ban.create(ban_params(:create))
|
||||
@ban = Ban.create(banner: CurrentUser.user, **ban_params(:create))
|
||||
|
||||
if @ban.errors.any?
|
||||
render :action => "new"
|
||||
|
||||
@@ -59,7 +59,7 @@ class UsersController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new(user_params(:create))
|
||||
@user = User.new(last_ip_addr: CurrentUser.ip_addr, **user_params(:create))
|
||||
if !Danbooru.config.enable_recaptcha? || verify_recaptcha(model: @user)
|
||||
@user.save
|
||||
if @user.errors.empty?
|
||||
|
||||
@@ -8,7 +8,6 @@ class Ban < ApplicationRecord
|
||||
belongs_to :banner, :class_name => "User"
|
||||
validate :user_is_inferior
|
||||
validates_presence_of :reason, :duration
|
||||
before_validation :initialize_banner_id, :on => :create
|
||||
|
||||
scope :unexpired, -> { where("bans.expires_at > ?", Time.now) }
|
||||
scope :expired, -> { where("bans.expires_at <= ?", Time.now) }
|
||||
@@ -50,10 +49,6 @@ class Ban < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_banner_id
|
||||
self.banner_id = CurrentUser.id if self.banner_id.blank?
|
||||
end
|
||||
|
||||
def user_is_inferior
|
||||
if user
|
||||
if user.is_admin?
|
||||
|
||||
@@ -13,7 +13,6 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
validate :script_formatted_correctly
|
||||
validate :forum_topic_id_not_invalid
|
||||
validate :validate_script, :on => :create
|
||||
before_validation :initialize_attributes, :on => :create
|
||||
before_validation :normalize_text
|
||||
after_create :create_forum_topic
|
||||
after_save :update_notice
|
||||
@@ -173,11 +172,6 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
lines.join("\n")
|
||||
end
|
||||
|
||||
def initialize_attributes
|
||||
self.user_id = CurrentUser.user.id unless self.user_id
|
||||
self.status = "pending"
|
||||
end
|
||||
|
||||
def normalize_text
|
||||
self.script = script.downcase
|
||||
end
|
||||
|
||||
@@ -48,9 +48,9 @@ class Comment < ApplicationRecord
|
||||
end
|
||||
|
||||
module VoteMethods
|
||||
def vote!(val)
|
||||
def vote!(val, voter = CurrentUser.user)
|
||||
numerical_score = (val == "up") ? 1 : -1
|
||||
vote = votes.create!(:score => numerical_score)
|
||||
vote = votes.create!(user: voter, score: numerical_score)
|
||||
|
||||
if vote.is_positive?
|
||||
update_column(:score, score + 1)
|
||||
|
||||
@@ -3,7 +3,6 @@ class CommentVote < ApplicationRecord
|
||||
|
||||
belongs_to :comment
|
||||
belongs_to :user
|
||||
before_validation :initialize_user, :on => :create
|
||||
validates_presence_of :score
|
||||
validates_uniqueness_of :user_id, :scope => :comment_id, :message => "have already voted for this comment"
|
||||
validate :validate_user_can_vote
|
||||
@@ -52,10 +51,6 @@ class CommentVote < ApplicationRecord
|
||||
score == -1
|
||||
end
|
||||
|
||||
def initialize_user
|
||||
self.user_id = CurrentUser.user.id
|
||||
end
|
||||
|
||||
def self.available_includes
|
||||
[:comment, :user]
|
||||
end
|
||||
|
||||
@@ -10,7 +10,6 @@ class ForumPost < ApplicationRecord
|
||||
has_one :tag_implication
|
||||
has_one :bulk_update_request
|
||||
|
||||
before_validation :initialize_is_deleted, :on => :create
|
||||
before_save :update_dtext_links, if: :dtext_links_changed?
|
||||
before_create :autoreport_spam
|
||||
after_create :update_topic_updated_at_on_create
|
||||
@@ -183,10 +182,6 @@ class ForumPost < ApplicationRecord
|
||||
topic.response_count -= 1
|
||||
end
|
||||
|
||||
def initialize_is_deleted
|
||||
self.is_deleted = false if is_deleted.nil?
|
||||
end
|
||||
|
||||
def quoted_response
|
||||
DText.quote(body, creator.name)
|
||||
end
|
||||
|
||||
@@ -19,7 +19,6 @@ class ForumTopic < ApplicationRecord
|
||||
has_many :moderation_reports, through: :posts
|
||||
has_one :original_post, -> {order("forum_posts.id asc")}, class_name: "ForumPost", foreign_key: "topic_id", inverse_of: :topic
|
||||
|
||||
before_validation :initialize_is_deleted, :on => :create
|
||||
validates_presence_of :title
|
||||
validates_associated :original_post
|
||||
validates_inclusion_of :category_id, :in => CATEGORIES.keys
|
||||
@@ -151,10 +150,6 @@ class ForumTopic < ApplicationRecord
|
||||
ModAction.log("undeleted forum topic ##{id} (title: #{title})", :forum_topic_undelete)
|
||||
end
|
||||
|
||||
def initialize_is_deleted
|
||||
self.is_deleted = false if is_deleted.nil?
|
||||
end
|
||||
|
||||
def page_for(post_id)
|
||||
(posts.where("id < ?", post_id).count / Danbooru.config.posts_per_page.to_f).ceil
|
||||
end
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
class ModAction < ApplicationRecord
|
||||
belongs_to :creator, :class_name => "User"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
|
||||
api_attributes including: [:category_id]
|
||||
|
||||
@@ -75,12 +74,8 @@ class ModAction < ApplicationRecord
|
||||
self.class.categories[category]
|
||||
end
|
||||
|
||||
def self.log(desc, cat = :other)
|
||||
create(:description => desc, :category => categories[cat])
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
def self.log(desc, cat = :other, user = CurrentUser.user)
|
||||
create(creator: user, description: desc, category: categories[cat])
|
||||
end
|
||||
|
||||
def self.available_includes
|
||||
|
||||
@@ -9,7 +9,6 @@ class Post < ApplicationRecord
|
||||
# Tags to copy when copying notes.
|
||||
NOTE_COPY_TAGS = %w[translated partially_translated check_translation translation_request reverse_translation]
|
||||
|
||||
before_validation :initialize_uploader, :on => :create
|
||||
before_validation :merge_old_changes
|
||||
before_validation :normalize_tags
|
||||
before_validation :strip_source
|
||||
@@ -984,15 +983,6 @@ class Post < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
module UploaderMethods
|
||||
def initialize_uploader
|
||||
if uploader_id.blank?
|
||||
self.uploader_id = CurrentUser.id
|
||||
self.uploader_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module PoolMethods
|
||||
def pools
|
||||
Pool.where("pools.post_ids && array[?]", id)
|
||||
@@ -1691,7 +1681,6 @@ class Post < ApplicationRecord
|
||||
include PresenterMethods
|
||||
include TagMethods
|
||||
include FavoriteMethods
|
||||
include UploaderMethods
|
||||
include PoolMethods
|
||||
include VoteMethods
|
||||
extend CountMethods
|
||||
|
||||
@@ -729,7 +729,6 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def initialize_attributes
|
||||
self.last_ip_addr ||= CurrentUser.ip_addr
|
||||
self.enable_post_navigation = true
|
||||
self.new_post_navigation_layout = true
|
||||
self.enable_sequential_post_navigation = true
|
||||
|
||||
Reference in New Issue
Block a user