validations: drop superfluous return statements.
Returning true or false in a validation callback doesn't do anything, so drop these superfluous return statements.
This commit is contained in:
@@ -5,7 +5,7 @@ class ArtistCommentary < ApplicationRecord
|
|||||||
attr_accessor :add_commentary_tag, :add_commentary_request_tag, :add_commentary_check_tag, :add_partial_commentary_tag
|
attr_accessor :add_commentary_tag, :add_commentary_request_tag, :add_commentary_check_tag, :add_partial_commentary_tag
|
||||||
before_validation :trim_whitespace
|
before_validation :trim_whitespace
|
||||||
validates_uniqueness_of :post_id
|
validates_uniqueness_of :post_id
|
||||||
belongs_to :post, required: true
|
belongs_to :post
|
||||||
has_many :versions, -> {order("artist_commentary_versions.id ASC")}, :class_name => "ArtistCommentaryVersion", :dependent => :destroy, :foreign_key => :post_id, :primary_key => :post_id
|
has_many :versions, -> {order("artist_commentary_versions.id ASC")}, :class_name => "ArtistCommentaryVersion", :dependent => :destroy, :foreign_key => :post_id, :primary_key => :post_id
|
||||||
has_one :previous_version, -> {order(id: :desc)}, :class_name => "ArtistCommentaryVersion", :foreign_key => :post_id, :primary_key => :post_id
|
has_one :previous_version, -> {order(id: :desc)}, :class_name => "ArtistCommentaryVersion", :foreign_key => :post_id, :primary_key => :post_id
|
||||||
after_save :create_version
|
after_save :create_version
|
||||||
|
|||||||
@@ -141,10 +141,8 @@ class BulkUpdateRequest < ApplicationRecord
|
|||||||
module ValidationMethods
|
module ValidationMethods
|
||||||
def script_formatted_correctly
|
def script_formatted_correctly
|
||||||
AliasAndImplicationImporter.tokenize(script)
|
AliasAndImplicationImporter.tokenize(script)
|
||||||
return true
|
|
||||||
rescue StandardError => e
|
rescue StandardError => e
|
||||||
errors[:base] << e.message
|
errors[:base] << e.message
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def forum_topic_id_not_invalid
|
def forum_topic_id_not_invalid
|
||||||
@@ -157,11 +155,8 @@ class BulkUpdateRequest < ApplicationRecord
|
|||||||
begin
|
begin
|
||||||
AliasAndImplicationImporter.new(script, forum_topic_id, "1", skip_secondary_validations).validate!
|
AliasAndImplicationImporter.new(script, forum_topic_id, "1", skip_secondary_validations).validate!
|
||||||
rescue RuntimeError => e
|
rescue RuntimeError => e
|
||||||
self.errors[:base] << e.message
|
errors[:base] << e.message
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
errors.empty?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -139,12 +139,8 @@ class Comment < ApplicationRecord
|
|||||||
def validate_creator_is_not_limited
|
def validate_creator_is_not_limited
|
||||||
if creator.is_comment_limited? && !do_not_bump_post?
|
if creator.is_comment_limited? && !do_not_bump_post?
|
||||||
errors.add(:base, "You can only post #{Danbooru.config.member_comment_limit} comments per hour")
|
errors.add(:base, "You can only post #{Danbooru.config.member_comment_limit} comments per hour")
|
||||||
false
|
elsif !creator.can_comment?
|
||||||
elsif creator.can_comment?
|
|
||||||
true
|
|
||||||
else
|
|
||||||
errors.add(:base, "You can not post comments within 1 week of sign up")
|
errors.add(:base, "You can not post comments within 1 week of sign up")
|
||||||
false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -153,7 +149,6 @@ class Comment < ApplicationRecord
|
|||||||
if Comment.where("post_id = ?", post_id).count <= Danbooru.config.comment_threshold && !do_not_bump_post?
|
if Comment.where("post_id = ?", post_id).count <= Danbooru.config.comment_threshold && !do_not_bump_post?
|
||||||
Post.where(:id => post_id).update_all(:last_comment_bumped_at => created_at)
|
Post.where(:id => post_id).update_all(:last_comment_bumped_at => created_at)
|
||||||
end
|
end
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_last_commented_at_on_destroy
|
def update_last_commented_at_on_destroy
|
||||||
@@ -170,8 +165,6 @@ class Comment < ApplicationRecord
|
|||||||
else
|
else
|
||||||
Post.where(:id => post_id).update_all(:last_comment_bumped_at => other_comments.first.created_at)
|
Post.where(:id => post_id).update_all(:last_comment_bumped_at => other_comments.first.created_at)
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def below_threshold?(user = CurrentUser.user)
|
def below_threshold?(user = CurrentUser.user)
|
||||||
|
|||||||
@@ -28,18 +28,12 @@ class CommentVote < ApplicationRecord
|
|||||||
def validate_user_can_vote
|
def validate_user_can_vote
|
||||||
if !user.can_comment_vote?
|
if !user.can_comment_vote?
|
||||||
errors.add :base, "You cannot vote on more than 10 comments per hour"
|
errors.add :base, "You cannot vote on more than 10 comments per hour"
|
||||||
false
|
|
||||||
else
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_comment_can_be_down_voted
|
def validate_comment_can_be_down_voted
|
||||||
if is_positive? && comment.creator == CurrentUser.user
|
if is_positive? && comment.creator == CurrentUser.user
|
||||||
errors.add :base, "You cannot upvote your own comments"
|
errors.add :base, "You cannot upvote your own comments"
|
||||||
false
|
|
||||||
else
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -214,9 +214,6 @@ class Dmail < ApplicationRecord
|
|||||||
def validate_sender_is_not_banned
|
def validate_sender_is_not_banned
|
||||||
if from.try(:is_banned?)
|
if from.try(: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
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -88,18 +88,12 @@ class FavoriteGroup < ApplicationRecord
|
|||||||
error += " Upgrade your account to create more."
|
error += " Upgrade your account to create more."
|
||||||
end
|
end
|
||||||
self.errors.add(:base, error)
|
self.errors.add(:base, error)
|
||||||
return false
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_number_of_posts
|
def validate_number_of_posts
|
||||||
if post_id_array.size > 10_000
|
if post_id_array.size > 10_000
|
||||||
self.errors.add(:base, "Favorite groups can have up to 10,000 posts each")
|
self.errors.add(:base, "Favorite groups can have up to 10,000 posts each")
|
||||||
return false
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,6 @@ class ForumPost < ApplicationRecord
|
|||||||
def topic_is_not_restricted
|
def topic_is_not_restricted
|
||||||
if topic && !topic.visible?(creator)
|
if topic && !topic.visible?(creator)
|
||||||
errors[:topic] << "is restricted"
|
errors[:topic] << "is restricted"
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -238,8 +237,6 @@ class ForumPost < ApplicationRecord
|
|||||||
if is_deleted? && is_original_post?
|
if is_deleted? && is_original_post?
|
||||||
topic.update_attribute(:is_deleted, true)
|
topic.update_attribute(:is_deleted, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_response
|
def build_response
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ class Note < ApplicationRecord
|
|||||||
def post_must_not_be_note_locked
|
def post_must_not_be_note_locked
|
||||||
if is_locked?
|
if is_locked?
|
||||||
errors.add :post, "is note locked"
|
errors.add :post, "is note locked"
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -78,7 +77,6 @@ class Note < ApplicationRecord
|
|||||||
return false unless post.present?
|
return false unless post.present?
|
||||||
if x < 0 || y < 0 || (x > post.image_width) || (y > post.image_height) || width < 0 || height < 0 || (x + width > post.image_width) || (y + height > post.image_height)
|
if x < 0 || y < 0 || (x > post.image_width) || (y > post.image_height) || width < 0 || height < 0 || (x + width > post.image_width) || (y + height > post.image_height)
|
||||||
self.errors.add(:note, "must be inside the image")
|
self.errors.add(:note, "must be inside the image")
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -75,18 +75,12 @@ class PostAppeal < ApplicationRecord
|
|||||||
def validate_creator_is_not_limited
|
def validate_creator_is_not_limited
|
||||||
if appeal_count_for_creator >= Danbooru.config.max_appeals_per_day
|
if appeal_count_for_creator >= Danbooru.config.max_appeals_per_day
|
||||||
errors[:creator] << "can appeal at most #{Danbooru.config.max_appeals_per_day} post a day"
|
errors[:creator] << "can appeal at most #{Danbooru.config.max_appeals_per_day} post a day"
|
||||||
false
|
|
||||||
else
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_post_is_inactive
|
def validate_post_is_inactive
|
||||||
if resolved?
|
if resolved?
|
||||||
errors[:post] << "is active"
|
errors[:post] << "is active"
|
||||||
false
|
|
||||||
else
|
|
||||||
true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class PostDisapproval < ApplicationRecord
|
class PostDisapproval < ApplicationRecord
|
||||||
DELETION_THRESHOLD = 1.month
|
DELETION_THRESHOLD = 1.month
|
||||||
|
|
||||||
belongs_to :post, required: true
|
belongs_to :post
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
after_initialize :initialize_attributes, if: :new_record?
|
after_initialize :initialize_attributes, if: :new_record?
|
||||||
validates_uniqueness_of :post_id, :scope => [:user_id], :message => "have already hidden this post"
|
validates_uniqueness_of :post_id, :scope => [:user_id], :message => "have already hidden this post"
|
||||||
|
|||||||
@@ -255,10 +255,7 @@ class Upload < ApplicationRecord
|
|||||||
|
|
||||||
def uploader_is_not_limited
|
def uploader_is_not_limited
|
||||||
if !uploader.can_upload?
|
if !uploader.can_upload?
|
||||||
self.errors.add(:uploader, uploader.upload_limited_reason)
|
errors.add(:uploader, uploader.upload_limited_reason)
|
||||||
return false
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -117,8 +117,7 @@ class User < ApplicationRecord
|
|||||||
module BanMethods
|
module BanMethods
|
||||||
def validate_ip_addr_is_not_banned
|
def validate_ip_addr_is_not_banned
|
||||||
if IpBan.is_banned?(CurrentUser.ip_addr)
|
if IpBan.is_banned?(CurrentUser.ip_addr)
|
||||||
self.errors[:base] << "IP address is banned"
|
errors[:base] << "IP address is banned"
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -407,8 +406,6 @@ class User < ApplicationRecord
|
|||||||
if per_page.nil? || !is_gold?
|
if per_page.nil? || !is_gold?
|
||||||
self.per_page = Danbooru.config.posts_per_page
|
self.per_page = Danbooru.config.posts_per_page
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def level_class
|
def level_class
|
||||||
|
|||||||
@@ -100,21 +100,14 @@ class UserFeedback < ApplicationRecord
|
|||||||
def creator_is_gold
|
def creator_is_gold
|
||||||
if !creator.is_gold?
|
if !creator.is_gold?
|
||||||
errors[:creator] << "must be gold"
|
errors[:creator] << "must be gold"
|
||||||
return false
|
|
||||||
elsif creator.no_feedback?
|
elsif creator.no_feedback?
|
||||||
errors[:creator] << "cannot submit feedback"
|
errors[:creator] << "cannot submit feedback"
|
||||||
return false
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_is_not_creator
|
def user_is_not_creator
|
||||||
if user_id == creator_id
|
if user_id == creator_id
|
||||||
errors[:creator] << "cannot submit feedback for yourself"
|
errors[:creator] << "cannot submit feedback for yourself"
|
||||||
return false
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -64,9 +64,6 @@ class UserNameChangeRequest < ApplicationRecord
|
|||||||
def not_limited
|
def not_limited
|
||||||
if UserNameChangeRequest.where("user_id = ? and created_at >= ?", CurrentUser.user.id, 1.week.ago).exists?
|
if UserNameChangeRequest.where("user_id = ? and created_at >= ?", CurrentUser.user.id, 1.week.ago).exists?
|
||||||
errors.add(:base, "You can only submit one name change request per week")
|
errors.add(:base, "You can only submit one name change request per week")
|
||||||
return false
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class UserPasswordResetNonce < ApplicationRecord
|
|||||||
def validate_existence_of_email
|
def validate_existence_of_email
|
||||||
if !User.with_email(email).exists?
|
if !User.with_email(email).exists?
|
||||||
errors[:email] << "is invalid"
|
errors[:email] << "is invalid"
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ class WikiPage < ApplicationRecord
|
|||||||
def validate_not_locked
|
def validate_not_locked
|
||||||
if is_locked? && !CurrentUser.is_builder?
|
if is_locked? && !CurrentUser.is_builder?
|
||||||
errors.add(:is_locked, "and cannot be updated")
|
errors.add(:is_locked, "and cannot be updated")
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user