mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Merge pull request #2034 from birarda/custom_username_length
allow for custom username length via site setting
This commit is contained in:
commit
69b498da24
@ -94,8 +94,14 @@ class User < ActiveRecord::Base
|
|||||||
LAST_VISIT = -2
|
LAST_VISIT = -2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
GLOBAL_USERNAME_LENGTH_RANGE = 3..15
|
||||||
|
|
||||||
def self.username_length
|
def self.username_length
|
||||||
3..15
|
if SiteSetting.enforce_global_nicknames
|
||||||
|
GLOBAL_USERNAME_LENGTH_RANGE
|
||||||
|
else
|
||||||
|
SiteSetting.min_username_length.to_i..GLOBAL_USERNAME_LENGTH_RANGE.end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def custom_groups
|
def custom_groups
|
||||||
|
@ -673,6 +673,8 @@ en:
|
|||||||
|
|
||||||
login_required: "Require authentication to read posts"
|
login_required: "Require authentication to read posts"
|
||||||
|
|
||||||
|
min_username_length: "Minimum username length. (Does not apply if global nickname uniqueness is forced)"
|
||||||
|
|
||||||
min_password_length: "Minimum password length."
|
min_password_length: "Minimum password length."
|
||||||
block_common_passwords: "Don't allow passwords that are in the 5000 most common passwords."
|
block_common_passwords: "Don't allow passwords that are in the 5000 most common passwords."
|
||||||
|
|
||||||
|
@ -102,6 +102,9 @@ users:
|
|||||||
must_approve_users:
|
must_approve_users:
|
||||||
client: true
|
client: true
|
||||||
default: false
|
default: false
|
||||||
|
min_username_length:
|
||||||
|
client: true
|
||||||
|
default: 3
|
||||||
min_password_length:
|
min_password_length:
|
||||||
client: true
|
client: true
|
||||||
default: 8
|
default: 8
|
||||||
|
@ -175,6 +175,34 @@ describe User do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'allow custom minimum username length from site settings' do
|
||||||
|
before do
|
||||||
|
@custom_min = User::GLOBAL_USERNAME_LENGTH_RANGE.begin - 1
|
||||||
|
SiteSetting.stubs("min_username_length").returns(@custom_min)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should allow a shorter username than default' do
|
||||||
|
result = user.change_username('a' * @custom_min)
|
||||||
|
result.should_not be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not allow a shorter username than limit' do
|
||||||
|
result = user.change_username('a' * (@custom_min - 1))
|
||||||
|
result.should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not allow a longer username than limit' do
|
||||||
|
result = user.change_username('a' * (User::GLOBAL_USERNAME_LENGTH_RANGE.end + 1))
|
||||||
|
result.should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should use default length for validation if enforce_global_nicknames is true' do
|
||||||
|
SiteSetting.stubs('enforce_global_nicknames').returns(true)
|
||||||
|
|
||||||
|
User::username_length.begin.should == User::GLOBAL_USERNAME_LENGTH_RANGE.begin
|
||||||
|
User::username_length.end.should == User::GLOBAL_USERNAME_LENGTH_RANGE.end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'delete posts' do
|
describe 'delete posts' do
|
||||||
@ -422,7 +450,7 @@ describe User do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe 'username format' do
|
describe 'username format' do
|
||||||
it "should always be 3 chars or longer" do
|
it "should be #{SiteSetting.min_username_length} chars or longer" do
|
||||||
@user = Fabricate.build(:user)
|
@user = Fabricate.build(:user)
|
||||||
@user.username = 'ss'
|
@user.username = 'ss'
|
||||||
@user.save.should == false
|
@user.save.should == false
|
||||||
|
Loading…
Reference in New Issue
Block a user