Merge branch 'master' of github.com:r888888888/danbooru
This commit is contained in:
@@ -7,6 +7,10 @@ class ArtistVersion < ActiveRecord::Base
|
||||
where("updater_id = ?", user_id)
|
||||
end
|
||||
|
||||
def updater_name(name)
|
||||
where("updater_id = (select _.id from users _ where lower(_.name) = ?)", name.mb_chars.downcase)
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = scoped
|
||||
return q if params.blank?
|
||||
@@ -15,6 +19,10 @@ class ArtistVersion < ActiveRecord::Base
|
||||
q = q.where("name like ? escape E'\\\\'", params[:name].to_escaped_for_sql_like)
|
||||
end
|
||||
|
||||
if params[:updater_name].present?
|
||||
q = q.updater_name(params[:updater_name])
|
||||
end
|
||||
|
||||
if params[:updater_id].present?
|
||||
q = q.for_user(params[:updater_id].to_i)
|
||||
end
|
||||
|
||||
@@ -174,6 +174,20 @@ class Note < ActiveRecord::Base
|
||||
save!
|
||||
end
|
||||
|
||||
def copy_to(new_post)
|
||||
new_note = dup
|
||||
new_note.post_id = new_post.id
|
||||
|
||||
width_ratio = new_post.image_width.to_f / post.image_width
|
||||
height_ratio = new_post.image_height.to_f / post.image_height
|
||||
new_note.x = x * width_ratio
|
||||
new_note.y = y * height_ratio
|
||||
new_note.width = width * width_ratio
|
||||
new_note.height = height * height_ratio
|
||||
|
||||
new_note.save
|
||||
end
|
||||
|
||||
def self.undo_changes_by_user(user_id)
|
||||
transaction do
|
||||
notes = Note.joins(:versions).where(["note_versions.updater_id = ?", user_id]).select("DISTINCT notes.*").all
|
||||
|
||||
@@ -49,8 +49,13 @@ class Pool < ActiveRecord::Base
|
||||
q = q.where("is_active = false")
|
||||
end
|
||||
|
||||
if params[:sort] == "name"
|
||||
case params[:sort]
|
||||
when "name"
|
||||
q = q.order("name")
|
||||
when "created_at"
|
||||
q = q.order("created_at desc")
|
||||
when "post_count"
|
||||
q = q.order("post_count desc")
|
||||
else
|
||||
q = q.order("updated_at desc")
|
||||
end
|
||||
@@ -139,12 +144,24 @@ class Pool < ActiveRecord::Base
|
||||
post_ids =~ /(?:\A| )#{post_id}(?:\Z| )/
|
||||
end
|
||||
|
||||
def page_number(post_id)
|
||||
post_id_array.find_index(post_id) + 1
|
||||
end
|
||||
|
||||
def deletable_by?(user)
|
||||
user.is_janitor?
|
||||
end
|
||||
|
||||
def create_mod_action_for_delete
|
||||
ModAction.create(:description => "deleted pool ##{id} (name: #{name})")
|
||||
end
|
||||
|
||||
def create_mod_action_for_undelete
|
||||
ModAction.create(:description => "undeleted pool ##{id} (name: #{name})")
|
||||
end
|
||||
|
||||
def create_mod_action_for_destroy
|
||||
ModAction.create(:description => "deleted pool ##{id} name=#{name} post_ids=#{post_ids}")
|
||||
ModAction.create(:description => "permanently deleted pool ##{id} name=#{name} post_ids=#{post_ids}")
|
||||
end
|
||||
|
||||
def add!(post)
|
||||
|
||||
@@ -153,7 +153,7 @@ class Post < ActiveRecord::Base
|
||||
|
||||
module ImageMethods
|
||||
def has_large?
|
||||
image_width.present? && image_width > Danbooru.config.large_image_width
|
||||
is_image? && image_width.present? && image_width > Danbooru.config.large_image_width
|
||||
end
|
||||
|
||||
def has_large
|
||||
@@ -872,15 +872,7 @@ class Post < ActiveRecord::Base
|
||||
def create_version
|
||||
return if disable_versioning
|
||||
|
||||
if created_at == updated_at
|
||||
CurrentUser.increment!(:post_update_count)
|
||||
versions.create(
|
||||
:rating => rating,
|
||||
:source => source,
|
||||
:tags => tag_string,
|
||||
:parent_id => parent_id
|
||||
)
|
||||
elsif rating_changed? || source_changed? || parent_id_changed? || tag_string_changed?
|
||||
if new_record? || rating_changed? || source_changed? || parent_id_changed? || tag_string_changed?
|
||||
CurrentUser.increment!(:post_update_count)
|
||||
versions.create(
|
||||
:rating => rating,
|
||||
@@ -908,6 +900,12 @@ class Post < ActiveRecord::Base
|
||||
def last_noted_at_as_integer
|
||||
last_noted_at.to_i
|
||||
end
|
||||
|
||||
def copy_notes_to(other_post)
|
||||
notes.each do |note|
|
||||
note.copy_to(other_post)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module ApiMethods
|
||||
|
||||
@@ -192,9 +192,9 @@ class Upload < ActiveRecord::Base
|
||||
self.tag_string = "#{tag_string} lowres".strip
|
||||
end
|
||||
|
||||
if image_width >= 1024 && image_width.to_f / image_height >= 3
|
||||
if image_width >= 1024 && image_width.to_f / image_height >= 4
|
||||
self.tag_string = "#{tag_string} wide_image".strip
|
||||
elsif image_height >= 1024 && image_height.to_f / image_width >= 3
|
||||
elsif image_height >= 1024 && image_height.to_f / image_width >= 4
|
||||
self.tag_string = "#{tag_string} tall_image".strip
|
||||
end
|
||||
end
|
||||
|
||||
@@ -519,7 +519,7 @@ class User < ActiveRecord::Base
|
||||
options[:except] ||= []
|
||||
options[:except] += hidden_attributes
|
||||
options[:methods] ||= []
|
||||
options[:methods] += [:wiki_page_version_count, :artist_version_count, :pool_version_count, :forum_post_count, :comment_count]
|
||||
options[:methods] += [:wiki_page_version_count, :artist_version_count, :pool_version_count, :forum_post_count, :comment_count, :positive_feedback_count, :neutral_feedback_count, :negative_feedback_count]
|
||||
super(options)
|
||||
end
|
||||
|
||||
@@ -529,7 +529,7 @@ class User < ActiveRecord::Base
|
||||
options[:except] ||= []
|
||||
options[:except] += hidden_attributes
|
||||
options[:methods] ||= []
|
||||
options[:methods] += [:wiki_page_version_count, :artist_version_count, :pool_version_count, :forum_post_count, :comment_count]
|
||||
options[:methods] += [:wiki_page_version_count, :artist_version_count, :pool_version_count, :forum_post_count, :comment_count, :positive_feedback_count, :neutral_feedback_count, :negative_feedback_count]
|
||||
super(options, &block)
|
||||
end
|
||||
|
||||
@@ -563,6 +563,18 @@ class User < ActiveRecord::Base
|
||||
def comment_count
|
||||
Comment.for_creator(id).count
|
||||
end
|
||||
|
||||
def positive_feedback_count
|
||||
feedback.positive.count
|
||||
end
|
||||
|
||||
def neutral_feedback_count
|
||||
feedback.neutral.count
|
||||
end
|
||||
|
||||
def negative_feedback_count
|
||||
feedback.negative.count
|
||||
end
|
||||
end
|
||||
|
||||
module SearchMethods
|
||||
|
||||
@@ -3,6 +3,7 @@ class WikiPage < ActiveRecord::Base
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_updater
|
||||
after_save :create_version
|
||||
before_destroy :create_mod_action_for_destroy
|
||||
belongs_to :creator, :class_name => "User"
|
||||
belongs_to :updater, :class_name => "User"
|
||||
validates_uniqueness_of :title, :case_sensitive => false
|
||||
@@ -159,4 +160,8 @@ class WikiPage < ActiveRecord::Base
|
||||
end
|
||||
end.map {|x| x.mb_chars.downcase.tr(" ", "_").to_s}
|
||||
end
|
||||
|
||||
def create_mod_action_for_destroy
|
||||
ModAction.create(:description => "permanently deleted wiki page [[#{title}]]")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -32,4 +32,8 @@ class WikiPageVersion < ActiveRecord::Base
|
||||
def pretty_title
|
||||
title.tr("_", " ")
|
||||
end
|
||||
|
||||
def category_name
|
||||
Tag.category_for(title)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user