Merge branch 'rails-5.1'
This commit is contained in:
@@ -4,8 +4,6 @@ require 'base64'
|
||||
require 'digest/md5'
|
||||
|
||||
class AmazonBackup < ApplicationRecord
|
||||
attr_accessible :last_id
|
||||
|
||||
def self.last_id
|
||||
first.last_id
|
||||
end
|
||||
|
||||
@@ -2,7 +2,6 @@ class ApiKey < ApplicationRecord
|
||||
belongs_to :user
|
||||
validates_uniqueness_of :user_id
|
||||
validates_uniqueness_of :key
|
||||
attr_accessible :user_id, :key
|
||||
|
||||
def self.generate!(user)
|
||||
create(:user_id => user.id, :key => SecureRandom.urlsafe_base64(32))
|
||||
|
||||
@@ -141,6 +141,41 @@ class ApplicationRecord < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
concerning :UserMethods do
|
||||
class_methods do
|
||||
def belongs_to_creator(options = {})
|
||||
class_eval do
|
||||
belongs_to :creator, options.merge(class_name: "User")
|
||||
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=)
|
||||
rec.ip_addr = CurrentUser.ip_addr if rec.respond_to?(:ip_addr=)
|
||||
end
|
||||
end
|
||||
|
||||
define_method :creator_name do
|
||||
User.id_to_name(creator_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def belongs_to_updater(options = {})
|
||||
class_eval do
|
||||
belongs_to :updater, options.merge(class_name: "User")
|
||||
before_validation do |rec|
|
||||
rec.updater_id = CurrentUser.id
|
||||
rec.updater_ip_addr = CurrentUser.ip_addr if rec.respond_to?(:updater_ip_addr=)
|
||||
end
|
||||
|
||||
define_method :updater_name do
|
||||
User.id_to_name(updater_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def warnings
|
||||
@warnings ||= ActiveModel::Errors.new(self)
|
||||
end
|
||||
|
||||
@@ -2,25 +2,25 @@ class Artist < ApplicationRecord
|
||||
extend Memoist
|
||||
class RevertError < Exception ; end
|
||||
|
||||
before_create :initialize_creator
|
||||
attribute :url_string, :string, default: ""
|
||||
before_validation :normalize_name
|
||||
after_save :create_version
|
||||
after_save :categorize_tag
|
||||
after_save :update_wiki
|
||||
after_save :save_urls
|
||||
validates_uniqueness_of :name
|
||||
validates_associated :urls
|
||||
validates :name, tag_name: true
|
||||
validate :validate_wiki, :on => :create
|
||||
after_validation :merge_validation_errors
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to_creator
|
||||
has_many :members, :class_name => "Artist", :foreign_key => "group_name", :primary_key => "name"
|
||||
has_many :urls, :dependent => :destroy, :class_name => "ArtistUrl"
|
||||
has_many :versions, lambda {order("artist_versions.id ASC")}, :class_name => "ArtistVersion"
|
||||
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
|
||||
has_one :tag_alias, :foreign_key => "antecedent_name", :primary_key => "name"
|
||||
has_one :tag, :foreign_key => "name", :primary_key => "name"
|
||||
attr_accessible :body, :notes, :name, :url_string, :other_names, :other_names_comma, :group_name, :notes, :as => [:member, :gold, :builder, :platinum, :moderator, :default, :admin]
|
||||
attr_accessible :is_active, :as => [:builder, :moderator, :default, :admin]
|
||||
attr_accessible :is_banned, :as => :admin
|
||||
attribute :notes, :string
|
||||
|
||||
scope :active, lambda { where(is_active: true) }
|
||||
scope :deleted, lambda { where(is_active: false) }
|
||||
@@ -178,22 +178,12 @@ class Artist < ApplicationRecord
|
||||
urls.map(&:url)
|
||||
end
|
||||
|
||||
def url_string=(string)
|
||||
@url_string_was = url_string
|
||||
|
||||
self.urls = string.scan(/[^[:space:]]+/).uniq.map do |url|
|
||||
self.urls.find_or_initialize_by(url: url)
|
||||
def save_urls
|
||||
self.urls = url_string.scan(/[^[:space:]]+/).uniq.map do |url|
|
||||
self.urls.find_or_create_by(url: url)
|
||||
end
|
||||
end
|
||||
|
||||
def url_string
|
||||
url_array.join("\n")
|
||||
end
|
||||
|
||||
def url_string_changed?
|
||||
@url_string_was != url_string
|
||||
end
|
||||
|
||||
def map_domain(x)
|
||||
case x
|
||||
when "pximg.net"
|
||||
@@ -258,7 +248,7 @@ class Artist < ApplicationRecord
|
||||
|
||||
module VersionMethods
|
||||
def create_version(force=false)
|
||||
if name_changed? || url_string_changed? || is_active_changed? || is_banned_changed? || other_names_changed? || group_name_changed? || notes_changed? || force
|
||||
if saved_change_to_name? || saved_change_to_url_string? || 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
|
||||
else
|
||||
@@ -271,7 +261,7 @@ class Artist < ApplicationRecord
|
||||
ArtistVersion.create(
|
||||
:artist_id => id,
|
||||
:name => name,
|
||||
:updater_id => CurrentUser.user.id,
|
||||
:updater_id => CurrentUser.id,
|
||||
:updater_ip_addr => CurrentUser.ip_addr,
|
||||
:url_string => url_string,
|
||||
:is_active => is_active,
|
||||
@@ -369,9 +359,9 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_wiki
|
||||
if persisted? && name_changed? && name_was.present? && WikiPage.titled(name_was).exists?
|
||||
if persisted? && saved_change_to_name? && attribute_before_last_save("name").present? && WikiPage.titled(attribute_before_last_save("name")).exists?
|
||||
# we're renaming the artist, so rename the corresponding wiki page
|
||||
old_page = WikiPage.titled(name_was).first
|
||||
old_page = WikiPage.titled(name_before_last_save).first
|
||||
|
||||
if wiki_page.present?
|
||||
# a wiki page with the new name already exists, so update the content
|
||||
@@ -383,7 +373,7 @@ class Artist < ApplicationRecord
|
||||
elsif wiki_page.nil?
|
||||
# if there are any notes, we need to create a new wiki page
|
||||
if @notes.present?
|
||||
create_wiki_page(body: @notes, title: name)
|
||||
wp = create_wiki_page(body: @notes, title: name)
|
||||
end
|
||||
elsif (!@notes.nil? && (wiki_page.body != @notes)) || wiki_page.title != name
|
||||
# if anything changed, we need to update the wiki page
|
||||
@@ -415,7 +405,7 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
|
||||
def categorize_tag
|
||||
if new_record? || name_changed?
|
||||
if new_record? || saved_change_to_name?
|
||||
Tag.find_or_create_by_name("artist:#{name}")
|
||||
end
|
||||
end
|
||||
@@ -666,10 +656,6 @@ class Artist < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.user.id
|
||||
end
|
||||
|
||||
def deletable_by?(user)
|
||||
user.is_builder?
|
||||
end
|
||||
|
||||
@@ -3,10 +3,9 @@ class ArtistCommentary < ApplicationRecord
|
||||
|
||||
attr_accessor :remove_commentary_tag, :remove_commentary_request_tag, :remove_commentary_check_tag
|
||||
attr_accessor :add_commentary_tag, :add_commentary_request_tag, :add_commentary_check_tag
|
||||
attr_accessible :post_id, :original_description, :original_title, :translated_description, :translated_title, :remove_commentary_tag, :remove_commentary_request_tag, :add_commentary_tag, :add_commentary_request_tag, :add_commentary_check_tag, :remove_commentary_check_tag
|
||||
before_validation :trim_whitespace
|
||||
validates_uniqueness_of :post_id
|
||||
belongs_to :post
|
||||
belongs_to :post, required: true
|
||||
has_many :versions, lambda {order("artist_commentary_versions.id ASC")}, :class_name => "ArtistCommentaryVersion", :dependent => :destroy, :foreign_key => :post_id, :primary_key => :post_id
|
||||
has_one :previous_version, lambda {order(id: :desc)}, :class_name => "ArtistCommentaryVersion", :foreign_key => :post_id, :primary_key => :post_id
|
||||
after_save :create_version
|
||||
@@ -109,12 +108,12 @@ class ArtistCommentary < ApplicationRecord
|
||||
post.add_tag("check_commentary")
|
||||
end
|
||||
|
||||
post.save if post.tag_string_changed?
|
||||
post.save if post.saved_change_to_tag_string?
|
||||
end
|
||||
|
||||
module VersionMethods
|
||||
def create_version
|
||||
return unless changed?
|
||||
return unless saved_changes?
|
||||
|
||||
if merge_version?
|
||||
merge_version
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
class ArtistCommentaryVersion < ApplicationRecord
|
||||
before_validation :initialize_updater
|
||||
belongs_to :post
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to_updater
|
||||
scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)}
|
||||
attr_accessible :post_id, :original_title, :original_description, :translated_title, :translated_description
|
||||
|
||||
def self.search(params)
|
||||
q = super
|
||||
@@ -18,13 +16,4 @@ class ArtistCommentaryVersion < ApplicationRecord
|
||||
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
self.updater_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def updater_name
|
||||
User.id_to_name(updater_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,6 @@ class ArtistUrl < ApplicationRecord
|
||||
validates_presence_of :url
|
||||
validate :validate_url_format
|
||||
belongs_to :artist, :touch => true
|
||||
attr_accessible :url, :artist_id, :normalized_url
|
||||
|
||||
def self.normalize(url)
|
||||
if url.nil?
|
||||
@@ -93,8 +92,8 @@ class ArtistUrl < ApplicationRecord
|
||||
|
||||
def validate_url_format
|
||||
uri = Addressable::URI.parse(url)
|
||||
errors[:base] << "'#{url}' must begin with http:// or https://" if !uri.scheme.in?(%w[http https])
|
||||
errors[:url] << "must begin with http:// or https://" if !uri.scheme.in?(%w[http https])
|
||||
rescue Addressable::URI::InvalidURIError => error
|
||||
errors[:base] << "'#{url}' is malformed: #{error}"
|
||||
errors[:url] << "is malformed: #{error}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class ArtistVersion < ApplicationRecord
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to_updater
|
||||
belongs_to :artist
|
||||
attr_accessible :artist_id, :name, :is_active, :other_names, :group_name, :url_string, :is_banned, :updater_id, :updater_ip_addr
|
||||
delegate :visible?, :to => :artist
|
||||
|
||||
module SearchMethods
|
||||
@@ -106,8 +105,4 @@ class ArtistVersion < ApplicationRecord
|
||||
def previous
|
||||
ArtistVersion.where("artist_id = ? and created_at < ?", artist_id, created_at).order("created_at desc").first
|
||||
end
|
||||
|
||||
def updater_name
|
||||
User.id_to_name(updater_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,7 +5,6 @@ class Ban < ApplicationRecord
|
||||
after_destroy :update_user_on_destroy
|
||||
belongs_to :user
|
||||
belongs_to :banner, :class_name => "User"
|
||||
attr_accessible :reason, :duration, :user_id, :user_name
|
||||
validate :user_is_inferior
|
||||
validates_presence_of :user_id, :reason, :duration
|
||||
before_validation :initialize_banner_id, :on => :create
|
||||
|
||||
@@ -2,9 +2,9 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
attr_accessor :reason, :skip_secondary_validations
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :forum_topic
|
||||
belongs_to :forum_post
|
||||
belongs_to :approver, :class_name => "User"
|
||||
belongs_to :forum_topic, optional: true
|
||||
belongs_to :forum_post, optional: true
|
||||
belongs_to :approver, optional: true, class_name: "User"
|
||||
|
||||
validates_presence_of :user
|
||||
validates_presence_of :script
|
||||
@@ -112,10 +112,12 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
def create_forum_topic
|
||||
if forum_topic_id
|
||||
forum_post = forum_topic.posts.create(body: reason_with_link)
|
||||
update_attributes(:forum_post_id => forum_post.id)
|
||||
update(forum_post_id: forum_post.id)
|
||||
else
|
||||
forum_topic = ForumTopic.create(:title => title, :category_id => 1, :original_post_attributes => {:body => reason_with_link})
|
||||
update_attributes(:forum_topic_id => forum_topic.id, :forum_post_id => forum_topic.posts.first.id)
|
||||
forum_topic = ForumTopic.create(title: title, category_id: 1, original_post_attributes: {body: reason_with_link})
|
||||
puts forum_topic.errors.full_messages
|
||||
puts forum_topic.original_post.errors.full_messages
|
||||
update(forum_topic_id: forum_topic.id, forum_post_id: forum_topic.posts.first.id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -136,13 +138,13 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
AliasAndImplicationImporter.tokenize(script)
|
||||
return true
|
||||
rescue StandardError => e
|
||||
errors.add(:base, e.message)
|
||||
errors[:base] << e.message
|
||||
return false
|
||||
end
|
||||
|
||||
def forum_topic_id_not_invalid
|
||||
if forum_topic_id && !forum_topic
|
||||
errors.add(:base, "Forum topic ID is invalid")
|
||||
errors[:base] << "Forum topic ID is invalid"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -150,7 +152,7 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
begin
|
||||
AliasAndImplicationImporter.new(script, forum_topic_id, "1", skip_secondary_validations).validate!
|
||||
rescue RuntimeError => e
|
||||
self.errors[:base] = e.message
|
||||
self.errors[:base] << e.message
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
@@ -5,21 +5,17 @@ class Comment < ApplicationRecord
|
||||
validate :validate_creator_is_not_limited, :on => :create
|
||||
validates_format_of :body, :with => /\S/, :message => 'has no content'
|
||||
belongs_to :post
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to_creator
|
||||
belongs_to_updater
|
||||
has_many :votes, :class_name => "CommentVote", :dependent => :destroy
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
after_create :update_last_commented_at_on_create
|
||||
after_update(:if => lambda {|rec| (!rec.is_deleted? || !rec.is_deleted_changed?) && CurrentUser.id != rec.creator_id}) do |rec|
|
||||
after_update(:if => lambda {|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)
|
||||
end
|
||||
after_save :update_last_commented_at_on_destroy, :if => lambda {|rec| rec.is_deleted? && rec.is_deleted_changed?}
|
||||
after_save(:if => lambda {|rec| rec.is_deleted? && rec.is_deleted_changed? && CurrentUser.id != rec.creator_id}) do |rec|
|
||||
after_save :update_last_commented_at_on_destroy, :if => lambda {|rec| rec.is_deleted? && rec.saved_change_to_is_deleted?}
|
||||
after_save(:if => lambda {|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)
|
||||
end
|
||||
attr_accessible :body, :post_id, :do_not_bump_post, :is_deleted, :as => [:member, :gold, :platinum, :builder, :moderator, :admin]
|
||||
attr_accessible :is_sticky, :as => [:moderator, :admin]
|
||||
mentionable(
|
||||
:message_field => :body,
|
||||
:title => lambda {|user_name| "#{creator_name} mentioned you in a comment on post ##{post_id}"},
|
||||
@@ -172,24 +168,6 @@ class Comment < ApplicationRecord
|
||||
extend SearchMethods
|
||||
include VoteMethods
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id ||= CurrentUser.user.id
|
||||
self.ip_addr ||= CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.user.id
|
||||
self.updater_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def creator_name
|
||||
User.id_to_name(creator_id)
|
||||
end
|
||||
|
||||
def updater_name
|
||||
User.id_to_name(updater_id)
|
||||
end
|
||||
|
||||
def validate_post_exists
|
||||
errors.add(:post, "must exist") unless Post.exists?(post_id)
|
||||
end
|
||||
@@ -245,11 +223,11 @@ class Comment < ApplicationRecord
|
||||
end
|
||||
|
||||
def delete!
|
||||
update({ :is_deleted => true }, :as => CurrentUser.role)
|
||||
update(is_deleted: true)
|
||||
end
|
||||
|
||||
def undelete!
|
||||
update({ :is_deleted => false }, :as => CurrentUser.role)
|
||||
update(is_deleted: false)
|
||||
end
|
||||
|
||||
def quoted_response
|
||||
|
||||
@@ -9,7 +9,6 @@ class CommentVote < ApplicationRecord
|
||||
validate :validate_user_can_vote
|
||||
validate :validate_comment_can_be_down_voted
|
||||
validates_inclusion_of :score, :in => [-1, 1], :message => "must be 1 or -1"
|
||||
attr_accessible :comment_id, :user_id, :score
|
||||
|
||||
def self.prune!
|
||||
where("created_at < ?", 14.days.ago).delete_all
|
||||
|
||||
@@ -235,7 +235,7 @@ class Dmail < ApplicationRecord
|
||||
|
||||
def validate_sender_is_not_banned
|
||||
if from.is_banned?
|
||||
errors[:base] = "Sender is banned and cannot send messages"
|
||||
errors[:base] << "Sender is banned and cannot send messages"
|
||||
return false
|
||||
else
|
||||
return true
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
class DmailFilter < ApplicationRecord
|
||||
belongs_to :user
|
||||
attr_accessible :words, :as => [:moderator, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
|
||||
validates_presence_of :user
|
||||
before_validation :initialize_user
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ class Favorite < ApplicationRecord
|
||||
belongs_to :post
|
||||
belongs_to :user
|
||||
scope :for_user, lambda {|user_id| where("user_id % 100 = #{user_id.to_i % 100} and user_id = #{user_id.to_i}")}
|
||||
attr_accessible :user_id, :post_id
|
||||
|
||||
def self.add(post:, user:)
|
||||
Favorite.transaction do
|
||||
@@ -26,7 +25,7 @@ class Favorite < ApplicationRecord
|
||||
User.where(:id => user.id).select("id").lock("FOR UPDATE NOWAIT").first
|
||||
|
||||
return unless Favorite.for_user(user.id).where(:user_id => user.id, :post_id => post_id).exists?
|
||||
Favorite.for_user(user.id).delete_all(post_id: post_id)
|
||||
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
|
||||
User.where(:id => user.id).update_all("favorite_count = favorite_count - 1")
|
||||
|
||||
@@ -3,15 +3,13 @@ require 'ostruct'
|
||||
class FavoriteGroup < ApplicationRecord
|
||||
validates_uniqueness_of :name, :case_sensitive => false, :scope => :creator_id
|
||||
validates_format_of :name, :with => /\A[^,]+\Z/, :message => "cannot have commas"
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to_creator
|
||||
before_validation :normalize_post_ids
|
||||
before_validation :normalize_name
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :strip_name
|
||||
validate :creator_can_create_favorite_groups, :on => :create
|
||||
validate :validate_number_of_posts
|
||||
before_save :update_post_count
|
||||
attr_accessible :name, :post_ids, :post_id_array, :is_public, :as => [:member, :gold, :platinum, :builder, :moderator, :admin, :default]
|
||||
|
||||
module SearchMethods
|
||||
def for_creator(user_id)
|
||||
@@ -125,10 +123,6 @@ class FavoriteGroup < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id ||= CurrentUser.id
|
||||
end
|
||||
|
||||
def strip_name
|
||||
self.name = name.to_s.strip
|
||||
end
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
class ForumPost < ApplicationRecord
|
||||
include Mentionable
|
||||
|
||||
attr_accessible :body, :topic_id, :as => [:member, :builder, :gold, :platinum, :admin, :moderator, :default]
|
||||
attr_accessible :is_locked, :is_sticky, :is_deleted, :as => [:admin, :moderator]
|
||||
attr_readonly :topic_id
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to_creator
|
||||
belongs_to_updater
|
||||
belongs_to :topic, :class_name => "ForumTopic"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
before_validation :initialize_is_deleted, :on => :create
|
||||
after_create :update_topic_updated_at_on_create
|
||||
after_update :update_topic_updated_at_on_update_for_original_posts
|
||||
@@ -137,22 +133,22 @@ class ForumPost < ApplicationRecord
|
||||
return if topic.nil?
|
||||
|
||||
if topic.is_locked?
|
||||
errors.add(:topic, "is locked")
|
||||
return false
|
||||
else
|
||||
return true
|
||||
errors[:topic] << "is locked"
|
||||
throw :abort
|
||||
end
|
||||
end
|
||||
|
||||
def topic_id_not_invalid
|
||||
if topic_id && !topic
|
||||
errors.add(:base, "Topic ID is invalid")
|
||||
errors[:base] << "Topic ID is invalid"
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def topic_is_not_restricted
|
||||
if topic && !topic.visible?(creator)
|
||||
errors.add(:topic, "restricted")
|
||||
errors[:topic] << "is restricted"
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
@@ -179,12 +175,12 @@ class ForumPost < ApplicationRecord
|
||||
end
|
||||
|
||||
def delete!
|
||||
update_attributes({:is_deleted => true}, :as => CurrentUser.role)
|
||||
update(is_deleted: true)
|
||||
update_topic_updated_at_on_delete
|
||||
end
|
||||
|
||||
def undelete!
|
||||
update_attributes({:is_deleted => false}, :as => CurrentUser.role)
|
||||
update(is_deleted: false)
|
||||
update_topic_updated_at_on_undelete
|
||||
end
|
||||
|
||||
@@ -212,14 +208,6 @@ class ForumPost < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def initialize_is_deleted
|
||||
self.is_deleted = false if is_deleted.nil?
|
||||
end
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class ForumSubscription < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :forum_topic
|
||||
attr_accessible :user, :forum_topic, :user_id, :forum_topic_id, :last_read_at, :delete_key
|
||||
|
||||
def self.prune!
|
||||
where("last_read_at < ?", 3.months.ago).delete_all
|
||||
|
||||
@@ -11,15 +11,11 @@ class ForumTopic < ApplicationRecord
|
||||
Admin: User::Levels::ADMIN,
|
||||
}
|
||||
|
||||
attr_accessible :title, :original_post_attributes, :category_id, :as => [:member, :builder, :gold, :platinum, :moderator, :admin, :default]
|
||||
attr_accessible :is_sticky, :is_locked, :is_deleted, :min_level, :as => [:admin, :moderator]
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to_creator
|
||||
belongs_to_updater
|
||||
has_many :posts, lambda {order("forum_posts.id asc")}, :class_name => "ForumPost", :foreign_key => "topic_id", :dependent => :destroy
|
||||
has_one :original_post, lambda {order("forum_posts.id asc")}, :class_name => "ForumPost", :foreign_key => "topic_id"
|
||||
has_one :original_post, lambda {order("forum_posts.id asc")}, class_name: "ForumPost", foreign_key: "topic_id", inverse_of: :topic
|
||||
has_many :subscriptions, :class_name => "ForumSubscription"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
before_validation :initialize_is_deleted, :on => :create
|
||||
validates_presence_of :title, :creator_id
|
||||
validates_associated :original_post
|
||||
@@ -28,7 +24,7 @@ class ForumTopic < ApplicationRecord
|
||||
validates :title, :length => {:maximum => 255}
|
||||
accepts_nested_attributes_for :original_post
|
||||
after_update :update_orignal_post
|
||||
after_save(:if => lambda {|rec| rec.is_locked? && rec.is_locked_changed?}) do |rec|
|
||||
after_save(:if => lambda {|rec| rec.is_locked? && rec.saved_change_to_is_locked?}) do |rec|
|
||||
ModAction.log("locked forum topic ##{id} (title: #{title})",:forum_topic_lock)
|
||||
end
|
||||
|
||||
@@ -173,14 +169,6 @@ class ForumTopic < ApplicationRecord
|
||||
self.is_deleted = false if is_deleted.nil?
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def page_for(post_id)
|
||||
(posts.where("id < ?", post_id).count / Danbooru.config.posts_per_page.to_f).ceil
|
||||
end
|
||||
@@ -216,11 +204,11 @@ class ForumTopic < ApplicationRecord
|
||||
end
|
||||
|
||||
def delete!
|
||||
update_attributes({:is_deleted => true}, :as => CurrentUser.role)
|
||||
update(is_deleted: true)
|
||||
end
|
||||
|
||||
def undelete!
|
||||
update_attributes({:is_deleted => false}, :as => CurrentUser.role)
|
||||
update(is_deleted: false)
|
||||
end
|
||||
|
||||
def update_orignal_post
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
class ForumTopicVisit < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :forum_topic
|
||||
attr_accessible :user_id, :user, :forum_topic_id, :forum_topic, :last_read_at
|
||||
|
||||
def self.prune!(user)
|
||||
where("user_id = ? and last_read_at < ?", user.id, user.last_forum_read_at).delete_all
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
class IpBan < ApplicationRecord
|
||||
IP_ADDR_REGEX = /\A(?:[0-9]{1,3}\.){3}[0-9]{1,3}\Z/
|
||||
belongs_to :creator, :class_name => "User"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
belongs_to_creator
|
||||
validates_presence_of :reason, :creator, :ip_addr
|
||||
validates_format_of :ip_addr, :with => IP_ADDR_REGEX
|
||||
validates_uniqueness_of :ip_addr, :if => lambda {|rec| rec.ip_addr =~ IP_ADDR_REGEX}
|
||||
attr_accessible :ip_addr, :reason
|
||||
after_create do |rec|
|
||||
ModAction.log("#{CurrentUser.name} created ip ban for #{rec.ip_addr}",:ip_ban_create)
|
||||
end
|
||||
@@ -44,8 +42,4 @@ class IpBan < ApplicationRecord
|
||||
def self.count_by_ip_addr(table, user_ids, user_id_field = "user_id", ip_addr_field = "ip_addr")
|
||||
select_all_sql("SELECT #{ip_addr_field}, count(*) FROM #{table} WHERE #{user_id_field} IN (?) GROUP BY #{ip_addr_field} ORDER BY count(*) DESC", user_ids).to_hash
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,8 +3,7 @@ class JanitorTrial < ApplicationRecord
|
||||
after_create :send_dmail
|
||||
after_create :promote_user
|
||||
validates_presence_of :user
|
||||
before_validation :initialize_creator
|
||||
attr_accessible :user_id, :user_name
|
||||
belongs_to_creator
|
||||
validates_inclusion_of :status, :in => %w(active inactive)
|
||||
before_validation :initialize_status
|
||||
validates_uniqueness_of :user_id
|
||||
@@ -57,10 +56,6 @@ class JanitorTrial < ApplicationRecord
|
||||
self.status = "active"
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def user_name
|
||||
user.try(:name)
|
||||
end
|
||||
|
||||
@@ -2,7 +2,6 @@ class ModAction < ApplicationRecord
|
||||
belongs_to :creator, :class_name => "User"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
validates_presence_of :creator_id
|
||||
attr_accessible :description, :category
|
||||
|
||||
#####DIVISIONS#####
|
||||
#Groups: 0-999
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
class NewsUpdate < ApplicationRecord
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to_creator
|
||||
belongs_to_updater
|
||||
scope :recent, lambda {where("created_at >= ?", 2.weeks.ago).order("created_at desc").limit(5)}
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
attr_accessible :message
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
class Note < ApplicationRecord
|
||||
class RevertError < Exception ; end
|
||||
|
||||
attr_accessor :updater_id, :updater_ip_addr, :html_id
|
||||
attribute :updater_id, :integer
|
||||
attribute :updater_ip_addr, :inet
|
||||
attr_accessor :html_id
|
||||
belongs_to :post
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to_creator
|
||||
belongs_to_updater
|
||||
has_many :versions, lambda {order("note_versions.id ASC")}, :class_name => "NoteVersion", :dependent => :destroy
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
validates_presence_of :post_id, :creator_id, :updater_id, :x, :y, :width, :height, :body
|
||||
validate :post_must_exist
|
||||
validate :note_within_image
|
||||
after_save :update_post
|
||||
after_save :create_version
|
||||
validate :post_must_not_be_note_locked
|
||||
attr_accessible :x, :y, :width, :height, :body, :updater_id, :updater_ip_addr, :is_active, :post_id, :post, :html_id
|
||||
|
||||
module SearchMethods
|
||||
def active
|
||||
@@ -87,15 +86,6 @@ class Note < ApplicationRecord
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id ||= CurrentUser.id
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
self.updater_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def post_must_exist
|
||||
if !Post.exists?(post_id)
|
||||
errors.add :post, "must exist"
|
||||
@@ -122,10 +112,6 @@ class Note < ApplicationRecord
|
||||
Post.exists?(["id = ? AND is_note_locked = ?", post_id, true])
|
||||
end
|
||||
|
||||
def creator_name
|
||||
User.id_to_name(creator_id)
|
||||
end
|
||||
|
||||
def rescale!(x_scale, y_scale)
|
||||
self.x *= x_scale
|
||||
self.y *= y_scale
|
||||
@@ -135,7 +121,7 @@ class Note < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_post
|
||||
if self.changed?
|
||||
if self.saved_changes?
|
||||
if Note.where(:is_active => true, :post_id => post_id).exists?
|
||||
execute_sql("UPDATE posts SET last_noted_at = ? WHERE id = ?", updated_at, post_id)
|
||||
else
|
||||
@@ -145,7 +131,7 @@ class Note < ApplicationRecord
|
||||
end
|
||||
|
||||
def create_version
|
||||
return unless versioned_attributes_changed?
|
||||
return unless saved_change_to_versioned_attributes?
|
||||
|
||||
if merge_version?
|
||||
merge_version
|
||||
@@ -156,8 +142,8 @@ class Note < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def versioned_attributes_changed?
|
||||
new_record? || x_changed? || y_changed? || width_changed? || height_changed? || is_active_changed? || body_changed?
|
||||
def saved_change_to_versioned_attributes?
|
||||
new_record? || saved_change_to_x? || saved_change_to_y? || saved_change_to_width? || saved_change_to_height? || saved_change_to_is_active? || saved_change_to_body?
|
||||
end
|
||||
|
||||
def create_new_version
|
||||
@@ -189,7 +175,7 @@ class Note < ApplicationRecord
|
||||
|
||||
def merge_version?
|
||||
prev = versions.last
|
||||
prev && prev.updater_id == CurrentUser.user.id && prev.updated_at > 1.hour.ago && !is_active_changed?
|
||||
prev && prev.updater_id == CurrentUser.user.id && prev.updated_at > 1.hour.ago && !saved_change_to_is_active?
|
||||
end
|
||||
|
||||
def revert_to(version)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
class NoteVersion < ApplicationRecord
|
||||
before_validation :initialize_updater
|
||||
belongs_to :updater, :class_name => "User", :counter_cache => "note_update_count"
|
||||
belongs_to_updater :counter_cache => "note_update_count"
|
||||
scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)}
|
||||
attr_accessible :note_id, :x, :y, :width, :height, :body, :updater_id, :updater_ip_addr, :is_active, :post_id, :html_id, :version
|
||||
|
||||
def self.search(params)
|
||||
q = super
|
||||
@@ -22,16 +20,7 @@ class NoteVersion < ApplicationRecord
|
||||
q.apply_default_order(params)
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
self.updater_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def previous
|
||||
NoteVersion.where("note_id = ? and updated_at < ?", note_id, updated_at).order("updated_at desc").first
|
||||
end
|
||||
|
||||
def updater_name
|
||||
User.id_to_name(updater_id)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
class PixivUgoiraFrameData < ApplicationRecord
|
||||
attr_accessible :post_id, :data, :content_type
|
||||
serialize :data
|
||||
end
|
||||
|
||||
@@ -3,24 +3,22 @@ require 'ostruct'
|
||||
class Pool < ApplicationRecord
|
||||
class RevertError < Exception ; end
|
||||
|
||||
validates_uniqueness_of :name, :case_sensitive => false, :if => :name_changed?
|
||||
validate :validate_name, :if => :name_changed?
|
||||
attribute :updater_id, :integer
|
||||
validates_uniqueness_of :name, :case_sensitive => false, :if => :saved_change_to_name?
|
||||
validate :validate_name, :if => :saved_change_to_name?
|
||||
validates_inclusion_of :category, :in => %w(series collection)
|
||||
validate :updater_can_change_category
|
||||
validate :updater_can_remove_posts
|
||||
validate :updater_can_edit_deleted
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to_creator
|
||||
belongs_to_updater
|
||||
before_validation :normalize_post_ids
|
||||
before_validation :normalize_name
|
||||
before_validation :initialize_is_active, :on => :create
|
||||
before_validation :initialize_creator, :on => :create
|
||||
after_save :update_category_pseudo_tags_for_posts_async
|
||||
after_save :create_version
|
||||
after_create :synchronize!
|
||||
before_destroy :create_mod_action_for_destroy
|
||||
attr_accessible :name, :description, :post_ids, :post_id_array, :post_count, :is_active, :category, :as => [:member, :gold, :platinum, :moderator, :admin, :default]
|
||||
attr_accessible :is_deleted, :as => [:builder, :moderator, :admin]
|
||||
|
||||
module SearchMethods
|
||||
def deleted
|
||||
@@ -163,10 +161,6 @@ class Pool < ApplicationRecord
|
||||
self.is_active = true if is_active.nil?
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def normalize_name
|
||||
self.name = Pool.normalize_name(name)
|
||||
end
|
||||
@@ -195,7 +189,6 @@ class Pool < ApplicationRecord
|
||||
self.post_ids = version.post_ids.join(" ")
|
||||
self.name = version.name
|
||||
self.description = version.description
|
||||
|
||||
synchronize!
|
||||
end
|
||||
|
||||
@@ -244,6 +237,7 @@ class Pool < ApplicationRecord
|
||||
return unless CurrentUser.user.can_remove_from_pools?
|
||||
|
||||
with_lock do
|
||||
reload
|
||||
update_attributes(:post_ids => remove_number_from_string(post.id, post_ids), :post_count => post_count - 1)
|
||||
post.remove_pool!(self)
|
||||
clear_post_id_array
|
||||
@@ -296,7 +290,7 @@ class Pool < ApplicationRecord
|
||||
|
||||
def synchronize!
|
||||
synchronize
|
||||
save if post_ids_changed?
|
||||
save if will_save_change_to_post_ids?
|
||||
end
|
||||
|
||||
def post_id_array
|
||||
@@ -306,15 +300,18 @@ class Pool < ApplicationRecord
|
||||
def post_id_array=(array)
|
||||
self.post_ids = array.join(" ")
|
||||
clear_post_id_array
|
||||
self
|
||||
end
|
||||
|
||||
def post_id_array_was
|
||||
@post_id_array_was ||= post_ids_was.scan(/\d+/).map(&:to_i)
|
||||
old_post_ids = post_ids_before_last_save || post_ids_was
|
||||
@post_id_array_was ||= old_post_ids.to_s.scan(/\d+/).map(&:to_i)
|
||||
end
|
||||
|
||||
def clear_post_id_array
|
||||
@post_id_array = nil
|
||||
@post_id_array_was = nil
|
||||
self
|
||||
end
|
||||
|
||||
def neighbors(post)
|
||||
@@ -353,6 +350,7 @@ class Pool < ApplicationRecord
|
||||
super
|
||||
@neighbor_posts = nil
|
||||
clear_post_id_array
|
||||
self
|
||||
end
|
||||
|
||||
def method_attributes
|
||||
@@ -360,7 +358,7 @@ class Pool < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_category_pseudo_tags_for_posts_async
|
||||
if category_changed?
|
||||
if saved_change_to_category?
|
||||
delay(:queue => "default").update_category_pseudo_tags_for_posts
|
||||
end
|
||||
end
|
||||
@@ -378,7 +376,7 @@ class Pool < ApplicationRecord
|
||||
end
|
||||
|
||||
def updater_can_change_category
|
||||
if category_changed? && !category_changeable_by?(CurrentUser.user)
|
||||
if saved_change_to_category? && !category_changeable_by?(CurrentUser.user)
|
||||
errors[:base] << "You cannot change the category of pools with greater than 100 posts"
|
||||
false
|
||||
else
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
class PoolVersion < ApplicationRecord
|
||||
class Error < Exception ; end
|
||||
|
||||
validates_presence_of :updater_id, :updater_ip_addr
|
||||
belongs_to :pool
|
||||
belongs_to :updater, :class_name => "User"
|
||||
before_validation :initialize_updater
|
||||
attr_accessible :pool_id, :is_deleted, :name, :description, :post_ids, :post_id_array, :post_count, :is_active, :category, :updater_id, :updater_ip_addr
|
||||
belongs_to_updater
|
||||
|
||||
module SearchMethods
|
||||
def for_user(user_id)
|
||||
@@ -73,19 +70,10 @@ class PoolVersion < ApplicationRecord
|
||||
puts "last version id: #{last_version_id}"
|
||||
end
|
||||
|
||||
def updater_name
|
||||
User.id_to_name(updater_id)
|
||||
end
|
||||
|
||||
def pretty_name
|
||||
name.tr("_", " ")
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
self.updater_id = CurrentUser.id
|
||||
self.updater_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def post_id_array
|
||||
@post_id_array ||= post_ids.scan(/\d+/).map(&:to_i)
|
||||
end
|
||||
|
||||
@@ -41,10 +41,10 @@ class Post < ApplicationRecord
|
||||
after_commit :update_iqdb_async, :on => :create
|
||||
after_commit :notify_pubsub
|
||||
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to :approver, :class_name => "User"
|
||||
belongs_to :updater, :class_name => "User", optional: true # this is handled in versions
|
||||
belongs_to :approver, class_name: "User", optional: true
|
||||
belongs_to :uploader, :class_name => "User", :counter_cache => "post_upload_count"
|
||||
belongs_to :parent, :class_name => "Post"
|
||||
belongs_to :parent, class_name: "Post", optional: true
|
||||
has_one :upload, :dependent => :destroy
|
||||
has_one :artist_commentary, :dependent => :destroy
|
||||
has_one :pixiv_ugoira_frame_data, :class_name => "PixivUgoiraFrameData", :dependent => :destroy
|
||||
@@ -60,14 +60,6 @@ class Post < ApplicationRecord
|
||||
has_many :replacements, class_name: "PostReplacement", :dependent => :destroy
|
||||
|
||||
serialize :keeper_data, JSON
|
||||
|
||||
if PostArchive.enabled?
|
||||
has_many :versions, lambda {order("post_versions.updated_at ASC")}, :class_name => "PostArchive", :dependent => :destroy
|
||||
end
|
||||
|
||||
attr_accessible :source, :rating, :tag_string, :old_tag_string, :old_parent_id, :old_source, :old_rating, :parent_id, :has_embedded_notes, :as => [:member, :builder, :gold, :platinum, :moderator, :admin, :default]
|
||||
attr_accessible :is_rating_locked, :is_note_locked, :has_cropped, :keeper_data, :as => [:builder, :moderator, :admin]
|
||||
attr_accessible :is_status_locked, :keeper_data, :as => [:admin]
|
||||
attr_accessor :old_tag_string, :old_parent_id, :old_source, :old_rating, :has_constraints, :disable_versioning, :view_count
|
||||
|
||||
concerning :KeeperMethods do
|
||||
@@ -82,7 +74,7 @@ class Post < ApplicationRecord
|
||||
uploader_id
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def keeper
|
||||
User.find(keeper_id)
|
||||
end
|
||||
@@ -92,6 +84,12 @@ class Post < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
if PostArchive.enabled?
|
||||
has_many :versions, lambda {order("post_versions.updated_at ASC")}, :class_name => "PostArchive", :dependent => :destroy
|
||||
end
|
||||
|
||||
attr_accessor :old_tag_string, :old_parent_id, :old_source, :old_rating, :has_constraints, :disable_versioning, :view_count
|
||||
|
||||
module FileMethods
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
@@ -521,7 +519,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def tag_array_was
|
||||
@tag_array_was ||= Tag.scan_tags(tag_string_was)
|
||||
@tag_array_was ||= Tag.scan_tags(tag_string_before_last_save || tag_string_was)
|
||||
end
|
||||
|
||||
def tags
|
||||
@@ -606,15 +604,15 @@ class Post < ApplicationRecord
|
||||
old_parent_id = old_parent_id.to_i
|
||||
end
|
||||
if old_parent_id == parent_id
|
||||
self.parent_id = parent_id_was
|
||||
self.parent_id = parent_id_before_last_save || parent_id_was
|
||||
end
|
||||
|
||||
if old_source == source.to_s
|
||||
self.source = source_was
|
||||
self.source = source_before_last_save || source_was
|
||||
end
|
||||
|
||||
if old_rating == rating
|
||||
self.rating = rating_was
|
||||
self.rating = rating_before_last_save || rating_was
|
||||
end
|
||||
end
|
||||
|
||||
@@ -838,13 +836,13 @@ class Post < ApplicationRecord
|
||||
self.rating = $1
|
||||
|
||||
when /^(-?)locked:notes?$/i
|
||||
assign_attributes({ is_note_locked: $1 != "-" }, as: CurrentUser.role)
|
||||
self.is_note_locked = ($1 != "-" ) if CurrentUser.is_builder?
|
||||
|
||||
when /^(-?)locked:rating$/i
|
||||
assign_attributes({ is_rating_locked: $1 != "-" }, as: CurrentUser.role)
|
||||
self.is_rating_locked = ($1 != "-" ) if CurrentUser.is_builder?
|
||||
|
||||
when /^(-?)locked:status$/i
|
||||
assign_attributes({ is_status_locked: $1 != "-" }, as: CurrentUser.role)
|
||||
self.is_status_locked = ($1 != "-" ) if CurrentUser.is_admin?
|
||||
|
||||
end
|
||||
end
|
||||
@@ -977,7 +975,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def remove_from_favorites
|
||||
Favorite.delete_all(post_id: id)
|
||||
Favorite.where(post_id: id).delete_all
|
||||
user_ids = fav_string.scan(/\d+/)
|
||||
User.where(:id => user_ids).update_all("favorite_count = favorite_count - 1")
|
||||
PostVote.where(post_id: id).delete_all
|
||||
@@ -1175,7 +1173,7 @@ class Post < ApplicationRecord
|
||||
|
||||
def fix_post_counts(post)
|
||||
post.set_tag_counts(false)
|
||||
if post.changed?
|
||||
if post.changes_saved?
|
||||
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
|
||||
@@ -1220,7 +1218,7 @@ class Post < ApplicationRecord
|
||||
# - Reparent all children to the first child.
|
||||
|
||||
def update_has_children_flag
|
||||
update({has_children: children.exists?, has_active_children: children.undeleted.exists?}, without_protection: true)
|
||||
update(has_children: children.exists?, has_active_children: children.undeleted.exists?)
|
||||
end
|
||||
|
||||
def blank_out_nonexistent_parents
|
||||
@@ -1252,10 +1250,10 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_parent_on_save
|
||||
return unless parent_id_changed? || is_deleted_changed?
|
||||
return unless saved_change_to_parent_id? || saved_change_to_is_deleted?
|
||||
|
||||
parent.update_has_children_flag if parent.present?
|
||||
Post.find(parent_id_was).update_has_children_flag if parent_id_was.present?
|
||||
Post.find(parent_id_before_last_save).update_has_children_flag if parent_id_before_last_save.present?
|
||||
end
|
||||
|
||||
def give_favorites_to_parent(options = {})
|
||||
@@ -1337,12 +1335,12 @@ class Post < ApplicationRecord
|
||||
Post.transaction do
|
||||
flag!(reason, is_deletion: true)
|
||||
|
||||
update({
|
||||
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(options) if options[:move_favorites]
|
||||
@@ -1385,11 +1383,15 @@ class Post < ApplicationRecord
|
||||
|
||||
module VersionMethods
|
||||
def create_version(force = false)
|
||||
if new_record? || rating_changed? || source_changed? || parent_id_changed? || tag_string_changed? || force
|
||||
if new_record? || saved_change_to_watched_attributes? || force
|
||||
create_new_version
|
||||
end
|
||||
end
|
||||
|
||||
def saved_change_to_watched_attributes?
|
||||
saved_change_to_rating? || saved_change_to_source? || saved_change_to_parent_id? || saved_change_to_tag_string?
|
||||
end
|
||||
|
||||
def merge_version?
|
||||
prev = versions.last
|
||||
prev && prev.updater_id == CurrentUser.user.id && prev.updated_at > 1.hour.ago
|
||||
|
||||
@@ -8,7 +8,6 @@ class PostAppeal < ApplicationRecord
|
||||
validate :validate_creator_is_not_limited
|
||||
before_validation :initialize_creator, :on => :create
|
||||
validates_uniqueness_of :creator_id, :scope => :post_id, :message => "have already appealed this post"
|
||||
attr_accessible :post_id, :post, :reason
|
||||
|
||||
module SearchMethods
|
||||
def reason_matches(query)
|
||||
|
||||
@@ -31,6 +31,6 @@ class PostApproval < ApplicationRecord
|
||||
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 }, without_protection: true)
|
||||
post.update(approver: user, is_flagged: false, is_pending: false, is_deleted: false)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
class PostDisapproval < ApplicationRecord
|
||||
DELETION_THRESHOLD = 1.month
|
||||
|
||||
belongs_to :post
|
||||
belongs_to :post, required: true
|
||||
belongs_to :user
|
||||
after_initialize :initialize_attributes, if: :new_record?
|
||||
validates_uniqueness_of :post_id, :scope => [:user_id], :message => "have already hidden this post"
|
||||
attr_accessible :post_id, :post, :user_id, :user, :reason, :message
|
||||
validates_inclusion_of :reason, :in => %w(legacy breaks_rules poor_quality disinterest)
|
||||
|
||||
scope :with_message, lambda {where("message is not null and message <> ''")}
|
||||
@@ -12,6 +12,14 @@ class PostDisapproval < ApplicationRecord
|
||||
scope :poor_quality, lambda {where(:reason => "poor_quality")}
|
||||
scope :disinterest, lambda {where(:reason => ["disinterest", "legacy"])}
|
||||
|
||||
def initialize_attributes
|
||||
self.user_id ||= CurrentUser.user.id
|
||||
end
|
||||
|
||||
def initialize_attributes
|
||||
self.user_id ||= CurrentUser.user.id
|
||||
end
|
||||
|
||||
def self.prune!
|
||||
PostDisapproval.where("post_id in (select _.post_id from post_disapprovals _ where _.created_at < ?)", DELETION_THRESHOLD.ago).delete_all
|
||||
end
|
||||
|
||||
@@ -17,7 +17,6 @@ class PostFlag < ApplicationRecord
|
||||
before_validation :initialize_creator, :on => :create
|
||||
validates_uniqueness_of :creator_id, :scope => :post_id, :on => :create, :unless => :is_deletion, :message => "have already flagged this post"
|
||||
before_save :update_post
|
||||
attr_accessible :post, :post_id, :reason, :is_resolved, :is_deletion
|
||||
attr_accessor :is_deletion
|
||||
|
||||
scope :by_users, lambda { where.not(creator: User.system) }
|
||||
|
||||
@@ -70,7 +70,11 @@ class PostReplacement < ApplicationRecord
|
||||
update_ugoira_frame_data(upload)
|
||||
|
||||
if md5_changed
|
||||
post.comments.create!({creator: User.system, body: comment_replacement_message, do_not_bump_post: true}, without_protection: true)
|
||||
CurrentUser.as(User.system) do
|
||||
post.comments.create!(body: comment_replacement_message, do_not_bump_post: true)
|
||||
end
|
||||
else
|
||||
post.queue_backup
|
||||
end
|
||||
|
||||
save!
|
||||
|
||||
@@ -2,7 +2,6 @@ class PostVersion < ApplicationRecord
|
||||
belongs_to :post
|
||||
belongs_to :updater, :class_name => "User"
|
||||
before_validation :initialize_updater
|
||||
attr_accessible :post_id, :is_status_locked, :is_rating_locked, :is_note_locked, :source, :rating, :tag_string, :old_tag_string, :old_parent_id, :old_source, :old_rating, :last_noted_at, :parent_id, :tags
|
||||
|
||||
module SearchMethods
|
||||
def for_user(user_id)
|
||||
|
||||
@@ -4,7 +4,6 @@ class PostVote < ApplicationRecord
|
||||
belongs_to :post
|
||||
belongs_to :user
|
||||
attr_accessor :vote
|
||||
attr_accessible :post, :post_id, :user, :user_id, :score, :vote
|
||||
|
||||
after_initialize :initialize_attributes, if: :new_record?
|
||||
validates_presence_of :post_id, :user_id, :score
|
||||
|
||||
@@ -43,10 +43,10 @@ class SavedSearch < ApplicationRecord
|
||||
|
||||
include ListbooruMethods
|
||||
|
||||
attr_accessor :disable_labels
|
||||
belongs_to :user
|
||||
validates :query, :presence => true
|
||||
validate :validate_count
|
||||
attr_accessible :query, :label_string
|
||||
before_create :update_user_on_create
|
||||
after_destroy :update_user_on_destroy
|
||||
after_save {|rec| Cache.delete(SavedSearch.cache_key(rec.user_id))}
|
||||
@@ -128,4 +128,12 @@ class SavedSearch < ApplicationRecord
|
||||
labels = labels.map { |label| SavedSearch.normalize_label(label) }
|
||||
super(labels)
|
||||
end
|
||||
|
||||
def disable_labels=(value)
|
||||
CurrentUser.update(disable_categorized_saved_searches: true) if value == "1"
|
||||
end
|
||||
|
||||
def disable_labels=(value)
|
||||
CurrentUser.update(disable_categorized_saved_searches: true) if value == "1"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,8 +3,6 @@ class Tag < ApplicationRecord
|
||||
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype|flagger|-flagger|appealer|-appealer|" +
|
||||
TagCategory.short_name_list.map {|x| "#{x}tags"}.join("|")
|
||||
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm|flagger|-flagger|appealer|-appealer"
|
||||
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"
|
||||
@@ -15,7 +13,7 @@ class Tag < ApplicationRecord
|
||||
validates :name, uniqueness: true, tag_name: true, on: :create
|
||||
validates_inclusion_of :category, in: TagCategory.category_ids
|
||||
|
||||
after_save :update_category_cache_for_all, if: :category_changed?
|
||||
after_save :update_category_cache_for_all, if: lambda {|rec| rec.saved_change_to_attribute?(:category)}
|
||||
|
||||
module ApiMethods
|
||||
def to_legacy_json
|
||||
|
||||
@@ -8,12 +8,6 @@ class TagAlias < TagRelationship
|
||||
validate :antecedent_and_consequent_are_different
|
||||
validate :consequent_has_wiki_page, :on => :create
|
||||
validate :mininum_antecedent_count, :on => :create
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :approver, :class_name => "User"
|
||||
belongs_to :forum_topic
|
||||
belongs_to :forum_post
|
||||
attr_accessible :antecedent_name, :consequent_name, :forum_topic_id, :skip_secondary_validations
|
||||
attr_accessible :status, :approver_id, :as => [:admin]
|
||||
|
||||
module CacheMethods
|
||||
extend ActiveSupport::Concern
|
||||
@@ -38,7 +32,7 @@ class TagAlias < TagRelationship
|
||||
module ApprovalMethods
|
||||
def approve!(update_topic: true, approver: CurrentUser.user)
|
||||
CurrentUser.scoped(approver) do
|
||||
update({ :status => "queued", :approver_id => approver.id }, :as => CurrentUser.role)
|
||||
update(status: "queued", approver_id: approver.id)
|
||||
delay(:queue => "default").process!(update_topic: update_topic)
|
||||
end
|
||||
end
|
||||
@@ -80,7 +74,7 @@ class TagAlias < TagRelationship
|
||||
|
||||
begin
|
||||
CurrentUser.scoped(approver) do
|
||||
update({ :status => "processing" }, :as => CurrentUser.role)
|
||||
update(status: "processing")
|
||||
move_aliases_and_implications
|
||||
move_saved_searches
|
||||
clear_all_cache
|
||||
@@ -88,7 +82,7 @@ class TagAlias < TagRelationship
|
||||
update_posts
|
||||
forum_updater.update(approval_message(approver), "APPROVED") if update_topic
|
||||
rename_wiki_and_artist
|
||||
update({ :status => "active", :post_count => consequent_tag.post_count }, :as => CurrentUser.role)
|
||||
update(status: "active", post_count: consequent_tag.post_count)
|
||||
end
|
||||
rescue Exception => e
|
||||
if tries < 5
|
||||
@@ -99,7 +93,7 @@ class TagAlias < TagRelationship
|
||||
|
||||
CurrentUser.scoped(approver) do
|
||||
forum_updater.update(failure_message(e), "FAILED") if update_topic
|
||||
update({ :status => "error: #{e}" }, :as => CurrentUser.role)
|
||||
update(status: "error: #{e}")
|
||||
end
|
||||
|
||||
if Rails.env.production?
|
||||
@@ -220,7 +214,7 @@ class TagAlias < TagRelationship
|
||||
end
|
||||
|
||||
def reject!
|
||||
update({ :status => "deleted" }, :as => CurrentUser.role)
|
||||
update(status: "deleted")
|
||||
clear_all_cache
|
||||
forum_updater.update(reject_message(CurrentUser.user), "REJECTED")
|
||||
destroy
|
||||
@@ -230,7 +224,7 @@ class TagAlias < TagRelationship
|
||||
return if skip_secondary_validations
|
||||
|
||||
unless WikiPage.titled(consequent_name).exists?
|
||||
self.errors[:base] = "The #{consequent_name} tag needs a corresponding wiki page"
|
||||
self.errors[:base] << "The #{consequent_name} tag needs a corresponding wiki page"
|
||||
return false
|
||||
end
|
||||
end
|
||||
@@ -239,7 +233,7 @@ class TagAlias < TagRelationship
|
||||
return if skip_secondary_validations
|
||||
|
||||
unless Post.fast_count(antecedent_name) >= 50
|
||||
self.errors[:base] = "The #{antecedent_name} tag must have at least 50 posts for an alias to be created"
|
||||
self.errors[:base] << "The #{antecedent_name} tag must have at least 50 posts for an alias to be created"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -252,11 +246,11 @@ class TagAlias < TagRelationship
|
||||
def create_mod_action
|
||||
alias_desc = %Q("tag alias ##{id}":[#{Rails.application.routes.url_helpers.tag_alias_path(self)}]: [[#{antecedent_name}]] -> [[#{consequent_name}]])
|
||||
|
||||
if id_changed?
|
||||
if saved_change_to_id?
|
||||
ModAction.log("created #{status} #{alias_desc}",:tag_alias_create)
|
||||
else
|
||||
# format the changes hash more nicely.
|
||||
change_desc = changes.except(:updated_at).map do |attribute, values|
|
||||
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}")
|
||||
|
||||
@@ -123,12 +123,12 @@ class TagImplication < TagRelationship
|
||||
return if skip_secondary_validations
|
||||
|
||||
unless WikiPage.titled(consequent_name).exists?
|
||||
self.errors[:base] = "The #{consequent_name} tag needs a corresponding wiki page"
|
||||
self.errors[:base] << "The #{consequent_name} tag needs a corresponding wiki page"
|
||||
return false
|
||||
end
|
||||
|
||||
unless WikiPage.titled(antecedent_name).exists?
|
||||
self.errors[:base] = "The #{antecedent_name} tag needs a corresponding wiki page"
|
||||
self.errors[:base] << "The #{antecedent_name} tag needs a corresponding wiki page"
|
||||
return false
|
||||
end
|
||||
end
|
||||
@@ -144,9 +144,9 @@ class TagImplication < TagRelationship
|
||||
|
||||
begin
|
||||
CurrentUser.scoped(approver) do
|
||||
update({ :status => "processing" }, :as => CurrentUser.role)
|
||||
update(status: "processing")
|
||||
update_posts
|
||||
update({ :status => "active" }, :as => CurrentUser.role)
|
||||
update(status: "active")
|
||||
update_descendant_names_for_parents
|
||||
forum_updater.update(approval_message(approver), "APPROVED") if update_topic
|
||||
end
|
||||
@@ -158,7 +158,7 @@ class TagImplication < TagRelationship
|
||||
end
|
||||
|
||||
forum_updater.update(failure_message(e), "FAILED") if update_topic
|
||||
update({ :status => "error: #{e}" }, :as => CurrentUser.role)
|
||||
update(status: "error: #{e}")
|
||||
|
||||
if Rails.env.production?
|
||||
NewRelic::Agent.notice_error(e, :custom_params => {:tag_implication_id => id, :antecedent_name => antecedent_name, :consequent_name => consequent_name})
|
||||
@@ -180,12 +180,12 @@ class TagImplication < TagRelationship
|
||||
end
|
||||
|
||||
def approve!(approver: CurrentUser.user, update_topic: true)
|
||||
update({ :status => "queued", :approver_id => approver.id }, :as => approver.role)
|
||||
update(status: "queued", approver_id: approver.id)
|
||||
delay(:queue => "default").process!(update_topic: update_topic)
|
||||
end
|
||||
|
||||
def reject!
|
||||
update({ :status => "deleted", }, :as => CurrentUser.role)
|
||||
update(status: "deleted")
|
||||
forum_updater.update(reject_message(CurrentUser.user), "REJECTED")
|
||||
destroy
|
||||
end
|
||||
@@ -193,11 +193,11 @@ class TagImplication < TagRelationship
|
||||
def create_mod_action
|
||||
implication = %Q("tag implication ##{id}":[#{Rails.application.routes.url_helpers.tag_implication_path(self)}]: [[#{antecedent_name}]] -> [[#{consequent_name}]])
|
||||
|
||||
if id_changed?
|
||||
if saved_change_to_id?
|
||||
ModAction.log("created #{status} #{implication}",:tag_implication_create)
|
||||
else
|
||||
# format the changes hash more nicely.
|
||||
change_desc = changes.except(:updated_at).map do |attribute, values|
|
||||
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}")
|
||||
|
||||
@@ -2,13 +2,11 @@ class TagRelationship < ApplicationRecord
|
||||
self.abstract_class = true
|
||||
|
||||
attr_accessor :skip_secondary_validations
|
||||
attr_accessible :antecedent_name, :consequent_name, :forum_topic_id, :skip_secondary_validations
|
||||
attr_accessible :status, :approver_id, :as => [:admin]
|
||||
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :approver, :class_name => "User"
|
||||
belongs_to :forum_post
|
||||
belongs_to :forum_topic
|
||||
belongs_to_creator
|
||||
belongs_to :approver, class_name: "User", optional: true
|
||||
belongs_to :forum_post, optional: true
|
||||
belongs_to :forum_topic, optional: true
|
||||
has_one :antecedent_tag, :class_name => "Tag", :foreign_key => "name", :primary_key => "antecedent_name"
|
||||
has_one :consequent_tag, :class_name => "Tag", :foreign_key => "name", :primary_key => "consequent_name"
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
class TagSubscription < ApplicationRecord
|
||||
belongs_to :creator, :class_name => "User"
|
||||
attr_accessible :name, :tag_query, :post_ids, :is_public, :is_visible_on_profile
|
||||
validates_presence_of :name, :tag_query, :creator_id
|
||||
|
||||
def migrate_to_saved_searches
|
||||
tag_query.split(/\r\n|\r|\n/).each do |query|
|
||||
creator.saved_searches.create({query: query, labels: [name]}, without_protection: true)
|
||||
creator.saved_searches.create(query: query, labels: [name])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -8,17 +8,19 @@ class Upload < ApplicationRecord
|
||||
:artist_commentary_desc, :include_artist_commentary,
|
||||
:referer_url, :downloaded_source, :replaced_post
|
||||
belongs_to :uploader, :class_name => "User"
|
||||
belongs_to :post
|
||||
before_validation :initialize_uploader, :on => :create
|
||||
|
||||
belongs_to :post, optional: true
|
||||
|
||||
before_validation :initialize_attributes
|
||||
validate :uploader_is_not_limited, :on => :create
|
||||
validate :file_or_source_is_present, :on => :create
|
||||
validate :rating_given
|
||||
attr_accessible :file, :image_width, :image_height, :file_ext, :md5,
|
||||
:file_size, :as_pending, :source, :rating,
|
||||
:tag_string, :status, :backtrace, :post_id, :md5_confirmation,
|
||||
:parent_id, :server, :artist_commentary_title,
|
||||
:artist_commentary_desc, :include_artist_commentary,
|
||||
:referer_url, :replaced_post
|
||||
|
||||
def initialize_attributes
|
||||
self.uploader_id = CurrentUser.user.id
|
||||
self.uploader_ip_addr = CurrentUser.ip_addr
|
||||
self.server = Danbooru.config.server_host
|
||||
end
|
||||
|
||||
module ValidationMethods
|
||||
def uploader_is_not_limited
|
||||
@@ -117,7 +119,7 @@ class Upload < ApplicationRecord
|
||||
self.source = source.to_s.strip
|
||||
if is_downloadable?
|
||||
self.downloaded_source, self.source, self.file = download_from_source(source, referer_url)
|
||||
else
|
||||
elsif self.file.respond_to?(:tempfile)
|
||||
self.file = self.file.tempfile
|
||||
end
|
||||
|
||||
@@ -245,7 +247,7 @@ class Upload < ApplicationRecord
|
||||
result = Vips::Image.gifload(file.path, page: 1) rescue $ERROR_INFO
|
||||
if result.is_a?(Vips::Image)
|
||||
true
|
||||
elsif result.is_a?(Vips::Error) && result.message.match?(/too few frames in GIF file/)
|
||||
elsif result.is_a?(Vips::Error) && result.message =~ /too few frames in GIF file/
|
||||
false
|
||||
else
|
||||
raise result
|
||||
@@ -337,7 +339,7 @@ class Upload < ApplicationRecord
|
||||
source =~ /^https?:\/\// && file.blank?
|
||||
end
|
||||
|
||||
def download_from_source(source, referer_url)
|
||||
def download_from_source(source, referer_url = nil)
|
||||
download = Downloads::File.new(source, referer_url: referer_url)
|
||||
file = download.download!
|
||||
ugoira_service.load(download.data)
|
||||
@@ -369,11 +371,6 @@ class Upload < ApplicationRecord
|
||||
end
|
||||
|
||||
module UploaderMethods
|
||||
def initialize_uploader
|
||||
self.uploader_id = CurrentUser.user.id
|
||||
self.uploader_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def uploader_name
|
||||
User.id_to_name(uploader_id)
|
||||
end
|
||||
|
||||
@@ -15,7 +15,7 @@ class User < ApplicationRecord
|
||||
ADMIN = 50
|
||||
end
|
||||
|
||||
# Used for `before_filter :<role>_only`. Must have a corresponding `is_<role>?` method.
|
||||
# Used for `before_action :<role>_only`. Must have a corresponding `is_<role>?` method.
|
||||
Roles = Levels.constants.map(&:downcase) + [
|
||||
:anonymous,
|
||||
:banned,
|
||||
@@ -64,11 +64,10 @@ class User < ApplicationRecord
|
||||
has_bit_flags BOOLEAN_ATTRIBUTES, :field => "bit_prefs"
|
||||
|
||||
attr_accessor :password, :old_password
|
||||
attr_accessible :dmail_filter_attributes, :enable_privacy_mode, :enable_post_navigation, :new_post_navigation_layout, :password, :old_password, :password_confirmation, :password_hash, :email, :last_logged_in_at, :last_forum_read_at, :has_mail, :receive_email_notifications, :comment_threshold, :always_resize_images, :favorite_tags, :blacklisted_tags, :name, :ip_addr, :time_zone, :default_image_size, :enable_sequential_post_navigation, :per_page, :hide_deleted_posts, :style_usernames, :enable_auto_complete, :custom_style, :show_deleted_children, :disable_categorized_saved_searches, :disable_tagged_filenames, :enable_recent_searches, :disable_cropped_thumbnails, :disable_mobile_gestures, :enable_safe_mode, :disable_responsive_mode, :as => [:moderator, :gold, :platinum, :member, :anonymous, :default, :builder, :admin]
|
||||
attr_accessible :level, :as => :admin
|
||||
|
||||
after_initialize :initialize_attributes, if: :new_record?
|
||||
validates :name, user_name: true, on: :create
|
||||
validates_uniqueness_of :email, :case_sensitive => false, :if => lambda {|rec| rec.email.present? && rec.email_changed? }
|
||||
validates_uniqueness_of :email, :case_sensitive => false, :if => lambda {|rec| rec.email.present? && rec.saved_change_to_email? }
|
||||
validates_length_of :password, :minimum => 5, :if => lambda {|rec| rec.new_record? || rec.password.present?}
|
||||
validates_inclusion_of :default_image_size, :in => %w(large original)
|
||||
validates_inclusion_of :per_page, :in => 1..100
|
||||
@@ -82,7 +81,6 @@ class User < ApplicationRecord
|
||||
before_validation :normalize_email
|
||||
before_create :encrypt_password_on_create
|
||||
before_update :encrypt_password_on_update
|
||||
before_create :initialize_default_boolean_attributes
|
||||
after_save :update_cache
|
||||
after_update :update_remote_cache
|
||||
before_create :promote_to_admin_if_first_user
|
||||
@@ -105,7 +103,7 @@ class User < ApplicationRecord
|
||||
has_many :saved_searches
|
||||
has_many :forum_posts, lambda {order("forum_posts.created_at, forum_posts.id")}, :foreign_key => "creator_id"
|
||||
has_many :user_name_change_requests, lambda {visible.order("user_name_change_requests.created_at desc")}
|
||||
belongs_to :inviter, :class_name => "User"
|
||||
belongs_to :inviter, class_name: "User", optional: true
|
||||
after_update :create_mod_action
|
||||
accepts_nested_attributes_for :dmail_filter
|
||||
|
||||
@@ -191,7 +189,7 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_remote_cache
|
||||
if name_changed?
|
||||
if saved_change_to_name?
|
||||
Danbooru.config.other_server_hosts.each do |server|
|
||||
HTTParty.delete("http://#{server}/users/#{id}/cache", Danbooru.config.httparty_options)
|
||||
end
|
||||
@@ -223,7 +221,7 @@ class User < ApplicationRecord
|
||||
self.bcrypt_password_hash = User.bcrypt(password)
|
||||
return true
|
||||
else
|
||||
errors[:old_password] = "is incorrect"
|
||||
errors[:old_password] << "is incorrect"
|
||||
return false
|
||||
end
|
||||
end
|
||||
@@ -385,6 +383,10 @@ class User < ApplicationRecord
|
||||
level_string.downcase.to_sym
|
||||
end
|
||||
|
||||
def level_string_before_last_save
|
||||
level_string(level_before_last_save)
|
||||
end
|
||||
|
||||
def level_string_was
|
||||
level_string(level_was)
|
||||
end
|
||||
@@ -438,8 +440,8 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def create_mod_action
|
||||
if level_changed?
|
||||
ModAction.log(%{"#{name}":/users/#{id} level changed #{level_string_was} -> #{level_string}},:user_level)
|
||||
if saved_change_to_level?
|
||||
ModAction.log(%{"#{name}":/users/#{id} level changed #{level_string_before_last_save} -> #{level_string}},:user_level)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -916,8 +918,8 @@ class User < ApplicationRecord
|
||||
extend SearchMethods
|
||||
include StatisticsMethods
|
||||
|
||||
def initialize_default_image_size
|
||||
self.default_image_size = "large"
|
||||
def as_current(&block)
|
||||
CurrentUser.as(self, &block)
|
||||
end
|
||||
|
||||
def can_update?(object, foreign_key = :user_id)
|
||||
@@ -936,7 +938,8 @@ class User < ApplicationRecord
|
||||
!CurrentUser.is_admin? && enable_privacy_mode? && CurrentUser.user.id != id
|
||||
end
|
||||
|
||||
def initialize_default_boolean_attributes
|
||||
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
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
class UserFeedback < ApplicationRecord
|
||||
self.table_name = "user_feedback"
|
||||
belongs_to :user
|
||||
belongs_to :creator, :class_name => "User"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
attr_accessor :disable_dmail_notification
|
||||
attr_accessible :body, :user_id, :category, :user_name, :disable_dmail_notification
|
||||
belongs_to_creator
|
||||
attribute :disable_dmail_notification, :boolean
|
||||
validates_presence_of :user, :creator, :body, :category
|
||||
validates_inclusion_of :category, :in => %w(positive negative neutral)
|
||||
validate :creator_is_gold
|
||||
@@ -76,18 +74,10 @@ class UserFeedback < ApplicationRecord
|
||||
|
||||
extend SearchMethods
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id ||= CurrentUser.id
|
||||
end
|
||||
|
||||
def user_name
|
||||
User.id_to_name(user_id)
|
||||
end
|
||||
|
||||
def creator_name
|
||||
User.id_to_name(creator_id)
|
||||
end
|
||||
|
||||
def user_name=(name)
|
||||
self.user_id = User.name_to_id(name)
|
||||
end
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
class UserNameChangeRequest < ApplicationRecord
|
||||
after_initialize :initialize_attributes, if: :new_record?
|
||||
validates_presence_of :user_id, :original_name, :desired_name
|
||||
validates_inclusion_of :status, :in => %w(pending approved rejected)
|
||||
belongs_to :user
|
||||
belongs_to :approver, :class_name => "User"
|
||||
belongs_to :approver, :class_name => "User", optional: true
|
||||
validate :not_limited, :on => :create
|
||||
validates :desired_name, user_name: true
|
||||
attr_accessible :status, :user_id, :original_name, :desired_name, :change_reason, :rejection_reason, :approver_id
|
||||
|
||||
def initialize_attributes
|
||||
self.user_id ||= CurrentUser.user.id
|
||||
self.original_name ||= CurrentUser.user.name
|
||||
end
|
||||
|
||||
def self.pending
|
||||
where(:status => "pending")
|
||||
|
||||
@@ -3,7 +3,6 @@ class UserPasswordResetNonce < ApplicationRecord
|
||||
validate :validate_existence_of_email
|
||||
before_validation :initialize_key, :on => :create
|
||||
after_create :deliver_notice
|
||||
attr_accessible :key, :nonce, :email
|
||||
|
||||
def self.prune!
|
||||
destroy_all(["created_at < ?", 1.week.ago])
|
||||
|
||||
@@ -3,19 +3,15 @@ class WikiPage < ApplicationRecord
|
||||
|
||||
before_save :normalize_title
|
||||
before_save :normalize_other_names
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
after_save :create_version
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to_creator
|
||||
belongs_to_updater
|
||||
validates_uniqueness_of :title, :case_sensitive => false
|
||||
validates_presence_of :title
|
||||
validates_presence_of :body, :unless => -> { is_deleted? || other_names.present? }
|
||||
validate :validate_rename
|
||||
validate :validate_locker_is_builder
|
||||
validate :validate_not_locked
|
||||
attr_accessor :skip_secondary_validations
|
||||
attr_accessible :title, :body, :is_locked, :is_deleted, :other_names, :skip_secondary_validations
|
||||
has_one :tag, :foreign_key => "name", :primary_key => "title"
|
||||
has_one :artist, lambda {where(:is_active => true)}, :foreign_key => "name", :primary_key => "title"
|
||||
has_many :versions, lambda {order("wiki_page_versions.id ASC")}, :class_name => "WikiPageVersion", :dependent => :destroy
|
||||
@@ -127,13 +123,6 @@ class WikiPage < ApplicationRecord
|
||||
titled(title).select("title, id").first
|
||||
end
|
||||
|
||||
def validate_locker_is_builder
|
||||
if is_locked_changed? && !CurrentUser.is_builder?
|
||||
errors.add(:is_locked, "can be modified by builders only")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def validate_not_locked
|
||||
if is_locked? && !CurrentUser.is_builder?
|
||||
errors.add(:is_locked, "and cannot be updated")
|
||||
@@ -142,7 +131,7 @@ class WikiPage < ApplicationRecord
|
||||
end
|
||||
|
||||
def validate_rename
|
||||
return if !title_changed? || skip_secondary_validations
|
||||
return if !will_save_change_to_title? || skip_secondary_validations
|
||||
|
||||
tag_was = Tag.find_by_name(Tag.normalize_name(title_was))
|
||||
if tag_was.present? && tag_was.post_count > 0
|
||||
@@ -179,10 +168,6 @@ class WikiPage < ApplicationRecord
|
||||
@skip_secondary_validations = (value == true || value == "1")
|
||||
end
|
||||
|
||||
def creator_name
|
||||
User.id_to_name(creator_id)
|
||||
end
|
||||
|
||||
def category_name
|
||||
Tag.category_for(title)
|
||||
end
|
||||
@@ -192,7 +177,7 @@ class WikiPage < ApplicationRecord
|
||||
end
|
||||
|
||||
def wiki_page_changed?
|
||||
title_changed? || body_changed? || is_locked_changed? || is_deleted_changed? || other_names_changed?
|
||||
saved_change_to_title? || saved_change_to_body? || saved_change_to_is_locked? || saved_change_to_is_deleted? || saved_change_to_other_names?
|
||||
end
|
||||
|
||||
def merge_version
|
||||
@@ -232,20 +217,6 @@ class WikiPage < ApplicationRecord
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def updater_name
|
||||
User.id_to_name(updater_id)
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.user.id
|
||||
end
|
||||
|
||||
def initialize_updater
|
||||
if wiki_page_changed?
|
||||
self.updater_id = CurrentUser.user.id
|
||||
end
|
||||
end
|
||||
|
||||
def post_set
|
||||
@post_set ||= PostSets::WikiPage.new(title, 1, 4)
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
class WikiPageVersion < ApplicationRecord
|
||||
belongs_to :wiki_page
|
||||
belongs_to :updater, :class_name => "User"
|
||||
belongs_to :artist
|
||||
attr_accessible :wiki_page_id, :title, :body, :is_locked, :is_deleted, :updater_id, :updater_ip_addr, :version, :other_names
|
||||
belongs_to_updater
|
||||
belongs_to :artist, optional: true
|
||||
delegate :visible?, :to => :wiki_page
|
||||
|
||||
module SearchMethods
|
||||
@@ -27,10 +26,6 @@ class WikiPageVersion < ApplicationRecord
|
||||
|
||||
extend SearchMethods
|
||||
|
||||
def updater_name
|
||||
User.id_to_name(updater_id)
|
||||
end
|
||||
|
||||
def pretty_title
|
||||
title.tr("_", " ")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user