users: add user name blacklist.
This commit is contained in:
@@ -6,5 +6,6 @@ class UserNameValidator < ActiveModel::EachValidator
|
|||||||
rec.errors[attr] << "must be 2 to 100 characters long" if !name.length.between?(2, 100)
|
rec.errors[attr] << "must be 2 to 100 characters long" if !name.length.between?(2, 100)
|
||||||
rec.errors[attr] << "cannot have whitespace or colons" if name =~ /[[:space:]]|:/
|
rec.errors[attr] << "cannot have whitespace or colons" if name =~ /[[:space:]]|:/
|
||||||
rec.errors[attr] << "cannot begin or end with an underscore" if name =~ /\A_|_\z/
|
rec.errors[attr] << "cannot begin or end with an underscore" if name =~ /\A_|_\z/
|
||||||
|
rec.errors[attr] << "is not allowed" if name =~ Regexp.union(Danbooru.config.user_name_blacklist)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ module Danbooru
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# An array of regexes containing disallowed usernames.
|
||||||
|
def user_name_blacklist
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
# Thumbnail size
|
# Thumbnail size
|
||||||
def small_image_width
|
def small_image_width
|
||||||
150
|
150
|
||||||
|
|||||||
@@ -91,6 +91,13 @@ class UserTest < ActiveSupport::TestCase
|
|||||||
assert_equal(["Name cannot begin or end with an underscore"], user.errors.full_messages)
|
assert_equal(["Name cannot begin or end with an underscore"], user.errors.full_messages)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "not allow blacklisted names" do
|
||||||
|
Danbooru.config.stubs(:user_name_blacklist).returns(["voldemort"])
|
||||||
|
user = build(:user, name: "voldemort42")
|
||||||
|
user.save
|
||||||
|
assert_equal(["Name is not allowed"], user.errors.full_messages)
|
||||||
|
end
|
||||||
|
|
||||||
should "be updated" do
|
should "be updated" do
|
||||||
@user = FactoryBot.create(:user)
|
@user = FactoryBot.create(:user)
|
||||||
@user.update_attribute(:name, "danzig")
|
@user.update_attribute(:name, "danzig")
|
||||||
|
|||||||
Reference in New Issue
Block a user