mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 03:51:07 +08:00
FEATURE: Add support for Unicode usernames and group names
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
13
lib/validators/external_system_avatars_validator.rb
Normal file
13
lib/validators/external_system_avatars_validator.rb
Normal file
@ -0,0 +1,13 @@
|
||||
class ExternalSystemAvatarsValidator
|
||||
def initialize(opts = {})
|
||||
@opts = opts
|
||||
end
|
||||
|
||||
def valid_value?(value)
|
||||
@valid = value == "t" || !SiteSetting.unicode_usernames
|
||||
end
|
||||
|
||||
def error_message
|
||||
I18n.t("site_settings.errors.unicode_usernames_avatars") if !@valid
|
||||
end
|
||||
end
|
13
lib/validators/unicode_username_validator.rb
Normal file
13
lib/validators/unicode_username_validator.rb
Normal file
@ -0,0 +1,13 @@
|
||||
class UnicodeUsernameValidator
|
||||
def initialize(opts = {})
|
||||
@opts = opts
|
||||
end
|
||||
|
||||
def valid_value?(value)
|
||||
@valid = SiteSetting.external_system_avatars_enabled || value == "f"
|
||||
end
|
||||
|
||||
def error_message
|
||||
I18n.t("site_settings.errors.unicode_usernames_avatars") if !@valid
|
||||
end
|
||||
end
|
26
lib/validators/unicode_username_whitelist_validator.rb
Normal file
26
lib/validators/unicode_username_whitelist_validator.rb
Normal file
@ -0,0 +1,26 @@
|
||||
class UnicodeUsernameWhitelistValidator
|
||||
def initialize(opts = {})
|
||||
@opts = opts
|
||||
end
|
||||
|
||||
def valid_value?(value)
|
||||
@error_message = nil
|
||||
return true if value.blank?
|
||||
|
||||
if value.match?(/^\/.*\/[imxo]*$/)
|
||||
@error_message = I18n.t("site_settings.errors.unicode_username_whitelist.leading_trailing_slash")
|
||||
else
|
||||
begin
|
||||
Regexp.new(value)
|
||||
rescue RegexpError => e
|
||||
@error_message = I18n.t("site_settings.errors.unicode_username_whitelist.regex_invalid", error: e.message)
|
||||
end
|
||||
end
|
||||
|
||||
@error_message.blank?
|
||||
end
|
||||
|
||||
def error_message
|
||||
@error_message
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user