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:
evazion
2019-08-04 15:45:05 -05:00
parent a926b162be
commit 9163b3cb1c
16 changed files with 6 additions and 62 deletions

View File

@@ -5,7 +5,7 @@ class ArtistCommentary < ApplicationRecord
attr_accessor :add_commentary_tag, :add_commentary_request_tag, :add_commentary_check_tag, :add_partial_commentary_tag
before_validation :trim_whitespace
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_one :previous_version, -> {order(id: :desc)}, :class_name => "ArtistCommentaryVersion", :foreign_key => :post_id, :primary_key => :post_id
after_save :create_version

View File

@@ -141,10 +141,8 @@ class BulkUpdateRequest < ApplicationRecord
module ValidationMethods
def script_formatted_correctly
AliasAndImplicationImporter.tokenize(script)
return true
rescue StandardError => e
errors[:base] << e.message
return false
end
def forum_topic_id_not_invalid
@@ -157,11 +155,8 @@ class BulkUpdateRequest < ApplicationRecord
begin
AliasAndImplicationImporter.new(script, forum_topic_id, "1", skip_secondary_validations).validate!
rescue RuntimeError => e
self.errors[:base] << e.message
return false
errors[:base] << e.message
end
errors.empty?
end
end

View File

@@ -139,12 +139,8 @@ class Comment < ApplicationRecord
def validate_creator_is_not_limited
if creator.is_comment_limited? && !do_not_bump_post?
errors.add(:base, "You can only post #{Danbooru.config.member_comment_limit} comments per hour")
false
elsif creator.can_comment?
true
else
elsif !creator.can_comment?
errors.add(:base, "You can not post comments within 1 week of sign up")
false
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?
Post.where(:id => post_id).update_all(:last_comment_bumped_at => created_at)
end
true
end
def update_last_commented_at_on_destroy
@@ -170,8 +165,6 @@ class Comment < ApplicationRecord
else
Post.where(:id => post_id).update_all(:last_comment_bumped_at => other_comments.first.created_at)
end
true
end
def below_threshold?(user = CurrentUser.user)

View File

@@ -28,18 +28,12 @@ class CommentVote < ApplicationRecord
def validate_user_can_vote
if !user.can_comment_vote?
errors.add :base, "You cannot vote on more than 10 comments per hour"
false
else
true
end
end
def validate_comment_can_be_down_voted
if is_positive? && comment.creator == CurrentUser.user
errors.add :base, "You cannot upvote your own comments"
false
else
true
end
end

View File

@@ -214,9 +214,6 @@ class Dmail < ApplicationRecord
def validate_sender_is_not_banned
if from.try(:is_banned?)
errors[:base] << "Sender is banned and cannot send messages"
return false
else
return true
end
end

View File

@@ -88,18 +88,12 @@ class FavoriteGroup < ApplicationRecord
error += " Upgrade your account to create more."
end
self.errors.add(:base, error)
return false
else
return true
end
end
def validate_number_of_posts
if post_id_array.size > 10_000
self.errors.add(:base, "Favorite groups can have up to 10,000 posts each")
return false
else
return true
end
end

View File

@@ -146,7 +146,6 @@ class ForumPost < ApplicationRecord
def topic_is_not_restricted
if topic && !topic.visible?(creator)
errors[:topic] << "is restricted"
return false
end
end
@@ -238,8 +237,6 @@ class ForumPost < ApplicationRecord
if is_deleted? && is_original_post?
topic.update_attribute(:is_deleted, true)
end
true
end
def build_response

View File

@@ -70,7 +70,6 @@ class Note < ApplicationRecord
def post_must_not_be_note_locked
if is_locked?
errors.add :post, "is note locked"
return false
end
end
@@ -78,7 +77,6 @@ class Note < ApplicationRecord
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)
self.errors.add(:note, "must be inside the image")
return false
end
end

View File

@@ -75,18 +75,12 @@ class PostAppeal < ApplicationRecord
def validate_creator_is_not_limited
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"
false
else
true
end
end
def validate_post_is_inactive
if resolved?
errors[:post] << "is active"
false
else
true
end
end

View File

@@ -1,7 +1,7 @@
class PostDisapproval < ApplicationRecord
DELETION_THRESHOLD = 1.month
belongs_to :post, required: true
belongs_to :post
belongs_to :user
after_initialize :initialize_attributes, if: :new_record?
validates_uniqueness_of :post_id, :scope => [:user_id], :message => "have already hidden this post"

View File

@@ -255,10 +255,7 @@ class Upload < ApplicationRecord
def uploader_is_not_limited
if !uploader.can_upload?
self.errors.add(:uploader, uploader.upload_limited_reason)
return false
else
return true
errors.add(:uploader, uploader.upload_limited_reason)
end
end

View File

@@ -117,8 +117,7 @@ class User < ApplicationRecord
module BanMethods
def validate_ip_addr_is_not_banned
if IpBan.is_banned?(CurrentUser.ip_addr)
self.errors[:base] << "IP address is banned"
return false
errors[:base] << "IP address is banned"
end
end
@@ -407,8 +406,6 @@ class User < ApplicationRecord
if per_page.nil? || !is_gold?
self.per_page = Danbooru.config.posts_per_page
end
return true
end
def level_class

View File

@@ -100,21 +100,14 @@ class UserFeedback < ApplicationRecord
def creator_is_gold
if !creator.is_gold?
errors[:creator] << "must be gold"
return false
elsif creator.no_feedback?
errors[:creator] << "cannot submit feedback"
return false
else
return true
end
end
def user_is_not_creator
if user_id == creator_id
errors[:creator] << "cannot submit feedback for yourself"
return false
else
return true
end
end

View File

@@ -64,9 +64,6 @@ class UserNameChangeRequest < ApplicationRecord
def not_limited
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")
return false
else
return true
end
end

View File

@@ -15,7 +15,6 @@ class UserPasswordResetNonce < ApplicationRecord
def validate_existence_of_email
if !User.with_email(email).exists?
errors[:email] << "is invalid"
return false
end
end

View File

@@ -114,7 +114,6 @@ class WikiPage < ApplicationRecord
def validate_not_locked
if is_locked? && !CurrentUser.is_builder?
errors.add(:is_locked, "and cannot be updated")
return false
end
end